Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugins/plugin-kubectl): kubectl get -nfoo does not get from namespace foo #8995

Merged
merged 1 commit into from
Sep 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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