From 1a4e827caefab22835daf191ef27d9ff9cb0bcb7 Mon Sep 17 00:00:00 2001 From: Nick Mitchell Date: Thu, 4 Jun 2020 19:11:06 -0400 Subject: [PATCH] fix(plugins/plugin-kubectl): Logs tab should have a default tail limit Fixes #4810 Fixes #4818 --- .../plugin-kubectl/logs/src/test/logs/logs-multi.ts | 6 +++++- .../src/lib/view/modes/ExecIntoPod.tsx | 8 +++----- plugins/plugin-kubectl/src/lib/view/modes/logs.tsx | 12 ++++++++++-- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/plugins/plugin-kubectl/logs/src/test/logs/logs-multi.ts b/plugins/plugin-kubectl/logs/src/test/logs/logs-multi.ts index 99876660c1c..8b3f54310b4 100644 --- a/plugins/plugin-kubectl/logs/src/test/logs/logs-multi.ts +++ b/plugins/plugin-kubectl/logs/src/test/logs/logs-multi.ts @@ -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}`) diff --git a/plugins/plugin-kubectl/src/lib/view/modes/ExecIntoPod.tsx b/plugins/plugin-kubectl/src/lib/view/modes/ExecIntoPod.tsx index ec016399b55..e9d245d5798 100644 --- a/plugins/plugin-kubectl/src/lib/view/modes/ExecIntoPod.tsx +++ b/plugins/plugin-kubectl/src/lib/view/modes/ExecIntoPod.tsx @@ -256,12 +256,10 @@ export class Terminal 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) } } diff --git a/plugins/plugin-kubectl/src/lib/view/modes/logs.tsx b/plugins/plugin-kubectl/src/lib/view/modes/logs.tsx index 0773787d844..660e606b560 100644 --- a/plugins/plugin-kubectl/src/lib/view/modes/logs.tsx +++ b/plugins/plugin-kubectl/src/lib/view/modes/logs.tsx @@ -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) @@ -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 @@ -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,