generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Request kube apiserver directly from frontend
- Loading branch information
Showing
11 changed files
with
251 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,51 @@ | ||
import { V1Node, V1NodeList } from "@kubernetes/client-node"; | ||
import { instance } from "@/api/v1/index"; | ||
import { k8sInstance } from "@/api/v1/index"; | ||
|
||
export const applyNode = async (req: V1Node, onError: (_: string) => void) => { | ||
try { | ||
const res = await instance.post<V1Node>(`/nodes`, req); | ||
if (!req.metadata?.name) { | ||
onError("metadata.name is not provided"); | ||
return; | ||
} | ||
const res = await k8sInstance.patch<V1Node>( | ||
`/nodes/${req.metadata.name}?fieldManager=simulator`, | ||
req, | ||
{ headers: { "Content-Type": "application/strategic-merge-patch+json" } } | ||
); | ||
return res.data; | ||
} catch (e: any) { | ||
onError(e); | ||
try { | ||
const res = await createNode(req, onError); | ||
return res; | ||
} catch (e: any) { | ||
onError(e); | ||
} | ||
} | ||
}; | ||
|
||
export const listNode = async () => { | ||
const res = await instance.get<V1NodeList>(`/nodes`, {}); | ||
const res = await k8sInstance.get<V1NodeList>(`/nodes`, {}); | ||
return res.data; | ||
}; | ||
|
||
export const getNode = async (name: string) => { | ||
const res = await instance.get<V1Node>(`/nodes/${name}`, {}); | ||
const res = await k8sInstance.get<V1Node>(`/nodes/${name}`, {}); | ||
return res.data; | ||
}; | ||
|
||
export const deleteNode = async (name: string) => { | ||
const res = await instance.delete(`/nodes/${name}`, {}); | ||
const res = await k8sInstance.delete(`/nodes/${name}`, {}); | ||
return res.data; | ||
}; | ||
|
||
const createNode = async (req: V1Node, onError: (_: string) => void) => { | ||
try { | ||
const res = await k8sInstance.post<V1Node>( | ||
`/nodes?fieldManager=simulator`, | ||
req | ||
); | ||
return res.data; | ||
} catch (e: any) { | ||
onError(e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,54 @@ | ||
import { V1Pod, V1PodList } from "@kubernetes/client-node"; | ||
import { instance } from "@/api/v1/index"; | ||
import { k8sInstance, namespaceURL } from "@/api/v1/index"; | ||
|
||
export const applyPod = async (req: V1Pod, onError: (_: string) => void) => { | ||
try { | ||
const res = await instance.post<V1Pod>(`/pods`, req); | ||
if (!req.metadata?.name) { | ||
onError("metadata.name is not provided"); | ||
return; | ||
} | ||
const res = await k8sInstance.patch<V1Pod>( | ||
namespaceURL + `/pods/${req.metadata.name}?fieldManager=simulator`, | ||
req, | ||
{ headers: { "Content-Type": "application/strategic-merge-patch+json" } } | ||
); | ||
return res.data; | ||
} catch (e: any) { | ||
onError(e); | ||
try { | ||
const res = await createPod(req, onError); | ||
return res; | ||
} catch (e: any) { | ||
onError(e); | ||
} | ||
} | ||
}; | ||
|
||
export const listPod = async () => { | ||
const res = await instance.get<V1PodList>(`/pods`, {}); | ||
const res = await k8sInstance.get<V1PodList>(namespaceURL + `/pods`, {}); | ||
return res.data; | ||
}; | ||
|
||
export const getPod = async (name: string) => { | ||
const res = await instance.get<V1Pod>(`/pods/${name}`, {}); | ||
const res = await k8sInstance.get<V1Pod>(namespaceURL + `/pods/${name}`, {}); | ||
return res.data; | ||
}; | ||
|
||
export const deletePod = async (name: string) => { | ||
const res = await instance.delete(`/pods/${name}`, {}); | ||
const res = await k8sInstance.delete( | ||
namespaceURL + `/pods/${name}?gracePeriodSeconds=0`, | ||
{} | ||
); | ||
return res.data; | ||
}; | ||
|
||
const createPod = async (req: V1Pod, onError: (_: string) => void) => { | ||
try { | ||
const res = await k8sInstance.post<V1Pod>( | ||
namespaceURL + `/pods?fieldManager=simulator`, | ||
req | ||
); | ||
return res.data; | ||
} catch (e: any) { | ||
onError(e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,66 @@ | ||
import { V1PriorityClass, V1PriorityClassList } from "@kubernetes/client-node"; | ||
import { instance } from "@/api/v1/index"; | ||
import { k8sSchedulingInstance } from "@/api/v1/index"; | ||
|
||
export const applyPriorityClass = async ( | ||
req: V1PriorityClass, | ||
onError: (_: string) => void | ||
) => { | ||
try { | ||
const res = await instance.post<V1PriorityClass>(`/priorityclasses`, req); | ||
if (!req.metadata?.name) { | ||
onError("metadata.name is not provided"); | ||
return; | ||
} | ||
const res = await k8sSchedulingInstance.patch<V1PriorityClass>( | ||
`/priorityclasses/${req.metadata.name}?fieldManager=simulator`, | ||
req, | ||
{ headers: { "Content-Type": "application/strategic-merge-patch+json" } } | ||
); | ||
return res.data; | ||
} catch (e: any) { | ||
onError(e); | ||
try { | ||
const res = await createPriorityClass(req, onError); | ||
return res; | ||
} catch (e: any) { | ||
onError(e); | ||
} | ||
} | ||
}; | ||
|
||
export const listPriorityClass = async () => { | ||
const res = await instance.get<V1PriorityClassList>(`/priorityclasses`, {}); | ||
const res = await k8sSchedulingInstance.get<V1PriorityClassList>( | ||
`/priorityclasses`, | ||
{} | ||
); | ||
return res.data; | ||
}; | ||
|
||
export const getPriorityClass = async (name: string) => { | ||
const res = await instance.get<V1PriorityClass>( | ||
const res = await k8sSchedulingInstance.get<V1PriorityClass>( | ||
`/priorityclasses/${name}`, | ||
{} | ||
); | ||
return res.data; | ||
}; | ||
|
||
export const deletePriorityClass = async (name: string) => { | ||
const res = await instance.delete(`/priorityclasses/${name}`, {}); | ||
const res = await k8sSchedulingInstance.delete( | ||
`/priorityclasses/${name}`, | ||
{} | ||
); | ||
return res.data; | ||
}; | ||
|
||
const createPriorityClass = async ( | ||
req: V1PriorityClass, | ||
onError: (_: string) => void | ||
) => { | ||
try { | ||
const res = await k8sSchedulingInstance.post<V1PriorityClass>( | ||
`/priorityclasses?fieldManager=simulator`, | ||
req | ||
); | ||
return res.data; | ||
} catch (e: any) { | ||
onError(e); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.