From 93e665267b061efecc5d61702e6ef63b605747ed Mon Sep 17 00:00:00 2001 From: Ionut Achim Date: Wed, 21 Feb 2024 17:05:36 +0200 Subject: [PATCH] fix: stringify the `context` and `kubeconfig` cli arguments prevents issues related to empty spaces, line breaks, existing quotes etc. --- electron/kubernetes/ProxyInstance.ts | 4 ++-- src/redux/cluster/service/kube-control.ts | 4 ++-- src/redux/thunks/applyResource.ts | 2 +- src/shared/utils/commands/kubectl.ts | 2 +- src/utils/cluster.ts | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/electron/kubernetes/ProxyInstance.ts b/electron/kubernetes/ProxyInstance.ts index f15b8a3617..9681ab28a4 100644 --- a/electron/kubernetes/ProxyInstance.ts +++ b/electron/kubernetes/ProxyInstance.ts @@ -51,8 +51,8 @@ export class ProxyInstance { throw new Error('MONOKLE_PROXY_EMPTY_CONTEXT'); } - const globalOptions = [`--context=${this.context}`]; - if (this.kubeconfig) globalOptions.push(`--kubeconfig=${this.kubeconfig}`); + const globalOptions = [`--context=${JSON.stringify(this.context)}`]; + if (this.kubeconfig) globalOptions.push(`--kubeconfig=${JSON.stringify(this.kubeconfig)}`); if (this.verbosity) globalOptions.push(`-v=${this.verbosity}`); const proxyOptions = [`--port=${this.port}`]; diff --git a/src/redux/cluster/service/kube-control.ts b/src/redux/cluster/service/kube-control.ts index 452758d895..95f3dc110c 100644 --- a/src/redux/cluster/service/kube-control.ts +++ b/src/redux/cluster/service/kube-control.ts @@ -44,7 +44,7 @@ export const KUBECTL = { function createGlobalArgs(globals: KubectlGlobal) { const globalArgs = []; - if (globals.kubeconfig) globalArgs.push(`--kubeconfig=${globals.kubeconfig}`); - if (globals.context) globalArgs.push(`--context=${globals.context}`); + if (globals.kubeconfig) globalArgs.push(`--kubeconfig=${JSON.stringify(globals.kubeconfig)}`); + if (globals.context) globalArgs.push(`--context=${JSON.stringify(globals.context)}`); return globalArgs; } diff --git a/src/redux/thunks/applyResource.ts b/src/redux/thunks/applyResource.ts index 8c22820603..eb2a8c8bc0 100644 --- a/src/redux/thunks/applyResource.ts +++ b/src/redux/thunks/applyResource.ts @@ -69,7 +69,7 @@ function applyKustomization( ) { const folder = getAbsoluteResourceFolder(resourceMeta, fileMap); - const args: string[] = ['--context', context]; + const args: string[] = ['--context', JSON.stringify(context)]; if (namespace) { args.push(...['--namespace', namespace.name]); } diff --git a/src/shared/utils/commands/kubectl.ts b/src/shared/utils/commands/kubectl.ts index 6403d681f7..f6e89fbec7 100644 --- a/src/shared/utils/commands/kubectl.ts +++ b/src/shared/utils/commands/kubectl.ts @@ -6,7 +6,7 @@ export function createKubectlApplyCommand( {context, namespace, input}: KubectlApplyArgs, env?: KubectlEnv ): CommandOptions { - const args = ['--context', context, 'apply', '-f', '-']; + const args = ['--context', JSON.stringify(context), 'apply', '-f', '-']; if (namespace) { args.unshift('--namespace', namespace); diff --git a/src/utils/cluster.ts b/src/utils/cluster.ts index 66183794ec..a6b11f44c7 100644 --- a/src/utils/cluster.ts +++ b/src/utils/cluster.ts @@ -9,9 +9,9 @@ export function getHelmClusterArgs(): string[] { const args = [ '--kubeconfig', - kubeconfigPath, + JSON.stringify(kubeconfigPath), '--kube-context', - context, + JSON.stringify(context), '--kube-apiserver', `http://127.0.0.1:${proxyPort}`, ];