Skip to content

Commit

Permalink
feat: Shuffled code lines
Browse files Browse the repository at this point in the history
  • Loading branch information
kaiwalyakoparkar committed Nov 12, 2024
1 parent a8d8070 commit 20d95db
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 24 deletions.
4 changes: 3 additions & 1 deletion api/kubernetes/combined.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ spec:
ports:
- port: 80
targetPort: 80
nodePort: 30080
name: web
- port: 8080
targetPort: 8080
name: api
nodePort: 30081
name: api
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down
46 changes: 23 additions & 23 deletions web/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ document.addEventListener('DOMContentLoaded', function () {
podsData.then(data => {
data = JSON.parse(data);
// console.log(data);

data.items.forEach(pod => {
let podElement = document.createElement('div');
podElement.className = 'pod-item';
Expand Down Expand Up @@ -60,7 +60,7 @@ document.addEventListener('DOMContentLoaded', function () {
container.then(data => {
data = JSON.parse(data);
containerName = data[0];
console.log("Using container " +containerName);
console.log("Using container " + containerName);
const pod = fetchLogs(namespace, podName, containerName);
pod.then(data => {
logsContent.textContent = data;
Expand Down Expand Up @@ -94,57 +94,57 @@ document.addEventListener('DOMContentLoaded', function () {

async function fetchLogs(namespace, podName, containerName) {
try {
const response = await fetch('http://localhost:8080/api/logs?namespace=' + namespace + '&pod=' + podName+ '&container='+ containerName);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const response = await fetch('http://localhost:8080/api/logs?namespace=' + namespace + '&pod=' + podName + '&container=' + containerName);
let data = await response.text();
data = JSON.parse(data);
if (!response.ok) {
throw new Error('Network response was not ok');
}
data = JSON.parse(data);
return data.output;
} catch (error) {
console.error('Error listing namespaces: ', error);
console.error('Error listing namespaces: ', error);
}
}

async function fetchPods(namespace) {
try {
const response = await fetch('http://localhost:8080/api/listPods?namespace=' + namespace);
if (!response.ok) {
throw new Error('Network response was not ok');
}
let data = await response.text();
data = JSON.parse(data);
if (!response.ok) {
throw new Error('Network response was not ok');
}
data = JSON.parse(data);
return data.env;
} catch (error) {
console.error('Error listing pods: ', error);
console.error('Error listing pods: ', error);
}
}

//Function to crawl the namespace url
async function fetchNamespaces() {
try {
const response = await fetch('http://localhost:8080/api/listNs');
if (!response.ok) {
throw new Error('Network response was not ok');
}
let data = await response.text();
data = JSON.parse(data);
if (!response.ok) {
throw new Error('Network response was not ok');
}
data = JSON.parse(data);
return data.env;
} catch (error) {
console.error('Error listing namespaces: ', error);
console.error('Error listing namespaces: ', error);
}
}

async function fetchContainer(namespace, podName) {
try {
const response = await fetch('http://localhost:8080/api/lsCont?namespace=' + namespace + '&pod=' + podName);
if (!response.ok) {
throw new Error('Network response was not ok');
}
let data = await response.text();
data = JSON.parse(data);
if (!response.ok) {
throw new Error('Network response was not ok');
}
data = JSON.parse(data);
return data.env;
} catch (error) {
console.error('Error listing containers: ', error);
console.error('Error listing containers: ', error);
}
}

0 comments on commit 20d95db

Please sign in to comment.