[go: nahoru, domu]

Skip to content

Commit

Permalink
Update icon&fix apply (labring#3135)
Browse files Browse the repository at this point in the history
Signed-off-by: zzjin <tczzjin@gmail.com>
  • Loading branch information
zzjin committed May 25, 2023
1 parent 1385217 commit 0007374
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
28 changes: 27 additions & 1 deletion frontend/providers/adminer/public/logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 24 additions & 11 deletions frontend/providers/adminer/src/pages/api/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { generateKubeBlockClusterTemplate } from '@/interfaces/kubeblock';
import { authSession } from '@/service/auth';
import { ApplyYaml, CRDMeta, GetCRD, GetUserDefaultNameSpace, K8sApi } from '@/service/kubernetes';
import { jsonRes } from '@/service/response';
import { HttpError } from '@kubernetes/client-node';
import type { NextApiRequest, NextApiResponse } from 'next';

const AdminerMeta: CRDMeta = {
Expand Down Expand Up @@ -30,17 +31,29 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const adminerName = 'adminer-' + kube_user.name;
const namespace = GetUserDefaultNameSpace(kube_user.name);

// get kubeblock clusters
const connections = await generateKubeBlockClusterTemplate(kc, namespace);
let connections: string[] = [];
try {
// get kubeblock clusters
connections = await generateKubeBlockClusterTemplate(kc, namespace);
} catch (error) {
// console.log(error);
}

// always apply cr, for new db cluster may be added
const adminerYaml = generateAdminerTemplate({
namespace: namespace,
adminerName: adminerName,
currentTime: new Date().toISOString(),
connections: connections
});
const result = await ApplyYaml(kc, adminerYaml);
try {
// always apply cr, for new db cluster may be added
const adminerYaml = generateAdminerTemplate({
namespace: namespace,
adminerName: adminerName,
currentTime: new Date().toISOString(),
connections: connections
});
const result = await ApplyYaml(kc, adminerYaml);
} catch (error) {
const errHttp = error as HttpError;
if (!errHttp || errHttp.response.statusCode !== 409) {
throw error;
}
}

// continue to get user namespace crd
let adminerMetaUser = { ...AdminerMeta };
Expand All @@ -61,7 +74,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// console.log(error)
}

jsonRes(res, { code: 201, data: result, message: '' });
jsonRes(res, { code: 201, data: null, message: '' });
} catch (error) {
// console.log(error)
jsonRes(res, { code: 500, error });
Expand Down

0 comments on commit 0007374

Please sign in to comment.