private async installKaitoComponents()

in src/panels/KaitoPanel.ts [272:381]


    private async installKaitoComponents(): Promise<Errorable<string>> {
        const clusterInfo = await getManagedCluster(
            this.sessionProvider,
            this.subscriptionId,
            this.resourceGroupName,
            this.clusterName,
        );

        if (failed(clusterInfo)) {
            vscode.window.showErrorMessage(`Error getting managed cluster info: ${clusterInfo.error}`);
            return { succeeded: false, error: clusterInfo.error };
        }

        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(
                `Error getting aks oidc issuer url, oidc issuer url is undefined/null/empty`,
            );
            return {
                succeeded: false,
                error: "Error getting aks oidc issuer url, oidc issuer url is undefined/null/empty",
            };
        }

        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);
        if (failed(kubectlresult)) {
            vscode.window.showErrorMessage(`Error restarting kaito-gpu-provisioner: ${kubectlresult.error}`);
            return { succeeded: false, error: kubectlresult.error };
        }

        // waiting for gpu provisioner to be ready, which usually takes around 30 seconds
        await new Promise((resolve) => setTimeout(resolve, 35000));
        let gpuProvisionerReady = false;
        const kaitoPods = await getKaitoPods(
            this.sessionProvider,
            this.kubectl,
            this.subscriptionId,
            this.resourceGroupName,
            this.clusterName,
        );
        const gpuProvisionerPod = kaitoPods.find((pod) =>
            pod.imageName.startsWith("mcr.microsoft.com/aks/kaito/gpu-provisioner"),
        );
        if (gpuProvisionerPod === undefined) {
            vscode.window.showErrorMessage(`GPU Provisioner not found`);
            return { succeeded: false, error: "GPU Provisioner not found" };
        }

        // If the pod is already ready, we can skip the loop
        if (
            await isPodReady(
                gpuProvisionerPod.nameSpace,
                gpuProvisionerPod.podName,
                this.kubectl,
                this.kubeConfigFilePath,
            )
        ) {
            gpuProvisionerReady = true;
        } else {
            // If the pod is not ready, we will poll readiness for the next 2 minutes
            const endTime = Date.now() + 120000;
            while (Date.now() < endTime) {
                if (
                    await isPodReady(
                        gpuProvisionerPod.nameSpace,
                        gpuProvisionerPod.podName,
                        this.kubectl,
                        this.kubeConfigFilePath,
                    )
                ) {
                    gpuProvisionerReady = true;
                    break;
                }
                // 5 second delay between checks
                await new Promise((resolve) => setTimeout(resolve, 5000));
            }
        }

        if (!gpuProvisionerReady) {
            vscode.window.showErrorMessage(`GPU Provisioner is not ready`);
            return { succeeded: false, error: "GPU Provisioner is not ready" };
        }

        return { succeeded: true, result: "KAITO components installed successfully" };
    }