Skip to content

Commit a4af0c4

Browse files
committed
backend working
Signed-off-by: Sayan Banerjee <sayanbanerjee2002@gmail.com>
1 parent c2e44ba commit a4af0c4

File tree

2 files changed

+204
-201
lines changed

2 files changed

+204
-201
lines changed

backend/src/server.js

Lines changed: 77 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ app.get("/api/jobs", async (req, res) => {
3232

3333
let response;
3434
if (namespace === "" || namespace === "All") {
35-
response = await k8sApi.listClusterCustomObject(
36-
"batch.volcano.sh",
37-
"v1alpha1",
38-
"jobs",
39-
true,
40-
);
35+
response = await k8sApi.listClusterCustomObject({
36+
group: "batch.volcano.sh",
37+
version: "v1alpha1",
38+
plural: "jobs",
39+
pretty: true,
40+
});
4141
} else {
42-
response = await k8sApi.listNamespacedCustomObject(
43-
"batch.volcano.sh",
44-
"v1alpha1",
42+
response = await k8sApi.listNamespacedCustomObject({
43+
group: "batch.volcano.sh",
44+
version: "v1alpha1",
4545
namespace,
46-
"jobs",
47-
true,
48-
);
46+
plural: "jobs",
47+
pretty: true,
48+
});
4949
}
5050

51-
let filteredJobs = response.body.items || [];
51+
let filteredJobs = response.items || [];
5252

5353
if (searchTerm) {
5454
filteredJobs = filteredJobs.filter((job) =>
@@ -88,14 +88,14 @@ app.get("/api/jobs", async (req, res) => {
8888
app.get("/api/jobs/:namespace/:name", async (req, res) => {
8989
try {
9090
const { namespace, name } = req.params;
91-
const response = await k8sApi.getNamespacedCustomObject(
92-
"batch.volcano.sh",
93-
"v1alpha1",
91+
const response = await k8sApi.getNamespacedCustomObject({
92+
group: "batch.volcano.sh",
93+
version: "v1alpha1",
9494
namespace,
95-
"jobs",
95+
plural: "jobs",
9696
name,
97-
);
98-
res.json(response.body);
97+
});
98+
res.json(response);
9999
} catch (err) {
100100
console.error("Error fetching job:", err);
101101
res.status(500).json({
@@ -109,15 +109,15 @@ app.get("/api/jobs/:namespace/:name", async (req, res) => {
109109
app.get("/api/job/:namespace/:name/yaml", async (req, res) => {
110110
try {
111111
const { namespace, name } = req.params;
112-
const response = await k8sApi.getNamespacedCustomObject(
113-
"batch.volcano.sh",
114-
"v1alpha1",
112+
const response = await k8sApi.getNamespacedCustomObject({
113+
group: "batch.volcano.sh",
114+
version: "v1alpha1",
115115
namespace,
116-
"jobs",
116+
plural: "jobs",
117117
name,
118-
);
118+
});
119119

120-
const formattedYaml = yaml.dump(response.body, {
120+
const formattedYaml = yaml.dump(response, {
121121
indent: 2,
122122
lineWidth: -1,
123123
noRefs: true,
@@ -137,30 +137,32 @@ app.get("/api/job/:namespace/:name/yaml", async (req, res) => {
137137

138138
// Get details of a specific Queue
139139
app.get("/api/queues/:name", async (req, res) => {
140+
const name = req.params.name;
140141
try {
141-
const response = await k8sApi.getClusterCustomObject(
142-
"scheduling.volcano.sh",
143-
"v1beta1",
144-
"queues",
145-
req.params.name,
146-
);
147-
res.json(response.body);
142+
const response = await k8sApi.getClusterCustomObject({
143+
group: "scheduling.volcano.sh",
144+
version: "v1beta1",
145+
plural: "queues",
146+
name,
147+
});
148+
res.json(response);
148149
} catch (error) {
149150
console.error("Error fetching queue details:", error);
150151
res.status(500).json({ error: "Failed to fetch queue details" });
151152
}
152153
});
153154

154155
app.get("/api/queue/:name/yaml", async (req, res) => {
156+
const name = req.params.name;
155157
try {
156-
const response = await k8sApi.getClusterCustomObject(
157-
"scheduling.volcano.sh",
158-
"v1beta1",
159-
"queues",
160-
req.params.name,
161-
);
162-
163-
const formattedYaml = yaml.dump(response.body, {
158+
const response = await k8sApi.getClusterCustomObject({
159+
group: "scheduling.volcano.sh",
160+
version: "v1beta1",
161+
plural: "queues",
162+
name,
163+
});
164+
165+
const formattedYaml = yaml.dump(response, {
164166
indent: 2,
165167
lineWidth: -1,
166168
noRefs: true,
@@ -194,13 +196,13 @@ app.get("/api/queues", async (req, res) => {
194196
stateFilter,
195197
});
196198

197-
const response = await k8sApi.listClusterCustomObject(
198-
"scheduling.volcano.sh",
199-
"v1beta1",
200-
"queues",
201-
);
199+
const response = await k8sApi.listClusterCustomObject({
200+
group: "scheduling.volcano.sh",
201+
version: "v1beta1",
202+
plural: "queues",
203+
});
202204

203-
let filteredQueues = response.body.items || [];
205+
let filteredQueues = response.items || [];
204206

205207
if (searchTerm) {
206208
filteredQueues = filteredQueues.filter((queue) =>
@@ -243,7 +245,7 @@ app.get("/api/namespaces", async (req, res) => {
243245
const response = await k8sCoreApi.listNamespace();
244246

245247
res.json({
246-
items: response.body.items,
248+
items: response.items,
247249
});
248250
} catch (error) {
249251
console.error("Error fetching namespaces:", error);
@@ -270,10 +272,10 @@ app.get("/api/pods", async (req, res) => {
270272
if (namespace === "" || namespace === "All") {
271273
response = await k8sCoreApi.listPodForAllNamespaces();
272274
} else {
273-
response = await k8sCoreApi.listNamespacedPod(namespace);
275+
response = await k8sCoreApi.listNamespacedPod({ namespace });
274276
}
275277

276-
let filteredPods = response.body.items || [];
278+
let filteredPods = response.items || [];
277279

278280
// Apply search filter
279281
if (searchTerm) {
@@ -307,10 +309,13 @@ app.get("/api/pods", async (req, res) => {
307309
app.get("/api/pod/:namespace/:name/yaml", async (req, res) => {
308310
try {
309311
const { namespace, name } = req.params;
310-
const response = await k8sCoreApi.readNamespacedPod(name, namespace);
312+
const response = await k8sCoreApi.readNamespacedPod({
313+
name,
314+
namespace,
315+
});
311316

312317
// Convert JSON to formatted YAML
313-
const formattedYaml = yaml.dump(response.body, {
318+
const formattedYaml = yaml.dump(response, {
314319
indent: 2,
315320
lineWidth: -1,
316321
noRefs: true,
@@ -332,16 +337,14 @@ app.get("/api/pod/:namespace/:name/yaml", async (req, res) => {
332337
// Get all Jobs (no pagination)
333338
app.get("/api/all-jobs", async (req, res) => {
334339
try {
335-
const response = await k8sApi.listClusterCustomObject(
336-
"batch.volcano.sh",
337-
"v1alpha1",
338-
"jobs", // 修改这里:从 "jobs" 改为 "vcjobs"
339-
{
340-
pretty: true,
341-
},
342-
);
340+
const response = await k8sApi.listClusterCustomObject({
341+
group: "batch.volcano.sh",
342+
version: "v1alpha1",
343+
plural: "jobs", // 修改这里:从 "jobs" 改为 "vcjobs"
344+
pretty: true,
345+
});
343346

344-
const jobs = response.body.items.map((job) => ({
347+
const jobs = response.items.map((job) => ({
345348
...job,
346349
status: {
347350
state: job.status?.state || getJobState(job),
@@ -375,14 +378,14 @@ function getJobState(job) {
375378
// Get all Queues (no pagination)
376379
app.get("/api/all-queues", async (req, res) => {
377380
try {
378-
const response = await k8sApi.listClusterCustomObject(
379-
"scheduling.volcano.sh",
380-
"v1beta1",
381-
"queues",
382-
);
381+
const response = await k8sApi.listClusterCustomObject({
382+
group: "scheduling.volcano.sh",
383+
version: "v1beta1",
384+
plural: "queues",
385+
});
383386
res.json({
384-
items: response.body.items,
385-
totalCount: response.body.items.length,
387+
items: response.items,
388+
totalCount: response.items.length,
386389
});
387390
} catch (error) {
388391
console.error("Error fetching all queues:", error);
@@ -395,8 +398,8 @@ app.get("/api/all-pods", async (req, res) => {
395398
try {
396399
const response = await k8sCoreApi.listPodForAllNamespaces();
397400
res.json({
398-
items: response.body.items,
399-
totalCount: response.body.items.length,
401+
items: response.items,
402+
totalCount: response.items.length,
400403
});
401404
} catch (error) {
402405
console.error("Error fetching all pods:", error);
@@ -407,11 +410,11 @@ app.get("/api/all-pods", async (req, res) => {
407410
const verifyVolcanoSetup = async () => {
408411
try {
409412
// Verify CRD access
410-
await k8sApi.listClusterCustomObject(
411-
"batch.volcano.sh",
412-
"v1alpha1",
413-
"jobs",
414-
);
413+
await k8sApi.listClusterCustomObject({
414+
group: "batch.volcano.sh",
415+
version: "v1alpha1",
416+
plural: "jobs",
417+
});
415418
return true;
416419
} catch (error) {
417420
console.error("Volcano verification failed:", error);

0 commit comments

Comments
 (0)