Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 43 additions & 19 deletions app/electron/aks-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ function mergeKubeconfig(existingConfig: string, newConfig: string): KubeConfig
* @param clusterName - AKS cluster name
* @param isDev - Whether running in development mode
* @param resourcesPath - Path to resources directory
* @param managedNamespace - Optional managed namespace name to use for scoped credentials
* @returns Promise with success status and message
*/
export async function registerAKSCluster(
Expand All @@ -243,27 +244,51 @@ export async function registerAKSCluster(
clusterName: string,
isAzureRBACEnabled: boolean,
isDev: boolean,
resourcesPath: string
resourcesPath: string,
managedNamespace?: string
): Promise<RegisterAKSClusterResult> {
const tempKubeconfigPath = path.join(os.tmpdir(), `kubeconfig-${Date.now()}.yaml`);

try {
// Step 1: Get the kubeconfig to a temporary file with --format azure
console.log('[AKS] Getting credentials for cluster:', clusterName);
const args = [
'aks',
'get-credentials',
'--subscription',
subscriptionId,
'--resource-group',
resourceGroup,
'--name',
clusterName,
'--format',
'azure',
'--file',
tempKubeconfigPath,
];
// Use namespace get-credentials if a managed namespace is provided
const args: string[] = ['aks'];

if (managedNamespace) {
console.log(
'[AKS] Getting namespace credentials for cluster:',
clusterName,
'namespace:',
managedNamespace
);
args.push(
'namespace',
'get-credentials',
'--cluster-name',
clusterName,
'--resource-group',
resourceGroup,
'--name',
managedNamespace,
'--subscription',
subscriptionId
);
} else {
console.log('[AKS] Getting credentials for cluster:', clusterName);
args.push(
'get-credentials',
'--subscription',
subscriptionId,
'--resource-group',
resourceGroup,
'--name',
clusterName,
'--format',
'azure'
);
}

args.push('--file', tempKubeconfigPath);

try {
// Use the shared command execution logic from runCmd.ts
Expand Down Expand Up @@ -298,15 +323,14 @@ export async function registerAKSCluster(
// Step 2: Read and modify the temporary kubeconfig
const tempKubeconfig = fs.readFileSync(tempKubeconfigPath, 'utf8');
let modifiedKubeconfig: string;
console.log('[AKS] isAzureRBACEnabled:', isAzureRBACEnabled);
if (isAzureRBACEnabled) {
if (tempKubeconfig.includes('command: kubelogin')) {
console.log('[AKS] Adding az-kubelogin to kubeconfig since Azure RBAC is enabled');
modifiedKubeconfig = addAzKubeloginToKubeconfig(tempKubeconfig, isDev, resourcesPath);
} else {
console.log('[AKS] Skipping az-kubelogin since Azure RBAC is disabled');
modifiedKubeconfig = tempKubeconfig;
}

// Step 3: Merge into main kubeconfig
const kubeconfigPath = path.join(os.homedir(), '.kube', 'config');
const kubeconfigDir = path.dirname(kubeconfigPath);
Expand Down
11 changes: 9 additions & 2 deletions app/electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1821,7 +1821,13 @@ async function startElecron() {
'register-aks-cluster',
async (
event,
data: { subscriptionId: string; resourceGroup: string; clusterName: string, isAzureRBACEnabled: boolean }
data: {
subscriptionId: string;
resourceGroup: string;
clusterName: string;
isAzureRBACEnabled: boolean;
managedNamespace?: string;
}
) => {
const { registerAKSCluster } = await import('./aks-cluster');
const resourcesDir = isDev
Expand All @@ -1833,7 +1839,8 @@ async function startElecron() {
data.clusterName,
data.isAzureRBACEnabled,
isDev,
resourcesDir
resourcesDir,
data.managedNamespace
);
}
);
Expand Down
6 changes: 5 additions & 1 deletion app/electron/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ contextBridge.exposeInMainWorld('desktopApi', {
subscriptionId: string,
resourceGroup: string,
clusterName: string,
isAzureRBACEnabled: boolean
isAzureRBACEnabled: boolean,
managedNamespace?: string
): Promise<{ success: boolean; message: string }> => {
return ipcRenderer.invoke('register-aks-cluster', {
subscriptionId,
resourceGroup,
clusterName,
isAzureRBACEnabled,
managedNamespace,
});
},

Expand All @@ -85,4 +87,6 @@ contextBridge.exposeInMainWorld('desktopApi', {
): Promise<{ success: boolean; content?: string; error?: string }> => {
return ipcRenderer.invoke('get-license-file', filename);
},

platform: process.platform,
});
Loading
Loading