Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 7d44bcb

Browse files
committed
fix(plugins/plugin-kubectl): make sure to pick the last specified label selector
Fixes #6840
1 parent 74f4e55 commit 7d44bcb

File tree

1 file changed

+8
-1
lines changed
  • plugins/plugin-kubectl/src/controller/kubectl

1 file changed

+8
-1
lines changed

plugins/plugin-kubectl/src/controller/kubectl/options.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,23 @@ export function getLabel({ parsedOptions }: Pick<Arguments<KubeOptions>, 'parsed
141141
if (label) {
142142
return label
143143
} else {
144+
// we need to pick the last one, in the case the command line
145+
// specified more than one; e.g. for `k get pod -lname=nginx
146+
// -lfoo=bar -n t1`, the kubectl CLI picks foo=bar
147+
let lastOne: string
148+
144149
// yargs-parser doesn't handle -lname=nginx without the space
145150
// after -l; or least not the way we've configured it
146151
for (const key in parsedOptions) {
147152
if (/^l.+/.test(key) && key !== 'limit') {
148153
const value = parsedOptions[key]
149154
if (value) {
150-
return `${key.slice(1)}=${value}`
155+
lastOne = `${key.slice(1)}=${value}`
151156
}
152157
}
153158
}
159+
160+
return lastOne
154161
}
155162
}
156163

0 commit comments

Comments
 (0)