diff --git a/package.json b/package.json index 90db1319e..df4fb0fb2 100644 --- a/package.json +++ b/package.json @@ -202,7 +202,7 @@ }, { "command": "aks.configureStarterWorkflow", - "title": "Starter Workflow" + "title": "Starter Workflow (deprecated)" }, { "command": "aks.aksCRUDDiagnostics", @@ -230,15 +230,15 @@ }, { "command": "aks.configureHelmStarterWorkflow", - "title": "Helm Workflow" + "title": "Helm Workflow (deprecated)" }, { "command": "aks.configureKomposeStarterWorkflow", - "title": "Kompose Workflow" + "title": "Kompose Workflow (deprecated)" }, { "command": "aks.configureKustomizeStarterWorkflow", - "title": "Kustomize Workflow" + "title": "Kustomize Workflow (deprecated)" }, { "command": "aks.draftDockerfile", @@ -323,6 +323,16 @@ "when": "workspaceFolderCount >= 1" } ], + "explorer/context": [ + { + "command": "aks.draftDockerfile", + "when": "explorerResourceIsFolder" + }, + { + "command": "aks.draftDeployment", + "when": "explorerResourceIsFolder" + } + ], "view/item/context": [ { "command": "aks.selectSubscriptions", @@ -363,6 +373,11 @@ "command": "aks.installAzureServiceOperator", "when": "view == kubernetes.cloudExplorer && viewItem =~ /aks\\.cluster/i || view == extension.vsKubernetesExplorer && viewItem =~ /vsKubernetes\\.\\w*cluster$/i" }, + { + "submenu": "aks.draftSubMenu", + "when": "view == kubernetes.cloudExplorer && viewItem =~ /aks\\.cluster/i && workspaceFolderCount >= 1", + "group": "9@1" + }, { "submenu": "aks.ghWorkflowSubMenu", "when": "view == kubernetes.cloudExplorer && viewItem =~ /aks\\.cluster/i", @@ -428,6 +443,16 @@ "group": "navigation" } ], + "aks.draftSubMenu": [ + { + "command": "aks.draftDeployment", + "group": "navigation" + }, + { + "command": "aks.draftWorkflow", + "group": "navigation" + } + ], "aks.ghWorkflowSubMenu": [ { "command": "aks.configureHelmStarterWorkflow", @@ -480,9 +505,13 @@ "id": "aks.detectorsSubMenu", "label": "Run AKS Diagnostics" }, + { + "id": "aks.draftSubMenu", + "label": "Draft" + }, { "id": "aks.ghWorkflowSubMenu", - "label": "Create GitHub Workflow" + "label": "Create GitHub Workflow (deprecated)" }, { "id": "aks.managedClusterOperationSubMenu", diff --git a/src/commands/draft/draftCommands.ts b/src/commands/draft/draftCommands.ts index 4f2fa9ea8..5423d3d74 100644 --- a/src/commands/draft/draftCommands.ts +++ b/src/commands/draft/draftCommands.ts @@ -11,7 +11,7 @@ import { } from "vscode"; import { DraftDockerfileDataProvider, DraftDockerfilePanel } from "../../panels/draft/DraftDockerfilePanel"; import { getExtension } from "../utils/host"; -import { Errorable, failed, getErrorMessage } from "../utils/errorable"; +import { Errorable, failed, getErrorMessage, succeeded } from "../utils/errorable"; import { getDraftBinaryPath } from "../utils/helper/draftBinaryDownload"; import { DraftDeploymentDataProvider, DraftDeploymentPanel } from "../../panels/draft/DraftDeploymentPanel"; import * as k8s from "vscode-kubernetes-tools-api"; @@ -26,11 +26,11 @@ import { basename, extname, join } from "path"; import { getReadySessionProvider } from "../../auth/azureAuth"; import { IActionContext } from "@microsoft/vscode-azext-utils"; import { DraftCommandParamsType } from "./types"; +import { getAksClusterTreeNode } from "../utils/clusters"; +import path from "path"; -export async function draftDockerfile( - _context: IActionContext, - params?: DraftCommandParamsType<"aks.draftDockerfile">, -): Promise { +export async function draftDockerfile(_context: IActionContext, target: unknown): Promise { + const params = getDraftDockerfileParams(target); const commonDependencies = await getCommonDraftDependencies(params?.workspaceFolder); if (commonDependencies === null) { return; @@ -38,14 +38,17 @@ export async function draftDockerfile( const { workspaceFolder, extension, draftBinaryPath } = commonDependencies; const panel = new DraftDockerfilePanel(extension.extensionUri); - const dataProvider = new DraftDockerfileDataProvider(workspaceFolder, draftBinaryPath); + const dataProvider = new DraftDockerfileDataProvider( + workspaceFolder, + draftBinaryPath, + params?.initialLocation || "", + ); panel.show(dataProvider); } -export async function draftDeployment( - _context: IActionContext, - params?: DraftCommandParamsType<"aks.draftDeployment">, -): Promise { +export async function draftDeployment(_context: IActionContext, target: unknown): Promise { + const cloudExplorer = await k8s.extension.cloudExplorer.v1; + const params = getDraftDeploymentParams(cloudExplorer, target); const commonDependencies = await getCommonDraftDependencies(params?.workspaceFolder); if (commonDependencies === null) { return; @@ -84,10 +87,9 @@ export async function draftDeployment( panel.show(dataProvider); } -export async function draftWorkflow( - _context: IActionContext, - params?: DraftCommandParamsType<"aks.draftWorkflow">, -): Promise { +export async function draftWorkflow(_context: IActionContext, target: unknown): Promise { + const cloudExplorer = await k8s.extension.cloudExplorer.v1; + const params = getDraftWorkflowParams(cloudExplorer, target); const commonDependencies = await getCommonDraftDependencies(params?.workspaceFolder); if (commonDependencies === null) { return; @@ -247,3 +249,69 @@ async function getRepo(octokit: Octokit, remote: Remote): Promise { + if (params instanceof Uri) { + const workspaceFolder = workspace.getWorkspaceFolder(params); + if (!workspaceFolder) { + return {}; + } + + const initialLocation = path.relative(workspaceFolder.uri.fsPath, params.fsPath); + return { + workspaceFolder: workspace.getWorkspaceFolder(params), + initialLocation, + }; + } + + return params as DraftCommandParamsType<"aks.draftDockerfile">; +} + +function getDraftDeploymentParams( + cloudExplorer: k8s.API, + params: unknown, +): DraftCommandParamsType<"aks.draftDeployment"> { + if (params instanceof Uri) { + const workspaceFolder = workspace.getWorkspaceFolder(params); + if (!workspaceFolder) { + return {}; + } + + const initialLocation = path.relative(workspaceFolder.uri.fsPath, params.fsPath); + return { + workspaceFolder, + initialLocation, + }; + } + + const clusterNode = getAksClusterTreeNode(params, cloudExplorer); + if (succeeded(clusterNode)) { + return { + initialSelection: { + subscriptionId: clusterNode.result.subscriptionId, + clusterResourceGroup: clusterNode.result.resourceGroupName, + clusterName: clusterNode.result.name, + }, + }; + } + + return params as DraftCommandParamsType<"aks.draftDeployment">; +} + +function getDraftWorkflowParams( + cloudExplorer: k8s.API, + params: unknown, +): DraftCommandParamsType<"aks.draftWorkflow"> { + const clusterNode = getAksClusterTreeNode(params, cloudExplorer); + if (succeeded(clusterNode)) { + return { + initialSelection: { + subscriptionId: clusterNode.result.subscriptionId, + clusterResourceGroup: clusterNode.result.resourceGroupName, + clusterName: clusterNode.result.name, + }, + }; + } + + return params as DraftCommandParamsType<"aks.draftWorkflow">; +} diff --git a/src/commands/draft/types.ts b/src/commands/draft/types.ts index ece080e92..4c1e54787 100644 --- a/src/commands/draft/types.ts +++ b/src/commands/draft/types.ts @@ -5,6 +5,7 @@ import { InitialSelection as WorkflowInitialSelection } from "../../webview-cont export type DraftCommandParamsTypes = { "aks.draftDockerfile": { workspaceFolder?: WorkspaceFolder; + initialLocation?: string; }; "aks.draftDeployment": { workspaceFolder?: WorkspaceFolder; diff --git a/src/panels/draft/DraftDockerfilePanel.ts b/src/panels/draft/DraftDockerfilePanel.ts index 8ea765170..b92ca9ae8 100644 --- a/src/panels/draft/DraftDockerfilePanel.ts +++ b/src/panels/draft/DraftDockerfilePanel.ts @@ -31,6 +31,7 @@ export class DraftDockerfileDataProvider implements PanelDataProvider<"draftDock constructor( readonly workspaceFolder: WorkspaceFolder, readonly draftBinaryPath: string, + readonly initialLocation: string, ) { this.draftDirectory = path.dirname(draftBinaryPath); } @@ -46,9 +47,9 @@ export class DraftDockerfileDataProvider implements PanelDataProvider<"draftDock fullPath: this.workspaceFolder.uri.fsPath, pathSeparator: path.sep, }, - location: "", + location: this.initialLocation, supportedLanguages: getSupportedLanguages(), - existingFiles: getExistingFiles(this.workspaceFolder, ""), + existingFiles: getExistingFiles(this.workspaceFolder, this.initialLocation), }; }