Skip to content

Commit

Permalink
initial pull request
Browse files Browse the repository at this point in the history
adding library dependencies

hide right-click button

removing irrelevant code and adding comments

fixing typo and adding signature

Signed-off-by: Tatsat Mishra <[email protected]>

adding library dependencies

hide right-click button

removing irrelevant code and adding comments
  • Loading branch information
JunyuQian committed Jan 9, 2025
1 parent cab4c06 commit b2312da
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 104 deletions.
123 changes: 19 additions & 104 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
63 changes: 63 additions & 0 deletions src/commands/aksFleet/aksFleetManager.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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.
}
15 changes: 15 additions & 0 deletions src/panels/CreateFleetPanel.ts
Original file line number Diff line number Diff line change
@@ -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 };
}
}

0 comments on commit b2312da

Please sign in to comment.