diff --git a/src/commands/aksAbortLastOperation/aksAbortLastOperation.ts b/src/commands/aksAbortLastOperation/aksAbortLastOperation.ts index 536ab3f78..3a566dc33 100644 --- a/src/commands/aksAbortLastOperation/aksAbortLastOperation.ts +++ b/src/commands/aksAbortLastOperation/aksAbortLastOperation.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; import * as k8s from 'vscode-kubernetes-tools-api'; import { IActionContext } from "@microsoft/vscode-azext-utils"; -import { abortLastOperationInCluster, getAksClusterTreeItem } from '../utils/clusters'; +import { abortLastOperationInCluster, determineProvisioningState, getAksClusterTreeItem } from '../utils/clusters'; import { failed, succeeded } from '../utils/errorable'; import { longRunning } from '../utils/host'; @@ -18,7 +18,17 @@ export default async function aksAbortLastOperation( } const clusterName = cluster.result.name; + + const clusterProvisioingState = await determineProvisioningState(cluster.result, clusterName); + if (failed(clusterProvisioingState)) { + vscode.window.showErrorMessage(clusterProvisioingState.error); + return; + } + if (clusterProvisioingState.succeeded && clusterProvisioingState.result === "Succeeded") { + vscode.window.showInformationMessage(`Cluster provisioning state is ${clusterProvisioingState} and there is no operation to abort.`); + return; + } const answer = await vscode.window.showInformationMessage(`Do you want to abort last operation in cluster ${clusterName}?`, "Yes", "No"); if (answer === "Yes") { diff --git a/src/commands/utils/clusters.ts b/src/commands/utils/clusters.ts index ce73a6277..45ce41af3 100644 --- a/src/commands/utils/clusters.ts +++ b/src/commands/utils/clusters.ts @@ -338,6 +338,21 @@ export async function determineClusterState( } } +export async function determineProvisioningState( + target: AksClusterTreeItem, + clusterName: string +): Promise> { + try { + const containerClient = getContainerClient(target); + const clusterInfo = (await containerClient.managedClusters.get(target.resourceGroupName, clusterName)); + + return { succeeded: true, result: clusterInfo.provisioningState ?? "" }; + + } catch (ex) { + return { succeeded: false, error: `Error invoking ${clusterName} managed cluster: ${ex}` }; + } +} + export async function startCluster( target: AksClusterTreeItem, clusterName: string,