diff --git a/plugins/plugin-kubectl/src/controller/kubectl/options.ts b/plugins/plugin-kubectl/src/controller/kubectl/options.ts index 34edaed2fba..0f0c7946323 100644 --- a/plugins/plugin-kubectl/src/controller/kubectl/options.ts +++ b/plugins/plugin-kubectl/src/controller/kubectl/options.ts @@ -195,7 +195,16 @@ export function hasLabel(args: Arguments) { /** @return the namespace as expressed in the command line, or undefined if not */ export function getNamespaceAsExpressed(args: Pick, 'parsedOptions'>): string { const ns = args.parsedOptions.n || args.parsedOptions.namespace - if (Array.isArray(ns)) { + if (!ns) { + // look for -nfoo, which yargs-parser doesn't handle very well + // this will show up as a parsedOption of { nfoo: true } + const maybeNs = Object.entries(args.parsedOptions).find( + ([key, value]) => value === true && key.length > 1 && key[0] === 'n' + ) + if (maybeNs) { + return maybeNs[0].slice(1) + } + } else if (Array.isArray(ns)) { return ns[ns.length - 1] } else { return ns diff --git a/plugins/plugin-kubectl/src/test/k8s1/apply-pod.ts b/plugins/plugin-kubectl/src/test/k8s1/apply-pod.ts index 8d612ce6944..4bf6329a4c1 100644 --- a/plugins/plugin-kubectl/src/test/k8s1/apply-pod.ts +++ b/plugins/plugin-kubectl/src/test/k8s1/apply-pod.ts @@ -32,7 +32,8 @@ describe(`kubectl apply pod ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi after(Common.after(this)) const ns: string = createNS() - const inNamespace = `-n ${ns}` + const inNamespace = `-n${ns}` + // ^^^ intentionally no space between -n and ${ns} to cover #8992 allocateNS(this, ns)