Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/reconcile cluster using update #280

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@
"command": "aks.aksAbortLastOperationInCluster",
"title": "Abort Last Operation"
},
{
"command": "aks.aksReconcileCluster",
"title": "Reconcile Cluster"
},
{
"command": "aks.aksInspektorGadgetShow",
"title": "Show Inspektor Gadget"
Expand Down Expand Up @@ -369,6 +373,10 @@
{
"command": "aks.aksAbortLastOperationInCluster",
"group": "navigation"
},
{
"command": "aks.aksReconcileCluster",
"group": "navigation"
}
]
},
Expand Down
39 changes: 39 additions & 0 deletions src/commands/aksReconcileCluster/aksReconcileCluster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import * as vscode from 'vscode';
import * as k8s from 'vscode-kubernetes-tools-api';
import { IActionContext } from "@microsoft/vscode-azext-utils";
import { reconcileUsingUpdateInCluster, getAksClusterTreeItem } from '../utils/clusters';
import { failed, succeeded } from '../utils/errorable';
import { longRunning } from '../utils/host';

export default async function aksReconcileCluster(
_context: IActionContext,
target: any
): Promise<void> {
const cloudExplorer = await k8s.extension.cloudExplorer.v1;

const cluster = getAksClusterTreeItem(target, cloudExplorer);
if (failed(cluster)) {
vscode.window.showErrorMessage(cluster.error);
return;
}

const clusterName = cluster.result.name;

const answer = await vscode.window.showInformationMessage(`Do you want to reconcile/update operation on cluster ${clusterName}?`, "Yes", "No");

if (answer === "Yes") {
const result = await longRunning(
`Reconciling/update last cluster operation in ${clusterName}.`,
async () => {
return await reconcileUsingUpdateInCluster(cluster.result, clusterName)
});

if (failed(result)) {
vscode.window.showErrorMessage(result.error);
}

if (succeeded(result)) {
vscode.window.showInformationMessage(result.result);
}
}
}
18 changes: 18 additions & 0 deletions src/commands/utils/clusters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,24 @@ export async function abortLastOperationInCluster(
}
}

export async function reconcileUsingUpdateInCluster(
target: AksClusterTreeItem,
clusterName: string
): Promise<Errorable<string>> {
try {
// Pleaset note: here is in the only place this way of reconcile is documented: https://learn.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-update()-examples
const containerClient = getContainerClient(target);
const getClusterInfo = await containerClient.managedClusters.get(target.resourceGroupName, clusterName);
await containerClient.managedClusters.beginCreateOrUpdateAndWait(target.resourceGroupName, clusterName, {
location: getClusterInfo.location,
})

return { succeeded: true, result: "Reconcile/Update cluster succeeded." };
} catch (ex) {
return { succeeded: false, error: `Error invoking ${clusterName} managed cluster: ${getErrorMessage(ex)}` };
}
}

export async function rotateClusterCert(
target: AksClusterTreeItem,
clusterName: string
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import aksRotateClusterCert from './commands/aksRotateClusterCert/aksRotateClust
import { aksInspektorGadgetShow } from './commands/aksInspektorGadget/aksInspektorGadget';
import aksCreateCluster from './commands/aksCreateCluster/aksCreateCluster';
import aksAbortLastOperation from './commands/aksAbortLastOperation/aksAbortLastOperation';
import aksReconcileCluster from './commands/aksReconcileCluster/aksReconcileCluster';

export async function activate(context: vscode.ExtensionContext) {
const cloudExplorer = await k8s.extension.cloudExplorer.v1;
Expand Down Expand Up @@ -73,6 +74,7 @@ export async function activate(context: vscode.ExtensionContext) {
registerCommandWithTelemetry('aks.aksDeleteCluster', aksDeleteCluster);
registerCommandWithTelemetry('aks.aksRotateClusterCert', aksRotateClusterCert);
registerCommandWithTelemetry('aks.aksAbortLastOperationInCluster', aksAbortLastOperation);
registerCommandWithTelemetry('aks.aksReconcileCluster', aksReconcileCluster);
registerCommandWithTelemetry('aks.aksInspektorGadgetShow', aksInspektorGadgetShow);
registerCommandWithTelemetry('aks.createCluster', aksCreateCluster);

Expand Down
Loading