-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a8fffa
commit 3309222
Showing
13 changed files
with
277 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { ApiResp } from '@/services/kubernet'; | ||
import { authSession } from '@/services/backend/auth'; | ||
import { getK8s } from '@/services/backend/kubernetes'; | ||
import { jsonRes } from '@/services/backend/response'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) { | ||
try { | ||
const { instanceName } = req.query as { instanceName: string }; | ||
if (!instanceName) { | ||
throw new Error('deploy name is empty'); | ||
} | ||
|
||
const { namespace, k8sAuth } = await getK8s({ | ||
kubeconfig: await authSession(req.headers) | ||
}); | ||
|
||
const result = await k8sAuth.deleteClusterRoleBinding(instanceName, namespace); | ||
|
||
jsonRes(res, { data: result }); | ||
} catch (err: any) { | ||
jsonRes(res, { | ||
code: 500, | ||
error: err | ||
}); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
frontend/providers/template/src/pages/api/resource/delCR.ts
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { ApiResp } from '@/services/kubernet'; | ||
import { authSession } from '@/services/backend/auth'; | ||
import { getK8s } from '@/services/backend/kubernetes'; | ||
import { jsonRes } from '@/services/backend/response'; | ||
import pluralize from 'pluralize'; | ||
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) { | ||
try { | ||
const { name, apiVersion, kind } = req.query as Record< | ||
'name' | 'apiVersion' | 'kind', | ||
undefined | null | string | ||
>; | ||
if (!name || !apiVersion || !kind) { | ||
return jsonRes(res, { message: 'bad request', code: 400 }); | ||
} | ||
const [group, version] = apiVersion.split('/'); | ||
if (!version || !group) return jsonRes(res, { message: 'bad request', code: 400 }); | ||
const client = await getK8s({ | ||
kubeconfig: await authSession(req.headers) | ||
}); | ||
const plural = pluralize.plural(kind.toLocaleLowerCase()); | ||
const result = await client.k8sCustomObjects.deleteNamespacedCustomObject( | ||
group, | ||
version, | ||
client.namespace, | ||
plural, | ||
name | ||
); | ||
|
||
jsonRes(res, { data: result }); | ||
} catch (err: any) { | ||
jsonRes(res, { | ||
code: 500, | ||
error: err | ||
}); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
frontend/providers/template/src/pages/api/resource/delPersistentVolumeClaim.ts
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
import { ApiResp } from '@/services/kubernet'; | ||
import { authSession } from '@/services/backend/auth'; | ||
import { K8sApi, getK8s } from '@/services/backend/kubernetes'; | ||
import { jsonRes } from '@/services/backend/response'; | ||
|
||
export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) { | ||
try { | ||
const { instanceName } = req.query as { instanceName: string }; | ||
if (!instanceName) { | ||
throw new Error('pvc name is empty'); | ||
} | ||
|
||
const { namespace, k8sCore } = await getK8s({ | ||
kubeconfig: await authSession(req.headers) | ||
}); | ||
|
||
// 删除 pvc | ||
const result = await k8sCore.deleteNamespacedPersistentVolumeClaim(instanceName, namespace); | ||
jsonRes(res, { data: result }); | ||
} catch (err: any) { | ||
jsonRes(res, { | ||
code: 500, | ||
error: err | ||
}); | ||
} | ||
} |
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.