Skip to content
This repository was archived by the owner on Jul 30, 2025. It is now read-only.

Commit 97a33a4

Browse files
committed
fix(plugins/plugin-kubectl): kubectl delete ns m1 m2 m3 m4 results in a one-row table
Fixes #5694
1 parent 2a45124 commit 97a33a4

File tree

3 files changed

+44
-19
lines changed

3 files changed

+44
-19
lines changed

plugins/plugin-client-common/web/css/static/ui.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ $kui--page-content-paragraph-padding: 0.375rem;
805805
.page-content p {
806806
padding: $kui--page-content-paragraph-padding 0;
807807
}
808-
.repl-output .page-content p:first-child {
808+
.repl-output .page-content p:only-child {
809809
padding: 0;
810810
}
811811
.page-content h1 {

plugins/plugin-kubectl/src/controller/kubectl/status.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,28 @@ async function getResourcesReferencedByCommandLine(
194194
): Promise<ResourceRef[]> {
195195
// Notes: kubectl create secret <generic> <name> <-- the name is in a different slot :(
196196
const [kind, nameGroupVersion, nameAlt] = argvRest
197+
const namespace = await getNamespace(args)
197198

198199
const isDelete = args.parsedOptions['final-state'] === FinalState.OfflineLike
200+
if (isDelete) {
201+
// kubectl delete (ns [m1 m2 m2 m3])
202+
// ^ argvRest ^
203+
// ^ slice(1) ^
204+
return argvRest
205+
.slice(1)
206+
.map(nameGroupVersion => nameGroupVersion.split(/\./))
207+
.map(([name, group, version]) => ({
208+
group,
209+
version,
210+
kind,
211+
name,
212+
namespace
213+
}))
214+
}
215+
199216
const isCreateSecret = !isDelete && /secret(s)?/i.test(kind)
200217
const [name, group, version] = isCreateSecret ? [nameAlt] : nameGroupVersion.split(/\./)
201218

202-
const namespace = await getNamespace(args)
203-
204219
return [{ group, version, kind, name, namespace }]
205220
}
206221

plugins/plugin-kubectl/src/test/k8s3/namespace.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,35 @@ import { strictEqual } from 'assert'
1818
import { Common, CLI, ReplExpect, SidecarExpect, Selectors } from '@kui-shell/test'
1919
import { waitForGreen, waitForRed, createNS, waitTillNone } from '@kui-shell/plugin-kubectl/tests/lib/k8s/utils'
2020

21-
const ns1: string = createNS()
22-
const ns2: string = createNS()
21+
const ns1 = createNS()
22+
const ns2 = createNS()
23+
const ns3 = createNS()
24+
const ns4 = createNS()
2325
const synonyms = ['kubectl']
2426

25-
describe(`kubectl namespace ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
27+
describe(`kubectl namespace CRUD ${process.env.MOCHA_RUN_TARGET || ''}`, function(this: Common.ISuite) {
2628
before(Common.before(this))
2729
after(Common.after(this))
2830

2931
synonyms.forEach(kubectl => {
30-
/** delete the given namespace */
31-
const deleteIt = (name: string, errOk = false) => {
32-
it(`should delete the namespace ${name} via ${kubectl}`, () => {
33-
return CLI.command(`${kubectl} delete namespace ${name}`, this.app)
34-
.then(ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(name) }))
35-
.then(selector => waitForRed(this.app, selector))
36-
.then(() => waitTillNone('namespace', undefined, name))
37-
.catch(err => {
38-
if (!errOk) {
39-
return Common.oops(this, true)(err)
40-
}
41-
})
32+
/** delete the given namespaces */
33+
const deleteIt = (names: string[], errOk = false) => {
34+
it(`should delete the namespaces ${names} via ${kubectl}`, async () => {
35+
try {
36+
const res = await CLI.command(`${kubectl} delete namespace ${names.join(' ')}`, this.app)
37+
38+
await Promise.all(
39+
names.map(name => {
40+
return ReplExpect.okWithCustom({ selector: Selectors.BY_NAME(name) })(res)
41+
.then(selector => waitForRed(this.app, selector))
42+
.then(() => waitTillNone('namespace', undefined, name))
43+
})
44+
)
45+
} catch (err) {
46+
if (!errOk) {
47+
return Common.oops(this, true)(err)
48+
}
49+
}
4250
})
4351
}
4452

@@ -205,7 +213,9 @@ describe(`kubectl namespace ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
205213
describeIt(ns2)
206214
createPod(ns1)
207215
createPod(ns2)
208-
deleteIt(ns1)
216+
createIt(ns3)
217+
createIt(ns4)
218+
deleteIt([ns1, ns3, ns4])
209219
deleteViaButton(ns2)
210220
})
211221
})

0 commit comments

Comments
 (0)