Skip to content

Commit

Permalink
fix(plugins/plugin-kubectl): Logs tab should have a default tail limit
Browse files Browse the repository at this point in the history
Fixes #4810
Fixes #4818
  • Loading branch information
starpit committed Jun 6, 2020
1 parent 2d33eb7 commit 1a4e827
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion plugins/plugin-kubectl/logs/src/test/logs/logs-multi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,11 @@ describe(`kubectl Logs multiple pods via selector ${process.env.MOCHA_RUN_TARGET
// testing various combination here
switchContainer(fqn1, [containerName1], [containerName2, 'hi'])
switchContainer(fqn2, [containerName2], [containerName1, 'hi'])
switchContainer(allContainers, [containerName1, containerName2, 'hi'], [])

// note: due to the --tail flag, we don't expect to see
// containerName1 in the logs -- it probably has flown off the top
// of the xtermjs scrollback
switchContainer(allContainers, [/* containerName1, */ containerName2, 'hi'], [])

// use k get -lfoo=bar to show the Logs tab, the first container of the first pod
getLogsViaLabel(`-c ${containerName1}`)
Expand Down
8 changes: 3 additions & 5 deletions plugins/plugin-kubectl/src/lib/view/modes/ExecIntoPod.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,10 @@ export class Terminal<S extends TerminalState = TerminalState> extends Container

private abortPriorJob() {
if (this.state.job) {
const abortThisJob = this.state.job

// the setTimeout helps us avoid exit-after-spawn races
setTimeout(() => {
if (this.state.job) {
this.state.job.abort()
}
}, 5000)
setTimeout(() => abortThisJob.abort(), 5000)
}
}

Expand Down
12 changes: 10 additions & 2 deletions plugins/plugin-kubectl/src/lib/view/modes/logs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ import { KubeOptions, getContainer, hasLabel } from '../../../controller/kubectl

const strings = i18n('plugin-kubectl', 'logs')

/**
* Default --tail flag, if the user does not specify one. See
* https://github.com/IBM/kui/issues/4810
*
*/
const defaultTail = 1000

export class Logs extends Terminal {
public constructor(props: ContainerProps) {
super(props)
Expand Down Expand Up @@ -107,7 +114,8 @@ export class Logs extends Terminal {
// --all-containers for convenience
// 2) only use argsForMode once
// 3) do not add -f unless the user requested it
const command = `${args.argsForMode.command} ${!containerName ? container : ''}`
const tail = !args.argsForMode.parsedOptions.tail ? ` --tail ${defaultTail}` : ''
const command = `${args.argsForMode.command} ${!containerName ? container : ''} ${tail}`

if (!isMulti) {
args.argsForMode.command = undefined // point 2
Expand All @@ -131,7 +139,7 @@ export class Logs extends Terminal {

const command = `${getCommandFromArgs(args)} logs ${podName} -n ${
pod.metadata.namespace
} ${theContainer} ${dashF}`
} ${theContainer} ${dashF} --tail ${defaultTail}`

return {
isLive,
Expand Down

0 comments on commit 1a4e827

Please sign in to comment.