Skip to content

Commit

Permalink
fix(plugins/plugin-kubectl): does not get from namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Sep 3, 2022
1 parent b6d19ed commit d5b8fbf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion plugins/plugin-kubectl/src/controller/kubectl/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,16 @@ export function hasLabel(args: Arguments<KubeOptions>) {
/** @return the namespace as expressed in the command line, or undefined if not */
export function getNamespaceAsExpressed(args: Pick<Arguments<KubeOptions>, '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
Expand Down
3 changes: 2 additions & 1 deletion plugins/plugin-kubectl/src/test/k8s1/apply-pod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit d5b8fbf

Please sign in to comment.