diff --git a/package-lock.json b/package-lock.json index fffa67f9..1b18c024 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@azure/arm-compute": "^22.2.0", "@azure/arm-containerregistry": "^10.1.0", "@azure/arm-containerservice": "21.2.0-beta.1", + "@azure/arm-containerservicefleet": "^1.1.0", "@azure/arm-features": "^3.1.0", "@azure/arm-monitor": "^7.0.0", "@azure/arm-msi": "^2.1.0", @@ -170,6 +171,24 @@ "node": ">=18.0.0" } }, + "node_modules/@azure/arm-containerservicefleet": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@azure/arm-containerservicefleet/-/arm-containerservicefleet-1.1.0.tgz", + "integrity": "sha512-KChkmPL/EALau0QXuPPMGXnKvNM//jWlv0O+NUg6T7qLGMAtZsmS0ClVLxOQ373ukQ1AEqHaY9KDdTTVxPvOnw==", + "license": "MIT", + "dependencies": { + "@azure/abort-controller": "^1.0.0", + "@azure/core-auth": "^1.6.0", + "@azure/core-client": "^1.7.0", + "@azure/core-lro": "^2.5.4", + "@azure/core-paging": "^1.2.0", + "@azure/core-rest-pipeline": "^1.14.0", + "tslib": "^2.2.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, "node_modules/@azure/arm-features": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/@azure/arm-features/-/arm-features-3.1.0.tgz", @@ -1908,32 +1927,6 @@ "@vscode/vsce-sign-win32-x64": "2.0.2" } }, - "node_modules/@vscode/vsce-sign-alpine-arm64": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-alpine-arm64/-/vsce-sign-alpine-arm64-2.0.2.tgz", - "integrity": "sha512-E80YvqhtZCLUv3YAf9+tIbbqoinWLCO/B3j03yQPbjT3ZIHCliKZlsy1peNc4XNZ5uIb87Jn0HWx/ZbPXviuAQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "alpine" - ] - }, - "node_modules/@vscode/vsce-sign-alpine-x64": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-alpine-x64/-/vsce-sign-alpine-x64-2.0.2.tgz", - "integrity": "sha512-n1WC15MSMvTaeJ5KjWCzo0nzjydwxLyoHiMJHu1Ov0VWTZiddasmOQHekA47tFRycnt4FsQrlkSCTdgHppn6bw==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "alpine" - ] - }, "node_modules/@vscode/vsce-sign-darwin-arm64": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-darwin-arm64/-/vsce-sign-darwin-arm64-2.0.2.tgz", @@ -1947,84 +1940,6 @@ "darwin" ] }, - "node_modules/@vscode/vsce-sign-darwin-x64": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-darwin-x64/-/vsce-sign-darwin-x64-2.0.2.tgz", - "integrity": "sha512-MCjPrQ5MY/QVoZ6n0D92jcRb7eYvxAujG/AH2yM6lI0BspvJQxp0o9s5oiAM9r32r9tkLpiy5s2icsbwefAQIw==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "darwin" - ] - }, - "node_modules/@vscode/vsce-sign-linux-arm": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-linux-arm/-/vsce-sign-linux-arm-2.0.2.tgz", - "integrity": "sha512-Fkb5jpbfhZKVw3xwR6t7WYfwKZktVGNXdg1m08uEx1anO0oUPUkoQRsNm4QniL3hmfw0ijg00YA6TrxCRkPVOQ==", - "cpu": [ - "arm" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@vscode/vsce-sign-linux-arm64": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-linux-arm64/-/vsce-sign-linux-arm64-2.0.2.tgz", - "integrity": "sha512-Ybeu7cA6+/koxszsORXX0OJk9N0GgfHq70Wqi4vv2iJCZvBrOWwcIrxKjvFtwyDgdeQzgPheH5nhLVl5eQy7WA==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@vscode/vsce-sign-linux-x64": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-linux-x64/-/vsce-sign-linux-x64-2.0.2.tgz", - "integrity": "sha512-NsPPFVtLaTlVJKOiTnO8Cl78LZNWy0Q8iAg+LlBiCDEgC12Gt4WXOSs2pmcIjDYzj2kY4NwdeN1mBTaujYZaPg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "linux" - ] - }, - "node_modules/@vscode/vsce-sign-win32-arm64": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-win32-arm64/-/vsce-sign-win32-arm64-2.0.2.tgz", - "integrity": "sha512-wPs848ymZ3Ny+Y1Qlyi7mcT6VSigG89FWQnp2qRYCyMhdJxOpA4lDwxzlpL8fG6xC8GjQjGDkwbkWUcCobvksQ==", - "cpu": [ - "arm64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ] - }, - "node_modules/@vscode/vsce-sign-win32-x64": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@vscode/vsce-sign-win32-x64/-/vsce-sign-win32-x64-2.0.2.tgz", - "integrity": "sha512-pAiRN6qSAhDM5SVOIxgx+2xnoVUePHbRNC7OD2aOR3WltTKxxF25OfpK8h8UQ7A0BuRkSgREbB59DBlFk4iAeg==", - "cpu": [ - "x64" - ], - "dev": true, - "optional": true, - "os": [ - "win32" - ] - }, "node_modules/@vscode/vsce/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", diff --git a/package.json b/package.json index 32d44d38..ed82f6b1 100644 --- a/package.json +++ b/package.json @@ -629,6 +629,7 @@ "@azure/arm-compute": "^22.2.0", "@azure/arm-containerregistry": "^10.1.0", "@azure/arm-containerservice": "21.2.0-beta.1", + "@azure/arm-containerservicefleet": "^1.1.0", "@azure/arm-features": "^3.1.0", "@azure/arm-monitor": "^7.0.0", "@azure/arm-msi": "^2.1.0", diff --git a/src/commands/aksFleet/aksFleetManager.ts b/src/commands/aksFleet/aksFleetManager.ts new file mode 100644 index 00000000..4558f6b2 --- /dev/null +++ b/src/commands/aksFleet/aksFleetManager.ts @@ -0,0 +1,63 @@ +import { IActionContext } from "@microsoft/vscode-azext-utils"; +import * as vscode from "vscode"; +import * as k8s from "vscode-kubernetes-tools-api"; +import { getCredential, getReadySessionProvider } from "../../auth/azureAuth"; +import { getAksClusterSubscriptionNode } from "../utils/clusters"; +import { failed } from "../utils/errorable"; +import { getResourceGroups } from "../utils/resourceGroups"; +import { createFleet } from "../../panels/CreateFleetPanel"; +import { ContainerServiceFleetClient } from "@azure/arm-containerservicefleet"; + +export default async function aksCreateFleet(_context: IActionContext, target: unknown): Promise { + const cloudExplorer = await k8s.extension.cloudExplorer.v1; + const sessionProvider = await getReadySessionProvider(); + + if (failed(sessionProvider)) { + vscode.window.showErrorMessage(sessionProvider.error); + return; + } + + const subscriptionNode = getAksClusterSubscriptionNode(target, cloudExplorer); + + if (failed(subscriptionNode)) { + vscode.window.showErrorMessage(subscriptionNode.error); + return; + } + + const subscriptionId = subscriptionNode.result?.subscriptionId; + const subscriptionName = subscriptionNode.result?.name; + const resourceGroup = await getResourceGroups(sessionProvider.result, subscriptionId); + + if (failed(resourceGroup)) { + vscode.window.showErrorMessage(resourceGroup.error); + return; + } + + if (!subscriptionId || !subscriptionName) { + vscode.window.showErrorMessage("Subscription ID or Name is undefined."); + return; + } + + // Temporary code for incremental check-in. + // TODO: Replace hardcoded values with dynamic parameters or configuration settings. + + // Initialize the ContainerServiceFleetClient with session credentials and subscription ID. + // Hardcoded 'subscriptionId' should be parameterized in future updates. + const client = new ContainerServiceFleetClient( + getCredential(sessionProvider.result), // Retrieve credentials from session provider. + subscriptionId, // TODO: Ensure subscriptionId is dynamically passed or configured. + ); + + // Create a fleet using hardcoded parameters. + // TODO: Replace hardcoded 'Fleet-Resource-Name', 'Fleet-Name', and 'Australia East' with configurable inputs. + createFleet( + client, + "Fleet-Resource-Name", // Fleet resource group name (hardcoded). + "Fleet-Name", // Fleet name (hardcoded). + { location: "Australia East" }, // Location (hardcoded). + ); + + // NOTE: This temporary implementation assumes static context for testing purposes. + // Ensure these hardcoded values are replaced with appropriate dynamic configurations + // before finalizing this code for production level work which will be user focused. +} diff --git a/src/panels/CreateFleetPanel.ts b/src/panels/CreateFleetPanel.ts new file mode 100644 index 00000000..7b9a0690 --- /dev/null +++ b/src/panels/CreateFleetPanel.ts @@ -0,0 +1,15 @@ +import { ContainerServiceFleetClient, Fleet } from "@azure/arm-containerservicefleet"; + +export async function createFleet( + client: ContainerServiceFleetClient, + resourceGroupName: string, + name: string, + resource: Fleet, +) { + try { + const result = await client.fleets.beginCreateOrUpdateAndWait(resourceGroupName, name, resource); + return { succeeded: true, result: result.name! }; + } catch (error) { + return { succeeded: false, error: (error as Error).message }; + } +}