Skip to content

Commit

Permalink
Simplify the KUBECONFIG management: just use the same as the k8s exte…
Browse files Browse the repository at this point in the history
…nsion

Signed-off-by: Alvaro Saurin <[email protected]>
  • Loading branch information
inercia committed Jan 16, 2021
1 parent 308ffc5 commit 2bf01a7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 109 deletions.
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@
"default": "always",
"description": "Update the kubeconfig after creating or deleting a cluster."
},
"k3d.kubeconfig": {
"type": "string",
"default": "",
"description": "Apply changes in this kubeconfig when merging configuration after creating new clusters."
},
"k3d.replaceContext": {
"type": "string",
"enum": [
Expand Down
4 changes: 2 additions & 2 deletions src/commands/createCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as form from './createClusterForm';

import * as k3d from '../k3d/k3d';

import * as config from '../utils/config';
import * as kubectl from '../utils/kubectl';
import { logChannel } from '../utils/log';
import { shell, ProcessTrackingEvent } from '../utils/shell';
import { succeeded, Errorable } from '../utils/errorable';
Expand Down Expand Up @@ -52,7 +52,7 @@ export async function createClusterInteractive(
clusterSettings: settings.ClusterCreateSettings,
switchContext: boolean = true): Promise<void> {

const kubeconfig = await config.getK3DKubeconfigPath();
const kubeconfig = await kubectl.getKubeconfigPath();

// createClusterProgressOf is invoked for processing each line of output from `k3d cluster create`
function createClusterProgressOf(e: ProcessTrackingEvent): ProgressStep<Errorable<null>> {
Expand Down
24 changes: 3 additions & 21 deletions src/k3d/k3d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import * as vscode from 'vscode';

import { Observable, throwError } from 'rxjs';

import { K3dClusterInfo, K3dRegistryInfo } from "./k3d.objectmodel";
import { ClusterCreateSettings, createClusterArgsFromSettings } from '../commands/createClusterSettings';
import { getOrInstallK3D, EnsureMode } from '../installer/installer';

import * as config from '../utils/config';
import { Errorable, failed } from '../utils/errorable';
import * as shell from '../utils/shell';
import { logChannel } from '../utils/log';
Expand All @@ -29,18 +26,10 @@ async function invokeK3DCommandObj<T>(
}
const exe = k3dExe.result;

let opts = shell.defExecOpts();
const kubeconfig = await kubectl.getKubeconfigPath();

const kubeconfig = await config.getK3DKubeconfigPath();
if (kubeconfig.length > 0) {
if (kubeconfig.includes(":")) {
const warningMsg = `KUBECONFIG includes multiple files: k3d will not be able to update it.`;
logChannel.appendLine(`[WARNING] ${warningMsg}`);
vscode.window.showInformationMessage(`WARNING: ${warningMsg}.`);
}

opts.env["KUBECONFIG"] = kubeconfig;
}
let opts = shell.defExecOpts();
opts.env["KUBECONFIG"] = kubeconfig;

const cmd = `${exe} ${command} ${args}`;
logChannel.appendLine(`$ ${cmd}`);
Expand Down Expand Up @@ -68,14 +57,7 @@ function invokeK3DCommandTracking(
const exe = k3dExe.result;

let opts = shell.defExecOpts();

if (kubeconfig) {
if (kubeconfig.includes(":")) {
const warningMsg = `KUBECONFIG includes multiple files: k3d will not be able to update it.`;
logChannel.appendLine(`[WARNING] ${warningMsg}`);
vscode.window.showInformationMessage(`WARNING: ${warningMsg}.`);
}

opts.env["KUBECONFIG"] = kubeconfig;
}

Expand Down
4 changes: 2 additions & 2 deletions src/providers/clusterProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as settings from '../commands/createClusterSettings';

import * as k3d from '../k3d/k3d';

import * as config from '../utils/config';
import * as kubectl from '../utils/kubectl';
import { Errorable } from '../utils/errorable';
import { shell, ProcessTrackingEvent } from '../utils/shell';
import { cantHappen } from '../utils/never';
Expand Down Expand Up @@ -122,7 +122,7 @@ async function getPageCreatingCluster(previousData: any): Promise<k8s.ClusterPro

const createSettings = form.createClusterSettingsFromForm(previousData);

const kubeconfig = await config.getK3DKubeconfigPath();
const kubeconfig = await kubectl.getKubeconfigPath();

const progressSteps: Observable<ProgressStep<Errorable<null>>> = k3d.createCluster(shell,
createSettings, kubeconfig).pipe(
Expand Down
27 changes: 0 additions & 27 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import * as vscode from 'vscode';

import * as kubectl from './kubectl';
import { Platform, platform } from "./shell";

// the K3D config key
Expand All @@ -11,10 +10,6 @@ export const VS_KUBE_K3D_CFG_KEY = "k3d";
// the Kubernetes tools config key
export const VS_KUBE_CFG_KEY = "vs-kubernetes";

// setting: force a specific KUBECONFIG where the kubeconfig will be merged
export const VS_KUBE_K3D_FORCE_KUBECONFIG_CFG_KEY =
`${VS_KUBE_K3D_CFG_KEY}.kubeconfig`;

// setting: merge of the new kubeconfig in the default kubeconfig
export const VS_KUBE_K3D_UPDATE_KUBECONFIG_CFG_KEY =
`${VS_KUBE_K3D_CFG_KEY}.updateKubeconfig`;
Expand Down Expand Up @@ -47,28 +42,6 @@ export const VS_KUBE_K3D_DOCKERHOST_CFG_KEY =

const USE_WSL_KEY = "use-wsl";

export function getK3DConfigForcedKubeconfig(): string | undefined {
return vscode.workspace.getConfiguration()[VS_KUBE_K3D_FORCE_KUBECONFIG_CFG_KEY];
}

export async function getK3DKubeconfigPath(kubeconfig?: string): Promise<string> {
if (kubeconfig) {
return kubeconfig;
}

const forcedKubeconfig = getK3DConfigForcedKubeconfig();
if (forcedKubeconfig) {
return forcedKubeconfig;
}

const systemKubeconfig = await kubectl.getKubeconfigPath();
if (systemKubeconfig.length > 0) {
return kubectl.getKubeconfigPath();
}

return "";
}

export enum UpdateKubeconfig {
OnCreate = 1,
OnDelete,
Expand Down
52 changes: 0 additions & 52 deletions src/utils/kubeconfig.ts

This file was deleted.

0 comments on commit 2bf01a7

Please sign in to comment.