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

Adding API calls to create a Fleet #1160

Merged
merged 1 commit into from
Jan 9, 2025
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
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 };
}
}
Loading