Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins/plugin-kubectl): Show Previous option for Logs tab
Fixes #4864
- Loading branch information
Showing
12 changed files
with
308 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* 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 { CLI, Common, ReplExpect, Selectors, SidecarExpect } from '@kui-shell/test' | ||
import { defaultModeForGet, waitForGreen } from '@kui-shell/plugin-kubectl/tests/lib/k8s/utils' | ||
|
||
export function create(this: Common.ISuite, ns: string, inputEncoded: string, podName: string) { | ||
it(`should create sample pod from URL`, () => { | ||
return CLI.command(`echo ${inputEncoded} | base64 --decode | kubectl create -f - -n ${ns}`, this.app) | ||
.then(ReplExpect.okWithPtyOutput(podName)) | ||
.catch(Common.oops(this, true)) | ||
}) | ||
} | ||
|
||
export function wait(this: Common.ISuite, ns: string, podName: string) { | ||
it(`should wait for the pod to come up`, () => { | ||
return CLI.command(`kubectl get pod ${podName} -n ${ns} -w`, this.app) | ||
.then(ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(podName) })) | ||
.then(selector => waitForGreen(this.app, selector)) | ||
.catch(Common.oops(this, true)) | ||
}) | ||
} | ||
|
||
export function get(this: Common.ISuite, ns: string, podName: string, wait = true) { | ||
it(`should get pod ${podName} via kubectl then click`, async () => { | ||
try { | ||
const selector: string = await CLI.command(`kubectl get pods ${podName} -n ${ns}`, this.app).then( | ||
ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(podName) }) | ||
) | ||
|
||
if (wait) { | ||
// wait for the badge to become green | ||
await waitForGreen(this.app, selector) | ||
} | ||
|
||
// now click on the table row | ||
await this.app.client.click(`${selector} .clickable`) | ||
await SidecarExpect.open(this.app) | ||
.then(SidecarExpect.mode(defaultModeForGet)) | ||
.then(SidecarExpect.showing(podName)) | ||
} catch (err) { | ||
return Common.oops(this, true)(err) | ||
} | ||
}) | ||
} | ||
|
||
export async function clickRetry(this: Common.ISuite) { | ||
await this.app.client.waitForVisible(Selectors.SIDECAR_MODE_BUTTON('retry-streaming')) | ||
await this.app.client.click(Selectors.SIDECAR_MODE_BUTTON('retry-streaming')) | ||
} | ||
|
||
async function waitUntilPreviousIs(this: Common.ISuite, type: 'info' | 'warning', previous: boolean) { | ||
const click = clickRetry.bind(this) | ||
|
||
await this.app.client.waitUntil(async () => { | ||
if (!this.app.client.isExisting(Selectors.SIDECAR_TOOLBAR_TEXT(type))) { | ||
await click() | ||
return false | ||
} else { | ||
return true | ||
} | ||
}) | ||
|
||
await SidecarExpect.toolbarText({ type, text: previous ? 'previous instance' : '' }) | ||
} | ||
|
||
export function logs( | ||
this: Common.ISuite, | ||
ns: string, | ||
podName: string, | ||
containerName: string, | ||
type: 'info' | 'warning', | ||
previous: boolean | ||
) { | ||
const wait = waitUntilPreviousIs.bind(this, type, previous) | ||
|
||
it(`should get logs for ${podName} with previous=${previous} via command`, async () => { | ||
try { | ||
await CLI.command( | ||
`kubectl logs ${podName} -c ${containerName} -n ${ns} ${previous ? '--previous' : ''}`, | ||
this.app | ||
) | ||
.then(ReplExpect.justOK) | ||
.then(SidecarExpect.open) | ||
.then(SidecarExpect.showing(podName, undefined, undefined, ns)) | ||
.then(SidecarExpect.mode('logs')) | ||
|
||
await wait() | ||
} catch (err) { | ||
await Common.oops(this, true) | ||
} | ||
}) | ||
} | ||
|
||
export function clickPrevious(this: Common.ISuite, type: 'info' | 'warning', previous: boolean) { | ||
const wait = waitUntilPreviousIs.bind(this, type, previous) | ||
|
||
it(`should click the previous toggle button and expect previous=${previous}`, async () => { | ||
const mode = 'kubectl-logs-previous-toggle' | ||
await this.app.client.waitForVisible(Selectors.SIDECAR_MODE_BUTTON(mode)) | ||
await this.app.client.click(Selectors.SIDECAR_MODE_BUTTON(mode)) | ||
await wait() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
plugins/plugin-kubectl/logs/src/test/logs/logs-tab-previous.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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 { Common } from '@kui-shell/test' | ||
import { createNS, allocateNS, deleteNS } from '@kui-shell/plugin-kubectl/tests/lib/k8s/utils' | ||
|
||
import { clickPrevious, create, logs, wait } from './helpers' | ||
|
||
import { readFileSync } from 'fs' | ||
import { dirname, join } from 'path' | ||
const ROOT = dirname(require.resolve('@kui-shell/plugin-kubectl/tests/package.json')) | ||
const inputBuffer = readFileSync(join(ROOT, 'data/k8s/crashy.yaml')) | ||
const inputEncoded = inputBuffer.toString('base64') | ||
|
||
const podName = 'kui-crashy' | ||
const containerName = 'crashy' | ||
|
||
describe(`kubectl Logs previous tab ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) { | ||
before(Common.before(this)) | ||
after(Common.after(this)) | ||
|
||
const ns = createNS() | ||
|
||
const createPodWithoutWaiting = create.bind(this, ns) | ||
const waitForPod = wait.bind(this, ns, podName) | ||
const kubectlLogs = logs.bind(this, ns, podName, containerName, 'warning', false) | ||
const kubectlLogsPrevious = logs.bind(this, ns, podName, containerName, 'warning', true) | ||
const clickPreviousToggle = clickPrevious.bind(this) | ||
|
||
/* Here comes the test */ | ||
allocateNS(this, ns) | ||
|
||
createPodWithoutWaiting(inputEncoded, podName) | ||
waitForPod() | ||
|
||
kubectlLogsPrevious() | ||
clickPreviousToggle('warning', false) // click toggle and expect previous=false | ||
|
||
kubectlLogs() | ||
clickPreviousToggle('warning', true) // click toggle and expect previous=true | ||
|
||
deleteNS(this, ns) | ||
}) |
Oops, something went wrong.