Skip to content

Commit

Permalink
feat(applaunchpad, dbprovider, template):support multi ns (#3927)
Browse files Browse the repository at this point in the history
  • Loading branch information
xudaotutou committed Sep 13, 2023
1 parent d3467d2 commit cbcec7e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 11 deletions.
4 changes: 3 additions & 1 deletion frontend/packages/client-sdk/src/master.ts
Expand Up @@ -55,8 +55,10 @@ class MasterSDK {
return {
user: {
id: session.user.userId,
k8sUsername: session.user.k8s_username,
name: session.user.name,
avatar: session.user.avatar
avatar: session.user.avatar,
nsid: session.user.nsid
},
kubeconfig: session.kubeconfig
};
Expand Down
12 changes: 7 additions & 5 deletions frontend/packages/client-sdk/src/types/user.d.ts
Expand Up @@ -30,11 +30,13 @@ export type UserQuotaItemType = {
limit: number;
};

export type UserInfoV1 = {
readonly id: string;
readonly name: string;
readonly avatar: string;
};
export type UserInfoV1 = Readonly<{
id: string;
name: string;
avatar: string;
k8sUsername: string;
nsid: string;
}>;

export type SessionV1 = {
token?: OAuthToken;
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/client-sdk/src/utils/kubernetes.ts
Expand Up @@ -266,7 +266,7 @@ export async function initK8s({ req }: { req: { headers: IncomingHttpHeaders } }
return Promise.reject('User is null');
}

const namespace = `ns-${kube_user.name}`;
const namespace = kc.contexts[0].namespace || `ns-${kube_user.name}`;

return Promise.resolve({
kc,
Expand Down
Expand Up @@ -195,7 +195,7 @@ export async function getK8s({ kubeconfig }: { kubeconfig: string }) {
return Promise.reject('用户不存在');
}

const namespace = `ns-${kube_user.name}`;
const namespace = kc.contexts[0].namespace || `ns-${kube_user.name}`;

const applyYamlList = async (yamlList: string[], type: 'create' | 'replace') => {
// insert namespace
Expand Down
2 changes: 1 addition & 1 deletion frontend/providers/applaunchpad/src/utils/user.ts
Expand Up @@ -18,7 +18,7 @@ export const getUserNamespace = () => {
const kubeConfig = getUserKubeConfig();
const json: any = yaml.load(kubeConfig);
try {
return `ns-${json.users[0].name}`;
return json?.contexts[0]?.context?.namespace || `ns-${json.users[0].name}`;
} catch (err) {
return 'nx-';
}
Expand Down
Expand Up @@ -212,7 +212,7 @@ export async function getK8s({ kubeconfig }: { kubeconfig: string }) {
return Promise.reject('用户不存在');
}

const namespace = GetUserDefaultNameSpace(kube_user.name);
const namespace = kc.contexts[0].namespace || GetUserDefaultNameSpace(kube_user.name);

const applyYamlList = async (yamlList: string[], type: 'create' | 'replace' | 'update') => {
// insert namespace
Expand Down
Expand Up @@ -150,7 +150,7 @@ export async function getK8s({ kubeconfig }: { kubeconfig: string }) {
return Promise.reject('用户不存在');
}

const namespace = GetUserDefaultNameSpace(kube_user.name);
const namespace = kc.contexts[0].namespace || GetUserDefaultNameSpace(kube_user.name);

const applyYamlList = async (yamlList: string[], type: 'create' | 'replace' | 'dryrun') => {
// insert namespace
Expand Down

0 comments on commit cbcec7e

Please sign in to comment.