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

Commit 2f95129

Browse files
myan9starpit
authored andcommitted
fix(plugin-kubectl): k get pods --all-namespaces has a title with "default" as the namespace
Fixes #4466
1 parent 3267e89 commit 2f95129

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

packages/test/src/api/selectors.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const TABLE_SHOW_AS_LIST = (N: number) => `${OUTPUT_N(N)} .kui--toolbar-b
9898
export const TABLE_AS_GRID = (N: number) => `${OUTPUT_N(N)} .kui--data-table-as-grid`
9999
export const TABLE_AS_LIST = (N: number) => `${OUTPUT_N(N)} .bx--data-table:not(.kui--data-table-as-grid)`
100100
export const TABLE_TITLE = (N: number) => `${OUTPUT_N(N)} .kui--data-table-title`
101+
export const TABLE_TITLE_SECONDARY = (N: number) => `${OUTPUT_N(N)} .kui--secondary-breadcrumb`
101102
export const BY_NAME = (name: string) => `tbody [data-name="${name}"]`
102103
export const LIST_RESULT_FIRST = 'tbody tr:first-child .clickable'
103104
export const LIST_RESULT_BY_N_AND_NAME = (N: number, name: string) =>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ export interface KubeOptions extends ParsedOptions {
187187
help?: boolean
188188
}
189189

190-
export function isForAllNamespaces(args: Arguments<KubeOptions>) {
191-
return args.parsedOptions.A || args.parsedOptions['all-namespaces']
190+
export function isForAllNamespaces(parsedOptions: KubeOptions) {
191+
return parsedOptions.A || parsedOptions['all-namespaces']
192192
}
193193

194194
export default KubeOptions

plugins/plugin-kubectl/src/lib/view/formatTable.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Table, Row, Cell, isTable, encodeComponent, Arguments, MixedResponse } from '@kui-shell/core'
17+
import { Table, Row, Cell, isTable, encodeComponent, Arguments, MixedResponse, i18n } from '@kui-shell/core'
1818

1919
import TrafficLight from '../model/traffic-light'
20-
import KubeOptions from '../../controller/kubectl/options'
20+
import KubeOptions, { isForAllNamespaces } from '../../controller/kubectl/options'
2121
import { RawResponse } from '../../controller/kubectl/response'
2222

2323
import cssForValue from './css-for-value'
2424

25+
const strings = i18n('plugin-kubectl')
26+
2527
/** return an array with at least maxColumns entries */
2628
const fillTo = (length: number, maxColumns: number): Cell[] => {
2729
if (length >= maxColumns) {
@@ -312,7 +314,7 @@ export const formatTable = <O extends KubeOptions>(
312314
body: rows.slice(1),
313315
noSort: true,
314316
title: capitalize(entityTypeFromRows || entityTypeFromCommandLine),
315-
breadcrumbs: [{ label: ns || 'default' }]
317+
breadcrumbs: [{ label: ns || (isForAllNamespaces(options) && strings('all')) || 'default' }]
316318
}
317319
}
318320

plugins/plugin-kubectl/src/test/k8s2/get-all-namespaces.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import {
2323
waitTillNone
2424
} from '@kui-shell/plugin-kubectl/tests/lib/k8s/utils'
2525

26+
import * as assert from 'assert'
27+
2628
const synonyms = ['kubectl']
2729

2830
describe(`kubectl get all-namespaces ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
@@ -55,26 +57,38 @@ describe(`kubectl get all-namespaces ${process.env.MOCHA_RUN_TARGET || ''}`, fun
5557

5658
/** list pods across all namespaces, then find the pod corresponding to the given namespace `ns` */
5759
const listAndClickOn = (ns: string) => {
58-
it(`should list pods --all-namespaces expecting ns ${ns} via ${kubectl} then click`, async () => {
59-
try {
60-
const selector = await CLI.command(`${kubectl} get pods --all-namespaces`, this.app).then(
61-
ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(ns) })
62-
)
63-
64-
// wait for the badge to become green
65-
await waitForGreen(this.app, selector)
66-
67-
// make sure the NAME cell is clickable (as opposed to, say, the NAMESPACE cell)
68-
await this.app.client.waitForExist(`${selector} .clickable[data-key="NAME"]`)
69-
70-
// now click on that cell
71-
await this.app.client.click(`${selector} .clickable`)
72-
await SidecarExpect.open(this.app)
73-
.then(SidecarExpect.mode(defaultModeForGet))
74-
.then(SidecarExpect.showing('nginx', undefined, undefined, ns))
75-
} catch (err) {
76-
return Common.oops(this, true)(err)
77-
}
60+
const allNamespaces = ['--all-namespaces', '-A']
61+
62+
allNamespaces.forEach(allNamespace => {
63+
it(`should list pods ${allNamespace} expecting ns ${ns} via ${kubectl} then click`, async () => {
64+
try {
65+
const { app, count } = await CLI.command(`${kubectl} get pods ${allNamespace}`, this.app)
66+
67+
await this.app.client.waitForExist(Selectors.TABLE_TITLE(count))
68+
69+
const actualTitle = await this.app.client.getText(Selectors.TABLE_TITLE(count))
70+
assert.strictEqual(actualTitle, 'Pod')
71+
72+
const secondaryTitle = await this.app.client.getText(Selectors.TABLE_TITLE_SECONDARY(count))
73+
assert.strictEqual(secondaryTitle, 'all')
74+
75+
const selector = await ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(ns) })({ app, count })
76+
77+
// wait for the badge to become green
78+
await waitForGreen(this.app, selector)
79+
80+
// make sure the NAME cell is clickable (as opposed to, say, the NAMESPACE cell)
81+
await this.app.client.waitForExist(`${selector} .clickable[data-key="NAME"]`)
82+
83+
// now click on that cell
84+
await this.app.client.click(`${selector} .clickable`)
85+
await SidecarExpect.open(this.app)
86+
.then(SidecarExpect.mode(defaultModeForGet))
87+
.then(SidecarExpect.showing('nginx', undefined, undefined, ns))
88+
} catch (err) {
89+
return Common.oops(this, true)(err)
90+
}
91+
})
7892
})
7993
}
8094

plugins/plugin-kubectl/view-utilization/src/controller/get-pod-data.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ async function getPodDataForAllNodes(
202202
args: Arguments<PodOptions>,
203203
top: (args: Arguments<KubeOptions>) => Promise<Table>
204204
): Promise<Table> {
205-
if (isForAllNamespaces(args) || args.parsedOptions.containers) {
205+
if (isForAllNamespaces(args.parsedOptions) || args.parsedOptions.containers) {
206206
return top(args)
207207
} else {
208208
const [forThisNS, forAllNS] = await Promise.all([top(args), top(withAllNamespaces(args))])
@@ -224,7 +224,7 @@ async function getPodDataForOneNode(
224224
// strip off the --node <node> option
225225
strip(args, '--node', 1) // 1 means --node takes 1 arg
226226

227-
if (isForAllNamespaces(args) || args.parsedOptions.containers) {
227+
if (isForAllNamespaces(args.parsedOptions) || args.parsedOptions.containers) {
228228
const [podTable, pods] = await Promise.all([top(args), getPodsInNode(args, forNode)])
229229

230230
if (podTable.body) {

0 commit comments

Comments
 (0)