Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:launchpad resource update in checkPermission API #5077

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/providers/applaunchpad/src/api/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ export const getUserAccount = () => GET<AccountCRD>('/api/guide/getAccount');

export const getPriceBonus = () => GET('/api/guide/getBonus');

export const checkPermission = (payload: { appName: string; resourceType: 'deploy' | 'sts' }) =>
export const checkPermission = (payload: { appName: string }) =>
GET('/api/platform/checkPermission', payload);
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ import * as k8s from '@kubernetes/client-node';

export default async function handler(req: NextApiRequest, res: NextApiResponse<ApiResp>) {
try {
const { appName, resourceType } = req.query as {
appName: string;
resourceType: 'deploy' | 'sts';
};

if (!appName || !resourceType) {
throw new Error('appName or resourceType is empty');
}
const { appName } = req.query as { appName: string };
if (!appName) throw new Error('appName is empty');

const { k8sApp, namespace } = await getK8s({
kubeconfig: await authSession(req.headers)
Expand All @@ -32,7 +26,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
headers: { 'Content-type': k8s.PatchUtils.PATCH_FORMAT_STRATEGIC_MERGE_PATCH }
};

if (resourceType === 'deploy') {
let deploymentUpdated = false;

try {
await k8sApp.patchNamespacedDeployment(
appName,
namespace,
Expand All @@ -44,7 +40,14 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
undefined,
options
);
} else if (resourceType === 'sts') {
deploymentUpdated = true;
} catch (deployErr: any) {
if (deployErr?.response?.statusCode !== 404) {
throw deployErr;
}
}

if (!deploymentUpdated) {
await k8sApp.patchNamespacedStatefulSet(
appName,
namespace,
Expand All @@ -58,22 +61,19 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
);
}

jsonRes(res, {
code: 200,
data: 'success'
});
jsonRes(res, { code: 200, data: 'success' });
} catch (err: any) {
if (err?.body?.code === 403 && err?.body?.message.includes('40001')) {
return jsonRes(res, {
code: 200,
data: 'insufficient_funds',
message: err?.body?.message
message: err.body.message
});
}

jsonRes(res, {
code: 500,
error: err?.body
error: err?.body || err?.message
});
}
}
5 changes: 2 additions & 3 deletions frontend/providers/applaunchpad/src/pages/app/edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
if (appName) {
try {
const result = await checkPermission({
appName: data.appName,
resourceType: !!data.storeList?.length ? 'sts' : 'deploy'
appName: data.appName
});
if (result === 'insufficient_funds') {
return toast({
Expand All @@ -370,7 +369,7 @@ const EditApp = ({ appName, tabType }: { appName?: string; tabType: string }) =>
} catch (error: any) {
return toast({
status: 'warning',
title: error
title: error?.message || 'Check Error'
});
}
}
Expand Down
Loading