From 7af048c24e1204eaf4a8fe8e7f31846afd2b7df1 Mon Sep 17 00:00:00 2001 From: Alvaro Saurin Date: Sat, 5 Dec 2020 19:08:39 +0100 Subject: [PATCH] Rename commands Signed-off-by: Alvaro Saurin --- .github/workflows/publish.yml | 6 ------ .vscode/extensions.json | 1 + package.json | 25 ++++++++++++++----------- src/commands/create-cluster.ts | 9 +++++++-- src/commands/delete-cluster.ts | 4 ++++ src/extension.ts | 4 ++-- src/k3d/k3d.ts | 4 ++-- src/providers/cluster-provider.ts | 20 +++++++++----------- src/utils/kubeconfig.ts | 1 + 9 files changed, 40 insertions(+), 34 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index caa70f9..7bb6787 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,12 +13,6 @@ jobs: - name: Checkout code uses: actions/checkout@v2 - - name: Compile - run: npm run compile - - - name: test - run: npm run test - - name: Set release version run: npm version ${{ github.ref }} diff --git a/.vscode/extensions.json b/.vscode/extensions.json index e14877a..e131325 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,5 +2,6 @@ // See http://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [ + "ms-kubernetes-tools.vscode-kubernetes-tools" ] } \ No newline at end of file diff --git a/package.json b/package.json index a131662..da8bb6f 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vscode-k3d", "displayName": "Kubernetes k3d", "description": "Work with the k3d local Kubernetes provider in Visual Studio Code", - "version": "0.0.2", + "version": "0.0.3", "preview": true, "publisher": "ms-kubernetes-tools", "engines": { @@ -22,8 +22,8 @@ "onCommand:extension.vsKubernetesConfigureFromCluster", "onCommand:extension.vsKubernetesCreateCluster", "onView:kubernetes.cloudExplorer", - "onCommand:k3d.createCluster", - "onCommand:k3d.deleteCluster" + "onCommand:extension.vsKubernetesK3DCreate", + "onCommand:extension.vsKubernetesK3DDelete" ], "main": "./dist/extension", "contributes": { @@ -47,12 +47,12 @@ ], "commands": [ { - "command": "k3d.createCluster", + "command": "extension.vsKubernetesK3DCreate", "category": "k3d", "title": "Create Cluster" }, { - "command": "k3d.deleteCluster", + "command": "extension.vsKubernetesK3DDelete", "category": "k3d", "title": "Delete Cluster" } @@ -60,24 +60,27 @@ "menus": { "view/item/context": [ { - "command": "k3d.createCluster", + "command": "extension.vsKubernetesK3DCreate", "when": "viewItem == kubernetes.cloudExplorer.cloud.k3d" }, { - "command": "k3d.deleteCluster", + "command": "extension.vsKubernetesK3DDelete", "when": "viewItem =~ /k3d\\.cluster/" } ] } }, "scripts": { - "vscode:prepublish": "webpack --mode production", "compile": "webpack --mode none", "watch": "webpack --mode none --watch", - "test-compile": "tsc -p ./", "postinstall": "node ./node_modules/vscode/bin/install", - "dist-tools": "npm install -g vsce", - "test": "npm run compile && node ./node_modules/vscode/bin/test" + + "test": "npm run compile && node ./node_modules/vscode/bin/test", + "test-compile": "tsc -p ./", + + "vscode:prepublish": "webpack --mode production", + "dist": "vsce package", + "dist-tools": "npm install -g vsce" }, "extensionDependencies": [ "ms-kubernetes-tools.vscode-kubernetes-tools" diff --git a/src/commands/create-cluster.ts b/src/commands/create-cluster.ts index 9b18660..1851a28 100644 --- a/src/commands/create-cluster.ts +++ b/src/commands/create-cluster.ts @@ -36,6 +36,10 @@ async function createClusterInteractive(settings: ClusterCreateSettings): Promis ); await displayClusterCreationUI(progressSteps); + + // refresh the views + vscode.commands.executeCommand("extension.vsKubernetesRefreshExplorer"); + vscode.commands.executeCommand("extension.vsKubernetesRefreshCloudExplorer"); } // createClusterProgressOf is invoked for processing each line of output from `k3d cluster create` @@ -84,9 +88,10 @@ async function displayClusterCreationResult(result: Errorable): Promise> { - const formResult = await showHTMLForm("k3d.createCluster", + const formResult = await showHTMLForm( + "extension.vsKubernetesK3DCreate", "Create k3d cluster", - k3d.createClusterHTML, + k3d.createClusterHTMLHeader + k3d.createClusterHTML, "Create Cluster"); if (formResult.cancelled) { return formResult; diff --git a/src/commands/delete-cluster.ts b/src/commands/delete-cluster.ts index a75bb50..d822eef 100644 --- a/src/commands/delete-cluster.ts +++ b/src/commands/delete-cluster.ts @@ -45,6 +45,10 @@ async function deleteClusterByName(clusterName: string): Promise { // TODO: remove from kubeconfig? await displayClusterDeletionResult(result, clusterName); + + // refresh the views + vscode.commands.executeCommand("extension.vsKubernetesRefreshExplorer"); + vscode.commands.executeCommand("extension.vsKubernetesRefreshCloudExplorer"); } async function displayClusterDeletionResult(result: Errorable, clusterName: string): Promise { diff --git a/src/extension.ts b/src/extension.ts index f4989fc..10967eb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -23,8 +23,8 @@ export async function activate(context: vscode.ExtensionContext) { } const disposables = [ - vscode.commands.registerCommand("k3d.createCluster", onCreateCluster), - vscode.commands.registerCommand("k3d.deleteCluster", onDeleteCluster), + vscode.commands.registerCommand("extension.vsKubernetesK3DCreate", onCreateCluster), + vscode.commands.registerCommand("extension.vsKubernetesK3DDelete", onDeleteCluster), ]; context.subscriptions.push(...disposables); diff --git a/src/k3d/k3d.ts b/src/k3d/k3d.ts index f553e67..9acfa5d 100644 --- a/src/k3d/k3d.ts +++ b/src/k3d/k3d.ts @@ -74,10 +74,10 @@ export function createClusterSettingsFromForm(s: any): ClusterCreateSettings { }; } +export const createClusterHTMLHeader = "

Create k3d cluster

"; + // createClusterHTML is the form that is shown when creating a new cluster export const createClusterHTML = ` -

Create k3d cluster

-

Create a new k3s cluster with containerized nodes (k3s in docker). Every cluster will consist of one or more containers:

    diff --git a/src/providers/cluster-provider.ts b/src/providers/cluster-provider.ts index edb06f9..f773502 100644 --- a/src/providers/cluster-provider.ts +++ b/src/providers/cluster-provider.ts @@ -1,6 +1,7 @@ // TODO: this whole file seems to have many things in common with k3d/k3d.ts +import * as vscode from 'vscode'; import * as k8s from 'vscode-kubernetes-tools-api'; import * as shelljs from 'shelljs'; import { ChildProcess } from 'child_process'; @@ -40,7 +41,7 @@ function getPage(sendingStep: string, previousData: any): k8s.ClusterProviderV1. function collectSettings(previousData: any): string { const html = formPage( PAGE_SETTINGS, - "Create k3d Cluster", + "Create k3d cluster", k3d.createClusterHTML, "Create", previousData); @@ -68,7 +69,8 @@ function createCluster(previousData: any): k8s.ClusterProviderV1.Observable { if (code === 0) { title = 'Cluster created'; - resultPara = `

    Your local cluster has been created BUT HAS NOT BEEN set as active in your kubeconfig

    `; + resultPara = `

    Your local cluster has been created and has been merged in your kubeconfig ${kubeconfig}

    `; observer.onNext(html()); - - shelljs.exec(`${exe} kubeconfig get ${settings.name}`, { async: true }, (code, pStdout, _pStderr) => { - if (code === 0) { - const kcpath = pStdout.trim(); - resultPara = `

    Your local cluster has been created and its kubeconfig is at ${kcpath}. To work with your cluster, switch to this kubeconfig, or copy settings from this file to your main kubeconfig.

    `; - observer.onNext(html()); - } - }); } else { title = 'Cluster creation failed'; resultPara = `

    Your local cluster was not created. See tool output above for why.

    `; observer.onNext(html()); } + + // refresh the views + vscode.commands.executeCommand("extension.vsKubernetesRefreshExplorer"); + vscode.commands.executeCommand("extension.vsKubernetesRefreshCloudExplorer"); }); } }; diff --git a/src/utils/kubeconfig.ts b/src/utils/kubeconfig.ts index 527af31..60849ed 100644 --- a/src/utils/kubeconfig.ts +++ b/src/utils/kubeconfig.ts @@ -23,6 +23,7 @@ export function getActiveKubeconfig(): string { return vscode.workspace.getConfiguration(VS_KUBE_EXTENSION_CONFIG_KEY)[VS_KUBE_KUBECONFIG_PATH_KEY]; } +// TODO: I think we could replace this by https://github.com/Azure/vscode-kubernetes-tools-api/blob/master/ts/configuration/v1.ts export function getKubeconfigPath(): string { // If the user specified a kubeconfig path -WSL or not-, let's use it. let kubeconfigPath: string | undefined = getActiveKubeconfig();