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(plugin-kubectl): k get pods --all-namespaces has a title with "default" as the namespace #4482

Merged
merged 1 commit into from
May 6, 2020
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
1 change: 1 addition & 0 deletions packages/test/src/api/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const TABLE_SHOW_AS_LIST = (N: number) => `${OUTPUT_N(N)} .kui--toolbar-b
export const TABLE_AS_GRID = (N: number) => `${OUTPUT_N(N)} .kui--data-table-as-grid`
export const TABLE_AS_LIST = (N: number) => `${OUTPUT_N(N)} .bx--data-table:not(.kui--data-table-as-grid)`
export const TABLE_TITLE = (N: number) => `${OUTPUT_N(N)} .kui--data-table-title`
export const TABLE_TITLE_SECONDARY = (N: number) => `${OUTPUT_N(N)} .kui--secondary-breadcrumb`
export const BY_NAME = (name: string) => `tbody [data-name="${name}"]`
export const LIST_RESULT_FIRST = 'tbody tr:first-child .clickable'
export const LIST_RESULT_BY_N_AND_NAME = (N: number, name: string) =>
Expand Down
4 changes: 2 additions & 2 deletions plugins/plugin-kubectl/src/controller/kubectl/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ export interface KubeOptions extends ParsedOptions {
help?: boolean
}

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

export default KubeOptions
8 changes: 5 additions & 3 deletions plugins/plugin-kubectl/src/lib/view/formatTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* limitations under the License.
*/

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

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

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

const strings = i18n('plugin-kubectl')

/** return an array with at least maxColumns entries */
const fillTo = (length: number, maxColumns: number): Cell[] => {
if (length >= maxColumns) {
Expand Down Expand Up @@ -312,7 +314,7 @@ export const formatTable = <O extends KubeOptions>(
body: rows.slice(1),
noSort: true,
title: capitalize(entityTypeFromRows || entityTypeFromCommandLine),
breadcrumbs: [{ label: ns || 'default' }]
breadcrumbs: [{ label: ns || (isForAllNamespaces(options) && strings('all')) || 'default' }]
}
}

Expand Down
54 changes: 34 additions & 20 deletions plugins/plugin-kubectl/src/test/k8s2/get-all-namespaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
waitTillNone
} from '@kui-shell/plugin-kubectl/tests/lib/k8s/utils'

import * as assert from 'assert'

const synonyms = ['kubectl']

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

/** list pods across all namespaces, then find the pod corresponding to the given namespace `ns` */
const listAndClickOn = (ns: string) => {
it(`should list pods --all-namespaces expecting ns ${ns} via ${kubectl} then click`, async () => {
try {
const selector = await CLI.command(`${kubectl} get pods --all-namespaces`, this.app).then(
ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(ns) })
)

// wait for the badge to become green
await waitForGreen(this.app, selector)

// make sure the NAME cell is clickable (as opposed to, say, the NAMESPACE cell)
await this.app.client.waitForExist(`${selector} .clickable[data-key="NAME"]`)

// now click on that cell
await this.app.client.click(`${selector} .clickable`)
await SidecarExpect.open(this.app)
.then(SidecarExpect.mode(defaultModeForGet))
.then(SidecarExpect.showing('nginx', undefined, undefined, ns))
} catch (err) {
return Common.oops(this, true)(err)
}
const allNamespaces = ['--all-namespaces', '-A']

allNamespaces.forEach(allNamespace => {
it(`should list pods ${allNamespace} expecting ns ${ns} via ${kubectl} then click`, async () => {
try {
const { app, count } = await CLI.command(`${kubectl} get pods ${allNamespace}`, this.app)

await this.app.client.waitForExist(Selectors.TABLE_TITLE(count))

const actualTitle = await this.app.client.getText(Selectors.TABLE_TITLE(count))
assert.strictEqual(actualTitle, 'Pod')

const secondaryTitle = await this.app.client.getText(Selectors.TABLE_TITLE_SECONDARY(count))
assert.strictEqual(secondaryTitle, 'all')

const selector = await ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(ns) })({ app, count })

// wait for the badge to become green
await waitForGreen(this.app, selector)

// make sure the NAME cell is clickable (as opposed to, say, the NAMESPACE cell)
await this.app.client.waitForExist(`${selector} .clickable[data-key="NAME"]`)

// now click on that cell
await this.app.client.click(`${selector} .clickable`)
await SidecarExpect.open(this.app)
.then(SidecarExpect.mode(defaultModeForGet))
.then(SidecarExpect.showing('nginx', undefined, undefined, ns))
} catch (err) {
return Common.oops(this, true)(err)
}
})
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ async function getPodDataForAllNodes(
args: Arguments<PodOptions>,
top: (args: Arguments<KubeOptions>) => Promise<Table>
): Promise<Table> {
if (isForAllNamespaces(args) || args.parsedOptions.containers) {
if (isForAllNamespaces(args.parsedOptions) || args.parsedOptions.containers) {
return top(args)
} else {
const [forThisNS, forAllNS] = await Promise.all([top(args), top(withAllNamespaces(args))])
Expand All @@ -224,7 +224,7 @@ async function getPodDataForOneNode(
// strip off the --node <node> option
strip(args, '--node', 1) // 1 means --node takes 1 arg

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

if (podTable.body) {
Expand Down