private async handleKaitoInstallation()

in src/panels/KaitoPanel.ts [101:193]


    private async handleKaitoInstallation(webview: MessageSink<ToWebViewMsgDef>) {
        // 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.",
            });
            return;
        }

        // Get the feature registration state
        const getFeatureClientRegisterState = await longRunning(
            `Getting the AIToolchainOperator registration state.`,
            () => {
                return this.featureClient.features.get("Microsoft.ContainerService", "AIToolchainOperatorPreview");
            },
        );

        if (getFeatureClientRegisterState.properties?.state !== "Registered") {
            // Register the feature
            const featureRegistrationPoller = await longRunning(`Registering the AIToolchainOperator.`, () => {
                return this.featureClient.features.register(
                    "Microsoft.ContainerService",
                    "AIToolchainOperatorPreview",
                    {},
                );
            });

            if (featureRegistrationPoller.properties?.state !== "Registered") {
                await longRunning(`Waiting for the AIToolchainOperator registration to complete.`, () => {
                    return this.registerKaitoFeature(webview);
                });
            }
        }

        // Install kaito enablement
        const kaitoInstallationResult = await longRunning(
            `Enabling the KAITO for cluster '${this.clusterName}'.`,
            () => {
                return this.handleKaitoInstallationLogic(currentJson, webview);
            },
        );

        if (kaitoInstallationResult && failed(kaitoInstallationResult)) {
            vscode.window.showErrorMessage(
                `Error installing KAITO addon for ${this.clusterName}: ${kaitoInstallationResult.error}`,
            );
            return;
        }

        // install Kaito Federated Credentials and role Assignments
        try {
            const installKaitoFederatedCredentialsAndRoleAssignments = await longRunning(
                `Installing KAITO Federated Credentials and role Assignments.`,
                () => {
                    return this.installKaitoComponents();
                },
            );

            if (failed(installKaitoFederatedCredentialsAndRoleAssignments)) {
                //installing federated credentionals failed
                const errorMessage = installKaitoFederatedCredentialsAndRoleAssignments.error;
                vscode.window.showErrorMessage(
                    `Error installing KAITO Federated Credentials and role Assignments: ${errorMessage}`,
                );
                webview.postKaitoInstallProgressUpdate({
                    operationDescription: "Installing Federated Credentials Failed",
                    event: 3,
                    errorMessage: errorMessage,
                });
                return;
            }

            //kaito installation succeeded
            webview.postKaitoInstallProgressUpdate({
                operationDescription: "Installing KAITO succeeded",
                event: 4,
                errorMessage: undefined,
            });
        } catch (ex) {
            vscode.window.showErrorMessage(
                `Error installing KAITO Federated Credentials and role Assignments: ${getErrorMessage(ex)}`,
            );
        }
    }