Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
momom-i committed Mar 14, 2022
1 parent 02b9633 commit 659a0ce
Show file tree
Hide file tree
Showing 28 changed files with 202 additions and 219 deletions.
22 changes: 9 additions & 13 deletions web/api/v1/node.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { V1Node, V1NodeList } from "@kubernetes/client-node";
import { k8sInstance } from "@/api/v1/index";

export const applyNode = async (req: V1Node, onError: (_: string) => void) => {
export const applyNode = async (req: V1Node) => {
try {
if (!req.metadata?.name) {
onError("metadata.name is not provided");
return;
throw new Error(`metadata.name is not provided`);
}
req.kind = "Node";
req.apiVersion = "v1";
Expand All @@ -16,36 +15,33 @@ export const applyNode = async (req: V1Node, onError: (_: string) => void) => {
);
return res.data;
} catch (e: any) {
onError("failed to applyNode: " + e);
throw new Error(`failed to apply node: ${e}`);
}
};

export const listNode = async (onError: (_: string) => void) => {
export const listNode = async () => {
try {
const res = await k8sInstance.get<V1NodeList>(`/nodes`, {});
return res.data;
} catch (e: any) {
onError("failed to listNode: " + e);
throw new Error(`failed to list nodes: ${e}`);
}
};

export const getNode = async (name: string, onError: (_: string) => void) => {
export const getNode = async (name: string) => {
try {
const res = await k8sInstance.get<V1Node>(`/nodes/${name}`, {});
return res.data;
} catch (e: any) {
onError("failed to getNode: " + e);
throw new Error(`failed to get node: ${e}`);
}
};

export const deleteNode = async (
name: string,
onError: (_: string) => void
) => {
export const deleteNode = async (name: string) => {
try {
const res = await k8sInstance.delete(`/nodes/${name}`, {});
return res.data;
} catch (e: any) {
onError("failed to deleteNode: " + e);
throw new Error(`failed to delete node: ${e}`);
}
};
19 changes: 9 additions & 10 deletions web/api/v1/pod.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { V1Pod, V1PodList } from "@kubernetes/client-node";
import { k8sInstance, namespaceURL } from "@/api/v1/index";

export const applyPod = async (req: V1Pod, onError: (_: string) => void) => {
export const applyPod = async (req: V1Pod) => {
try {
if (!req.metadata?.name) {
onError("metadata.name is not provided");
return;
throw new Error(`metadata.name is not provided`);
}
req.kind = "Pod";
req.apiVersion = "v1";
Expand All @@ -16,39 +15,39 @@ export const applyPod = async (req: V1Pod, onError: (_: string) => void) => {
);
return res.data;
} catch (e: any) {
onError("failed to applyPod: " + e);
throw new Error(`failed to apply pod: ${e}`);
}
};

export const listPod = async (onError: (_: string) => void) => {
export const listPod = async () => {
try {
const res = await k8sInstance.get<V1PodList>(namespaceURL + `/pods`, {});
return res.data;
} catch (e: any) {
onError("failed to listPod: " + e);
throw new Error(`failed to list pods: ${e}`);
}
};

export const getPod = async (name: string, onError: (_: string) => void) => {
export const getPod = async (name: string) => {
try {
const res = await k8sInstance.get<V1Pod>(
namespaceURL + `/pods/${name}`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to getPod: " + e);
throw new Error(`failed to get pod: ${e}`);
}
};

export const deletePod = async (name: string, onError: (_: string) => void) => {
export const deletePod = async (name: string) => {
try {
const res = await k8sInstance.delete(
namespaceURL + `/pods/${name}?gracePeriodSeconds=0`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to deletePod: " + e);
throw new Error(`failed to delete pod: ${e}`);
}
};
28 changes: 9 additions & 19 deletions web/api/v1/priorityclass.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { V1PriorityClass, V1PriorityClassList } from "@kubernetes/client-node";
import { k8sSchedulingInstance } from "@/api/v1/index";

export const applyPriorityClass = async (
req: V1PriorityClass,
onError: (_: string) => void
) => {
export const applyPriorityClass = async (req: V1PriorityClass) => {
try {
if (!req.metadata?.name) {
onError("metadata.name is not provided");
return;
throw new Error(`metadata.name is not provided`);
}
req.kind = "PriorityClass";
req.apiVersion = "scheduling.k8s.io/v1";
Expand All @@ -19,48 +15,42 @@ export const applyPriorityClass = async (
);
return res.data;
} catch (e: any) {
onError("failed to applyPriorityClass: " + e);
throw new Error(`failed to apply priority class: ${e}`);
}
};

export const listPriorityClass = async (onError: (_: string) => void) => {
export const listPriorityClass = async () => {
try {
const res = await k8sSchedulingInstance.get<V1PriorityClassList>(
`/priorityclasses`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to listPriorityClass: " + e);
throw new Error(`failed to list priority classes: ${e}`);
}
};

export const getPriorityClass = async (
name: string,
onError: (_: string) => void
) => {
export const getPriorityClass = async (name: string) => {
try {
const res = await k8sSchedulingInstance.get<V1PriorityClass>(
`/priorityclasses/${name}`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to getPriorityClass: " + e);
throw new Error(`failed to get priority class: ${e}`);
}
};

export const deletePriorityClass = async (
name: string,
onError: (_: string) => void
) => {
export const deletePriorityClass = async (name: string) => {
try {
const res = await k8sSchedulingInstance.delete(
`/priorityclasses/${name}`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to deletePriorityClass: " + e);
throw new Error(`failed to delete priority class: ${e}`);
}
};
28 changes: 9 additions & 19 deletions web/api/v1/pv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import {
} from "@kubernetes/client-node";
import { k8sInstance } from "@/api/v1/index";

export const applyPersistentVolume = async (
req: V1PersistentVolume,
onError: (_: string) => void
) => {
export const applyPersistentVolume = async (req: V1PersistentVolume) => {
try {
if (!req.metadata?.name) {
onError("metadata.name is not provided");
return;
throw new Error(`metadata.name is not provided`);
}
req.kind = "PersistentVolume";
req.apiVersion = "v1";
Expand All @@ -22,45 +18,39 @@ export const applyPersistentVolume = async (
);
return res.data;
} catch (e: any) {
onError("failed to applyPersistentVolume: " + e);
throw new Error(`failed to apply persistent volume: ${e}`);
}
};

export const listPersistentVolume = async (onError: (_: string) => void) => {
export const listPersistentVolume = async () => {
try {
const res = await k8sInstance.get<V1PersistentVolumeList>(
`/persistentvolumes`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to listPersistentVolume: " + e);
throw new Error(`failed to list persistent volumes: ${e}`);
}
};

export const getPersistentVolume = async (
name: string,
onError: (_: string) => void
) => {
export const getPersistentVolume = async (name: string) => {
try {
const res = await k8sInstance.get<V1PersistentVolume>(
`/persistentvolumes/${name}`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to getPersistentVolume: " + e);
throw new Error(`failed to get persistent volume: ${e}`);
}
};

export const deletePersistentVolume = async (
name: string,
onError: (_: string) => void
) => {
export const deletePersistentVolume = async (name: string) => {
try {
const res = await k8sInstance.delete(`/persistentvolumes/${name}`, {});
return res.data;
} catch (e: any) {
onError("failed to deletePersistentVolume: " + e);
throw new Error(`failed to delete persistent volume: ${e}`);
}
};
28 changes: 9 additions & 19 deletions web/api/v1/pvc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import {
import { k8sInstance, namespaceURL } from "@/api/v1/index";

export const applyPersistentVolumeClaim = async (
req: V1PersistentVolumeClaim,
onError: (_: string) => void
req: V1PersistentVolumeClaim
) => {
try {
if (!req.metadata?.name) {
onError("metadata.name is not provided");
return;
throw new Error(`metadata.name is not provided`);
}
req.kind = "PersistentVolumeClaim";
req.apiVersion = "v1";
Expand All @@ -23,50 +21,42 @@ export const applyPersistentVolumeClaim = async (
);
return res.data;
} catch (e: any) {
onError("failed to applyPersistentVolumeClaim: " + e);
throw new Error(`failed to apply persistent volume claim: ${e}`);
}
};

export const listPersistentVolumeClaim = async (
onError: (_: string) => void
) => {
export const listPersistentVolumeClaim = async () => {
try {
const res = await k8sInstance.get<V1PersistentVolumeClaimList>(
namespaceURL + `/persistentvolumeclaims`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to listPersistentVolumeClaim: " + e);
throw new Error(`failed to list persistent volume claims: ${e}`);
}
};

export const getPersistentVolumeClaim = async (
name: string,
onError: (_: string) => void
) => {
export const getPersistentVolumeClaim = async (name: string) => {
try {
const res = await k8sInstance.get<V1PersistentVolumeClaim>(
namespaceURL + `/persistentvolumeclaims/${name}`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to getPersistentVolumeClaim: " + e);
throw new Error(`failed to get persistent volume claim: ${e}`);
}
};

export const deletePersistentVolumeClaim = async (
name: string,
onError: (_: string) => void
) => {
export const deletePersistentVolumeClaim = async (name: string) => {
try {
const res = await k8sInstance.delete(
namespaceURL + `/persistentvolumeclaims/${name}`,
{}
);
return res.data;
} catch (e: any) {
onError("failed to deletePersistentVolumeClaim: " + e);
throw new Error(`failed to delete persistent volume claim: ${e}`);
}
};
5 changes: 2 additions & 3 deletions web/api/v1/schedulerconfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { instance } from "@/api/v1/index";
import { SchedulerConfiguration } from "./types";

export const applySchedulerConfiguration = async (
req: SchedulerConfiguration,
onError: (_msg: string) => void
req: SchedulerConfiguration
) => {
try {
const res = await instance.post<SchedulerConfiguration>(
Expand All @@ -12,7 +11,7 @@ export const applySchedulerConfiguration = async (
);
return res.data;
} catch (e: any) {
onError(e);
throw new Error(`failed to apply scheduler configration: ${e}`);
}
};

Expand Down
Loading

0 comments on commit 659a0ce

Please sign in to comment.