Skip to content

Commit

Permalink
Rename commands
Browse files Browse the repository at this point in the history
Signed-off-by: Alvaro Saurin <[email protected]>
  • Loading branch information
inercia committed Dec 6, 2020
1 parent e95b5a8 commit 7af048c
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 34 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand Down
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
25 changes: 14 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand All @@ -47,37 +47,40 @@
],
"commands": [
{
"command": "k3d.createCluster",
"command": "extension.vsKubernetesK3DCreate",
"category": "k3d",
"title": "Create Cluster"
},
{
"command": "k3d.deleteCluster",
"command": "extension.vsKubernetesK3DDelete",
"category": "k3d",
"title": "Delete Cluster"
}
],
"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"
Expand Down
9 changes: 7 additions & 2 deletions src/commands/create-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -84,9 +88,10 @@ async function displayClusterCreationResult(result: Errorable<null>): Promise<vo
////////////////////////////////////////////////////////////////////////////////////////////////////////////

async function promptClusterSettings(): Promise<Cancellable<ClusterCreateSettings>> {
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;
Expand Down
4 changes: 4 additions & 0 deletions src/commands/delete-cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ async function deleteClusterByName(clusterName: string): Promise<void> {

// 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<null>, clusterName: string): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/k3d/k3d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ export function createClusterSettingsFromForm(s: any): ClusterCreateSettings {
};
}

export const createClusterHTMLHeader = "<h1>Create k3d cluster</h1>";

// createClusterHTML is the form that is shown when creating a new cluster
export const createClusterHTML = `
<h1>Create k3d cluster</h1>
<p/>
Create a new k3s cluster with containerized nodes (k3s in docker).
Every cluster will consist of one or more containers:
<ul>
Expand Down
20 changes: 9 additions & 11 deletions src/providers/cluster-provider.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -68,7 +69,8 @@ function createCluster(previousData: any): k8s.ClusterProviderV1.Observable<stri
argsStr += " --wait --update-default-kubeconfig";

const exe = k3dExe();
shelljs.env["KUBECONFIG"] = getKubeconfigPath();
const kubeconfig = getKubeconfigPath();
shelljs.env["KUBECONFIG"] = kubeconfig;
const command = `${exe} cluster create ${settings.name} ${argsStr}`;

const childProcess = shelljs.exec(command, { async: true }) as ChildProcess;
Expand Down Expand Up @@ -99,21 +101,17 @@ function createCluster(previousData: any): k8s.ClusterProviderV1.Observable<stri
childProcess.on('exit', (code: number) => {
if (code === 0) {
title = 'Cluster created';
resultPara = `<p style='font-weight: bold; color: lightgreen'>Your local cluster has been created BUT HAS NOT BEEN set as active in your kubeconfig</p>`;
resultPara = `<p style='font-weight: bold; color: lightgreen'>Your local cluster has been created and has been merged in your kubeconfig ${kubeconfig}</p>`;
observer.onNext(html());

shelljs.exec(`${exe} kubeconfig get ${settings.name}`, { async: true }, (code, pStdout, _pStderr) => {
if (code === 0) {
const kcpath = pStdout.trim();
resultPara = `<p style='font-weight: bold; color: lightgreen'>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.</p>`;
observer.onNext(html());
}
});
} else {
title = 'Cluster creation failed';
resultPara = `<p style='font-weight: bold; color: red'>Your local cluster was not created. See tool output above for why.</p>`;
observer.onNext(html());
}

// refresh the views
vscode.commands.executeCommand("extension.vsKubernetesRefreshExplorer");
vscode.commands.executeCommand("extension.vsKubernetesRefreshCloudExplorer");
});
}
};
Expand Down
1 change: 1 addition & 0 deletions src/utils/kubeconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 7af048c

Please sign in to comment.