Skip to content

Commit

Permalink
Add draft context menu commands and deprecate starter workflows (#696)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbom authored May 28, 2024
1 parent db6c4e8 commit c583894
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 21 deletions.
39 changes: 34 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
},
{
"command": "aks.configureStarterWorkflow",
"title": "Starter Workflow"
"title": "Starter Workflow (deprecated)"
},
{
"command": "aks.aksCRUDDiagnostics",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -428,6 +443,16 @@
"group": "navigation"
}
],
"aks.draftSubMenu": [
{
"command": "aks.draftDeployment",
"group": "navigation"
},
{
"command": "aks.draftWorkflow",
"group": "navigation"
}
],
"aks.ghWorkflowSubMenu": [
{
"command": "aks.configureHelmStarterWorkflow",
Expand Down Expand Up @@ -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",
Expand Down
96 changes: 82 additions & 14 deletions src/commands/draft/draftCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -26,26 +26,29 @@ 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<void> {
export async function draftDockerfile(_context: IActionContext, target: unknown): Promise<void> {
const params = getDraftDockerfileParams(target);
const commonDependencies = await getCommonDraftDependencies(params?.workspaceFolder);
if (commonDependencies === null) {
return;
}

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<void> {
export async function draftDeployment(_context: IActionContext, target: unknown): Promise<void> {
const cloudExplorer = await k8s.extension.cloudExplorer.v1;
const params = getDraftDeploymentParams(cloudExplorer, target);
const commonDependencies = await getCommonDraftDependencies(params?.workspaceFolder);
if (commonDependencies === null) {
return;
Expand Down Expand Up @@ -84,10 +87,9 @@ export async function draftDeployment(
panel.show(dataProvider);
}

export async function draftWorkflow(
_context: IActionContext,
params?: DraftCommandParamsType<"aks.draftWorkflow">,
): Promise<void> {
export async function draftWorkflow(_context: IActionContext, target: unknown): Promise<void> {
const cloudExplorer = await k8s.extension.cloudExplorer.v1;
const params = getDraftWorkflowParams(cloudExplorer, target);
const commonDependencies = await getCommonDraftDependencies(params?.workspaceFolder);
if (commonDependencies === null) {
return;
Expand Down Expand Up @@ -247,3 +249,69 @@ async function getRepo(octokit: Octokit, remote: Remote): Promise<GitHubRepo | n
defaultBranch: response.data.default_branch,
};
}

function getDraftDockerfileParams(params: unknown): DraftCommandParamsType<"aks.draftDockerfile"> {
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<k8s.CloudExplorerV1>,
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<k8s.CloudExplorerV1>,
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">;
}
1 change: 1 addition & 0 deletions src/commands/draft/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { InitialSelection as WorkflowInitialSelection } from "../../webview-cont
export type DraftCommandParamsTypes = {
"aks.draftDockerfile": {
workspaceFolder?: WorkspaceFolder;
initialLocation?: string;
};
"aks.draftDeployment": {
workspaceFolder?: WorkspaceFolder;
Expand Down
5 changes: 3 additions & 2 deletions src/panels/draft/DraftDockerfilePanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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),
};
}

Expand Down

0 comments on commit c583894

Please sign in to comment.