in src/commands/periscope/periscope.ts [84:207]
async function runAKSPeriscope(
kubectl: k8s.APIAvailable<k8s.KubectlV1>,
clusterNode: AksClusterTreeNode,
clusterKubeConfig: string,
): Promise<void> {
const clusterName = clusterNode.name;
const sessionProvider = await getReadySessionProvider();
if (failed(sessionProvider)) {
vscode.window.showErrorMessage(sessionProvider.error);
return;
}
// Get Diagnostic settings for cluster and get associated storage account information.
const clusterDiagnosticSettings = await longRunning(`Identifying cluster diagnostic settings.`, () =>
getClusterDiagnosticSettings(sessionProvider.result, clusterNode),
);
const extension = getExtension();
if (failed(extension)) {
vscode.window.showErrorMessage(extension.error);
return;
}
const panel = new PeriscopePanel(extension.result.extensionUri);
if (!clusterDiagnosticSettings || !clusterDiagnosticSettings.value?.length) {
// If there is no storage account attached to diagnostic setting, don't move forward and at this point we will render webview with helpful content.
const dataProvider = PeriscopeDataProvider.createForNoDiagnostics(clusterNode.name);
panel.show(dataProvider);
return;
}
// TODO: It's possible to have diagnostics configured, but with no storage account. If that's the case,
// we'll fail silently at this point. Need to improve the UX here.
const clusterStorageAccountId = await chooseStorageAccount(
clusterDiagnosticSettings,
"Select storage account for Periscope deployment:",
);
if (!clusterStorageAccountId) return;
// Generate storage sas keys, manage aks persicope run.
const clusterStorageInfo = await longRunning(`Generating SAS for ${clusterName} cluster.`, () =>
getStorageInfo(sessionProvider.result, kubectl, clusterNode, clusterStorageAccountId, clusterKubeConfig),
);
if (failed(clusterStorageInfo)) {
vscode.window.showErrorMessage(clusterStorageInfo.error);
return;
}
const kustomizeConfig = getKustomizeConfig();
if (failed(kustomizeConfig)) {
vscode.window.showErrorMessage(kustomizeConfig.error);
return;
}
const containerClient = getAksClient(sessionProvider.result, clusterNode.subscriptionId);
// Get the features of the cluster that determine which optional kustomize components to deploy.
const clusterFeatures = await getClusterFeatures(containerClient, clusterNode.resourceGroupName, clusterNode.name);
if (failed(clusterFeatures)) {
vscode.window.showErrorMessage(clusterFeatures.error);
return;
}
// Create a run ID of format: YYYY-MM-DDThh-mm-ssZ
const runId = `${new Date().toISOString().slice(0, 19).replace(/:/g, "-")}Z`;
const aksDeploymentFile = await longRunning(
`Creating AKS Periscope resource specification for ${clusterName}.`,
() =>
prepareAKSPeriscopeKustomizeOverlay(
clusterStorageInfo.result,
kustomizeConfig.result,
clusterFeatures.result,
runId,
),
);
if (failed(aksDeploymentFile)) {
vscode.window.showErrorMessage(aksDeploymentFile.error);
return;
}
const nodeNames = await getNodeNames(kubectl, clusterKubeConfig);
if (failed(nodeNames)) {
vscode.window.showErrorMessage(nodeNames.error);
return;
}
const runCommandResult = await longRunning(`Deploying AKS Periscope to ${clusterName}.`, () =>
deployKustomizeOverlay(kubectl, aksDeploymentFile.result, clusterKubeConfig),
);
const deploymentParameters = {
kubectl,
kustomizeConfig: kustomizeConfig.result,
storage: clusterStorageInfo.result,
clusterKubeConfig,
periscopeNamespace: "aks-periscope",
};
if (failed(runCommandResult)) {
// For a failure running the command result, we display the error in a webview.
const dataProvider = PeriscopeDataProvider.createForDeploymentError(
clusterNode.name,
runId,
runCommandResult.error,
deploymentParameters,
);
panel.show(dataProvider);
return;
}
// Show the webview for successful deployment
const dataProvider = PeriscopeDataProvider.createForDeploymentSuccess(
clusterNode.name,
runId,
nodeNames.result,
deploymentParameters,
);
panel.show(dataProvider);
}