Skip to content

Commit

Permalink
Only start abort if cluster provision state is not succeeded.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatsinnit committed Oct 6, 2023
1 parent c3d30e6 commit 3082b0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/commands/aksAbortLastOperation/aksAbortLastOperation.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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") {
Expand Down
15 changes: 15 additions & 0 deletions src/commands/utils/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,21 @@ export async function determineClusterState(
}
}

export async function determineProvisioningState(
target: AksClusterTreeItem,
clusterName: string
): Promise<Errorable<string>> {
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,
Expand Down

0 comments on commit 3082b0f

Please sign in to comment.