Skip to content

Commit

Permalink
fix: stringify the context and kubeconfig cli arguments
Browse files Browse the repository at this point in the history
prevents issues related to empty spaces, line breaks, existing quotes etc.
  • Loading branch information
monojack committed Feb 21, 2024
1 parent 66a036c commit cc1919e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions electron/kubernetes/ProxyInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`];
Expand Down
4 changes: 2 additions & 2 deletions src/redux/cluster/service/kube-control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/redux/thunks/applyResource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/utils/commands/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
];
Expand Down

0 comments on commit cc1919e

Please sign in to comment.