@@ -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 */
240241export 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 ) ;
0 commit comments