diff --git a/src/panels/KaitoPanel.ts b/src/panels/KaitoPanel.ts index 65466abed..8074cec96 100644 --- a/src/panels/KaitoPanel.ts +++ b/src/panels/KaitoPanel.ts @@ -136,6 +136,24 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { } private async handleKaitoInstallation(webview: MessageSink) { + // Get current json + const currentJson = await longRunning(`Get current cluster information.`, () => { + return this.resourceManagementClient.resources.getById(this.armId, "2023-08-01"); + }); + + // Prevent KAITO installation on automatic clusters + const skuName = currentJson.sku?.name; + if (skuName === "Automatic") { + webview.postKaitoInstallProgressUpdate({ + operationDescription: "Automatic Cluster Detected", + event: 3, + errorMessage: + "KAITO cannot be installed on automatic clusters. Please try installing KAITO on a standard cluster.", + models: [], + }); + return; + } + // Get the feature registration state const getFeatureClientRegisterState = await longRunning( `Getting the AIToolchainOperator registration state.`, @@ -161,11 +179,6 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { } } - // Get current json - const currentJson = await longRunning(`Get current cluster information.`, () => { - return this.resourceManagementClient.resources.getById(this.armId, "2023-08-01"); - }); - // Install kaito enablement const kaitoInstallationResult = await longRunning( `Enabling the KAITO for cluster '${this.clusterName}'.`, @@ -191,9 +204,18 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { ); if (failed(installKaitoFederatedCredentialsAndRoleAssignments)) { + //installing federated credentionals failed + const errorMessage = installKaitoFederatedCredentialsAndRoleAssignments.error; vscode.window.showErrorMessage( - `Error installing KAITO Federated Credentials and role Assignments: ${installKaitoFederatedCredentialsAndRoleAssignments.error}`, + `Error installing KAITO Federated Credentials and role Assignments: ${errorMessage}`, ); + webview.postKaitoInstallProgressUpdate({ + operationDescription: "Installing Federated Credentials Failed", + event: 3, + errorMessage: errorMessage, + models: [], + }); + return; } //kaito installation succeeded @@ -304,13 +326,18 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { return { succeeded: false, error: clusterInfo.error }; } - await this.installKaitoRoleAssignments( + const roleAssignmentsResult = await this.installKaitoRoleAssignments( clusterInfo.result.nodeResourceGroup!, this.subscriptionId, this.resourceGroupName, this.clusterName, ); + //halt installation if role assignments creation failed + if (failed(roleAssignmentsResult)) { + return { succeeded: false, error: roleAssignmentsResult.error }; + } + const aksOidcIssuerUrl = clusterInfo.result.oidcIssuerProfile?.issuerURL; if (!aksOidcIssuerUrl) { vscode.window.showErrorMessage( @@ -321,12 +348,18 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { error: "Error getting aks oidc issuer url, oidc issuer url is undefined/null/empty", }; } - await this.installKaitoFederatedCredentials( + + const kaitoFederatedCredentialsResult = await this.installKaitoFederatedCredentials( clusterInfo.result.nodeResourceGroup!, this.clusterName, aksOidcIssuerUrl, ); + //halt installation if federated credentials installation failed + if (failed(kaitoFederatedCredentialsResult)) { + return { succeeded: false, error: kaitoFederatedCredentialsResult.error }; + } + //kubectl rollout restart deployment kaito-gpu-provisioner -n kube-system const command = `rollout restart deployment kaito-gpu-provisioner -n kube-system`; const kubectlresult = await invokeKubectlCommand(this.kubectl, this.kubeConfigFilePath, command); @@ -404,14 +437,14 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { subscriptionId: string, resourceGroupName: string, clusterName: string, - ) { + ): Promise> { // get principal id of managed service identity const identityName = `ai-toolchain-operator-${clusterName}`; const identityResult = await getIdentity(this.managedServiceIdentityClient, mcResourceGroup, identityName); if (failed(identityResult)) { vscode.window.showErrorMessage(`Error getting identity: ${identityResult.error}`); - return; + return { succeeded: false, error: identityResult.error }; } const roleAssignment = await createRoleAssignment( @@ -423,17 +456,22 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { ); if (failed(roleAssignment)) { - vscode.window.showWarningMessage( - `Error installing KAITO Federated Credentials and role Assignments: ${roleAssignment.error}`, - ); + // Don't cancel installation if role assignments already exist, user could be attempting to reinstall + if (roleAssignment.error?.includes("already exists")) { + return { succeeded: true, result: "Role assignments already exist" }; + } else { + // cancel installation only if there is an alternate error that conflicts with further steps + return { succeeded: false, error: roleAssignment.error }; + } } + return { succeeded: true, result: "Role assignments created successfully" }; } private async installKaitoFederatedCredentials( nodeResourceGroup: string, clusterName: string, aksOidcIssuerUrl: string, - ) { + ): Promise> { const result = await createFederatedCredential( this.managedServiceIdentityClient, nodeResourceGroup, @@ -445,8 +483,10 @@ export class KaitoPanelDataProvider implements PanelDataProvider<"kaito"> { ); if (failed(result)) { - vscode.window.showErrorMessage(`Error creating federated credentials: ${result.error}`); - return; + // vscode.window.showErrorMessage(`Error creating federated credentials: ${result.error}`); + return { succeeded: false, error: result.error }; + } else { + return { succeeded: true, result: "Federated credentials created successfully" }; } } } diff --git a/webview-ui/src/Kaito/Kaito.module.css b/webview-ui/src/Kaito/Kaito.module.css index 186ccce63..3d1e07b9c 100644 --- a/webview-ui/src/Kaito/Kaito.module.css +++ b/webview-ui/src/Kaito/Kaito.module.css @@ -123,3 +123,7 @@ .installBlurb { margin: 0.5rem 0rem 0.06rem 0rem; } +.errorMessage { + font-weight: 400; + width: 90%; +} diff --git a/webview-ui/src/Kaito/Kaito.tsx b/webview-ui/src/Kaito/Kaito.tsx index b5cc83c24..05cbf8083 100644 --- a/webview-ui/src/Kaito/Kaito.tsx +++ b/webview-ui/src/Kaito/Kaito.tsx @@ -64,7 +64,7 @@ export function Kaito(initialState: InitialState) {

-
+
{state.kaitoInstallStatus === ProgressEventType.NotStarted && (
)} + {state.kaitoInstallStatus === ProgressEventType.Failed && ( +
+

Error installing KAITO.

+

{state.errors}

+
+ )}