private async handleKaitoInstallationLogic()

in src/panels/KaitoPanel.ts [195:270]


    private async handleKaitoInstallationLogic(
        currentJson: GenericResource,
        webview: MessageSink<ToWebViewMsgDef>,
    ): Promise<Errorable<string> | undefined> {
        // Install kaito enablement
        const managedClusterSpec: ManagedCluster = {
            location: currentJson.location!,
            aiToolchainOperatorProfile: { enabled: true },
            oidcIssuerProfile: { enabled: true },
        };

        try {
            const poller = await longRunning("", () => {
                return this.containerServiceClient.managedClusters.beginCreateOrUpdate(
                    this.resourceGroupName,
                    this.clusterName,
                    managedClusterSpec,
                );
            });
            // kaito installation in progress
            webview.postKaitoInstallProgressUpdate({
                operationDescription: "Installing KAITO",
                event: 1,
                errorMessage: undefined,
            });
            poller.onProgress((state) => {
                if (state.status === "succeeded") {
                    webview.postKaitoInstallProgressUpdate({
                        operationDescription: "KAITO Federated Credentials and role Assignments",
                        event: 1,
                        errorMessage: undefined,
                    });
                } else if (state.status === "failed") {
                    webview.postKaitoInstallProgressUpdate({
                        operationDescription: "Installing KAITO failed",
                        event: 3,
                        errorMessage: state.error?.message,
                    });
                }
            });
            await poller.pollUntilDone();

            return { succeeded: true, result: "KAITO installation logic completed successfully" };
        } catch (ex) {
            const errorMessage = isInvalidTemplateDeploymentError(ex)
                ? getInvalidTemplateErrorMessage(ex)
                : getErrorMessage(ex);

            // Retry the operation
            if (RETRY_COUNT < MAX_RETRY) {
                RETRY_COUNT++;
                const answer = await vscode.window.showErrorMessage(
                    `Error installing KAITO addon for ${this.clusterName}: ${errorMessage}`,
                    { modal: true },
                    "Retry",
                );

                // Here the retry logic exist
                if (answer === "Retry") {
                    this.handleKaitoInstallation(webview);
                }
            }

            if (RETRY_COUNT >= MAX_RETRY) {
                vscode.window.showErrorMessage(`Error installing KAITO addon for ${this.clusterName}: ${errorMessage}`);
            }

            webview.postKaitoInstallProgressUpdate({
                operationDescription: "Installing KAITO failed",
                event: 3,
                errorMessage: ex instanceof Error ? ex.message : String(ex),
            });

            return { succeeded: false, error: ex instanceof Error ? ex.message : String(ex) };
        }
    }