Skip to content

Commit b564fcc

Browse files
committed
update
1 parent adee9e9 commit b564fcc

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

frontend/desktop/src/pages/api/auth/rotateKubeconfig.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import * as k8s from '@kubernetes/client-node';
66
import { k8sRFC3339Time } from '@/utils/format';
77
import { switchKubeconfigNamespace } from '@/utils/switchKubeconfigNamespace';
88

9-
/**
10-
* Rotate kubeconfig by setting kubeConfigRotateAt timestamp
11-
* This triggers the backend to generate a new kubeconfig
12-
*/
139
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
1410
try {
1511
const regionUser = await verifyAccessToken(req.headers);
@@ -43,11 +39,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
4339
previousKubeconfig = preBody.status.kubeConfig as string;
4440
}
4541
} catch (err) {
46-
// Non-fatal: we can still poll for presence/change after patch.
4742
console.warn('Failed to read previous kubeconfig before rotation:', err);
4843
}
4944

50-
// Patch user spec with kubeConfigRotateAt to trigger rotation
5145
const patches = [
5246
{
5347
op: 'add',
@@ -72,7 +66,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
7266
}
7367
);
7468

75-
// Wait for the new kubeconfig to be generated
7669
const newKubeconfig = await watchKubeconfigUpdate(
7770
adminKc,
7871
group,
@@ -86,7 +79,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
8679
throw new Error('Failed to get updated kubeconfig');
8780
}
8881

89-
// Switch namespace to user's workspace
9082
const kubeconfig = switchKubeconfigNamespace(newKubeconfig, regionUser.workspaceId);
9183

9284
return jsonRes(res, {
@@ -105,18 +97,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
10597
}
10698
}
10799

108-
/**
109-
* Watch for kubeconfig update after rotation
110-
*/
111100
async function watchKubeconfigUpdate(
112101
kc: k8s.KubeConfig,
113102
group: string,
114103
version: string,
115104
plural: string,
116105
name: string,
117106
previousKubeconfig?: string,
118-
interval = 1000,
119-
timeout = 45000
107+
interval = 5000,
108+
timeout = 60000
120109
): Promise<string | null> {
121110
let lastSeenPhase: string | undefined;
122111
let lastSeenMessage: string | undefined;
@@ -142,7 +131,6 @@ async function watchKubeconfigUpdate(
142131
const currentKubeconfig = body?.status?.kubeConfig as string | undefined;
143132
if (currentKubeconfig) {
144133
if (previousKubeconfig === undefined) {
145-
// No baseline to compare, return the first kubeconfig we see.
146134
return currentKubeconfig;
147135
}
148136
if (currentKubeconfig !== previousKubeconfig) {

0 commit comments

Comments
 (0)