Skip to content

Commit 4a230d7

Browse files
joaquimrochasniok
authored andcommitted
aksd: Fix importing AKS project from managed namespaces
It was always trying to set up the kubeconfig without the namespace info.
1 parent 499300d commit 4a230d7

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

app/electron/aks-cluster.ts

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ function mergeKubeconfig(existingConfig: string, newConfig: string): KubeConfig
235235
* @param clusterName - AKS cluster name
236236
* @param isDev - Whether running in development mode
237237
* @param resourcesPath - Path to resources directory
238+
* @param managedNamespace - Optional managed namespace name to use for scoped credentials
238239
* @returns Promise with success status and message
239240
*/
240241
export async function registerAKSCluster(
@@ -243,27 +244,49 @@ export async function registerAKSCluster(
243244
clusterName: string,
244245
isAzureRBACEnabled: boolean,
245246
isDev: boolean,
246-
resourcesPath: string
247+
resourcesPath: string,
248+
managedNamespace?: string
247249
): Promise<RegisterAKSClusterResult> {
248250
const tempKubeconfigPath = path.join(os.tmpdir(), `kubeconfig-${Date.now()}.yaml`);
249251

250252
try {
251253
// Step 1: Get the kubeconfig to a temporary file with --format azure
252-
console.log('[AKS] Getting credentials for cluster:', clusterName);
253-
const args = [
254-
'aks',
255-
'get-credentials',
256-
'--subscription',
257-
subscriptionId,
258-
'--resource-group',
259-
resourceGroup,
260-
'--name',
261-
clusterName,
262-
'--format',
263-
'azure',
264-
'--file',
265-
tempKubeconfigPath,
266-
];
254+
// Use namespace get-credentials if a managed namespace is provided
255+
const args: string[] = ['aks'];
256+
257+
if (managedNamespace) {
258+
console.log(
259+
'[AKS] Getting namespace credentials for cluster:',
260+
clusterName,
261+
'namespace:',
262+
managedNamespace
263+
);
264+
args.push(
265+
'namespace',
266+
'get-credentials',
267+
'--cluster-name',
268+
clusterName,
269+
'--resource-group',
270+
resourceGroup,
271+
'--name',
272+
managedNamespace,
273+
'--subscription',
274+
subscriptionId
275+
);
276+
} else {
277+
console.log('[AKS] Getting credentials for cluster:', clusterName);
278+
args.push(
279+
'get-credentials',
280+
'--subscription',
281+
subscriptionId,
282+
'--resource-group',
283+
resourceGroup,
284+
'--name',
285+
clusterName
286+
);
287+
}
288+
289+
args.push('--format', 'azure', '--file', tempKubeconfigPath);
267290

268291
try {
269292
// Use the shared command execution logic from runCmd.ts
@@ -306,7 +329,7 @@ export async function registerAKSCluster(
306329
console.log('[AKS] Skipping az-kubelogin since Azure RBAC is disabled');
307330
modifiedKubeconfig = tempKubeconfig;
308331
}
309-
332+
310333
// Step 3: Merge into main kubeconfig
311334
const kubeconfigPath = path.join(os.homedir(), '.kube', 'config');
312335
const kubeconfigDir = path.dirname(kubeconfigPath);

app/electron/main.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,13 @@ async function startElecron() {
18211821
'register-aks-cluster',
18221822
async (
18231823
event,
1824-
data: { subscriptionId: string; resourceGroup: string; clusterName: string, isAzureRBACEnabled: boolean }
1824+
data: {
1825+
subscriptionId: string;
1826+
resourceGroup: string;
1827+
clusterName: string;
1828+
isAzureRBACEnabled: boolean;
1829+
managedNamespace?: string;
1830+
}
18251831
) => {
18261832
const { registerAKSCluster } = await import('./aks-cluster');
18271833
const resourcesDir = isDev
@@ -1833,7 +1839,8 @@ async function startElecron() {
18331839
data.clusterName,
18341840
data.isAzureRBACEnabled,
18351841
isDev,
1836-
resourcesDir
1842+
resourcesDir,
1843+
data.managedNamespace
18371844
);
18381845
}
18391846
);

app/electron/preload.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ contextBridge.exposeInMainWorld('desktopApi', {
6969
subscriptionId: string,
7070
resourceGroup: string,
7171
clusterName: string,
72-
isAzureRBACEnabled: boolean
72+
isAzureRBACEnabled: boolean,
73+
managedNamespace?: string
7374
): Promise<{ success: boolean; message: string }> => {
7475
return ipcRenderer.invoke('register-aks-cluster', {
7576
subscriptionId,
7677
resourceGroup,
7778
clusterName,
7879
isAzureRBACEnabled,
80+
managedNamespace,
7981
});
8082
},
8183

0 commit comments

Comments
 (0)