Skip to content

Commit

Permalink
feat: Expand kubectl direct watching to support heterogeneous use cases
Browse files Browse the repository at this point in the history
This PR updates the duration over which red badges flash from 6 cycles down to 3.

This PR also works around an issue in globby. sindresorhus/globby#166

Fixes kubernetes-sigs#6504
  • Loading branch information
starpit committed Jan 8, 2021
1 parent 08e471e commit 96ba419
Show file tree
Hide file tree
Showing 15 changed files with 336 additions and 131 deletions.
2 changes: 1 addition & 1 deletion packages/test/src/api/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export class TestTable {
const cell = await ctx.app.client.$(
`${Selectors.OUTPUT_N(self.cmdIdx)} ${Selectors.TABLE_CELL(row.name, expectTable.header.name)}`
)
await cell.waitForExist()
await cell.waitForExist({ timeout: 10000 })
await cell.click()
await CLI.expectPriorInput(prompt, command)(ctx.app)
} catch (err) {
Expand Down
10 changes: 6 additions & 4 deletions plugins/plugin-bash-like/fs/src/lib/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async function isDir(filepath: string): Promise<Stats> {
return new Promise((resolve, reject) => {
stat(filepath, (err, stats) => {
if (err) {
if (err.code === 'ENOENT') {
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') {
resolve(undefined)
} else {
reject(err)
Expand Down Expand Up @@ -168,14 +168,16 @@ export async function kuiglob({
const globbedEntries =
toGlob.length === 0 && inputs.length > 0
? []
: ((await globby(toGlob.length === 0 ? '*' : toGlob, {
followSymbolicLinks: false,
: (((await globby(toGlob.length === 0 ? ['*'] : toGlob, {
onlyFiles: false,
suppressErrors: true,
expandDirectories: false, // see https://github.com/sindresorhus/globby/issues/166
followSymbolicLinks: false,
dot: parsedOptions.a || parsedOptions.all,
stats: needStats,
objectMode: !needStats,
cwd: isHeadless() ? process.cwd() : tab.state.cwd
})) as RawGlobStats[])
})) as any) as RawGlobStats[])
// ^^^^^^ re: type conversion; globby type declaration issue #139

// handle -d; fast-glob doesn't seem to handle this very well on its
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ $grid-cell-size: 1.25rem;
}

&.red-background {
/* if it's red, then blink around 6 times */
animation: var(--animation-medium-repeating-pulse);
/* if it's red, then blink around 3 times */
animation: var(--animation-short-repeating-pulse);
}
}
}
2 changes: 1 addition & 1 deletion plugins/plugin-ibmcloud/plugin/src/controller/available.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default async function getAvailablePlugins(
tab: Tab,
url = defaultURL
): Promise<{ plugins: AvailablePluginRaw[] }> {
return JSON.parse((await fetchFileString(tab.REPL, `${url}/plugins`))[0])
return JSON.parse((await fetchFileString(tab.REPL, `${url}/plugins`))[0] || '{ "plugins": [] }')
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/plugin-kubectl-flow-views/tekton/src/lib/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const parse = async (raw: string | PromiseLike<string>): Promise<KubeReso
*/
export const read = async (tab: Tab, filepath: string): Promise<string> => {
const data = await fetchFileString(tab.REPL, filepath)
if (data.length === 1) {
if (data.length === 1 && data[0]) {
return data[0]
} else {
throw new Error(`Failed to fetch ${filepath}`)
Expand Down
40 changes: 40 additions & 0 deletions plugins/plugin-kubectl/src/controller/client/direct/404.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 IBM Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Row, Table } from '@kui-shell/core'

import { rowWith, standardStatusHeader } from './unify'
import TrafficLight from '../../../lib/model/traffic-light'

/**
* @return a Row for the given name in `names` with an Offline status.
*
*/
function fabricate404Row(name: string, kind: string): Row {
return rowWith(name, kind, 'Offline', TrafficLight.Red)
}

/**
* @return a Table with one row per given name in `names`, each row
* with an Offline status.
*
*/
export default function fabricate404Table(names: string[], kind: string): Table {
return {
header: standardStatusHeader,
body: names.map(name => fabricate404Row(name, kind))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ export default async function createDirect(
]

const watchPart = await status(args, groups, FinalState.OnlineLike)
return withErrors(watchPart, errors)
if (watchPart) {
return withErrors(watchPart, errors)
}
}
}
}
Expand Down

0 comments on commit 96ba419

Please sign in to comment.