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

Commit 43863f2

Browse files
committed
fix: avoid using kui-custom command for switching kubectl namespace
Fixes #4806
1 parent ed0374f commit 43863f2

File tree

2 files changed

+2
-34
lines changed

2 files changed

+2
-34
lines changed

plugins/plugin-kubectl/src/controller/kubectl/get-namespaces.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
* limitations under the License.
1515
*/
1616

17-
import Debug from 'debug'
1817
import {
1918
Arguments,
2019
Registrar,
@@ -35,8 +34,6 @@ import { doGet, doGetAsMMR, getFlags as flags } from './get'
3534
import { isKubeResource } from '../../lib/model/resource'
3635
import { KubeOptions, isTableRequest, isWatchRequest } from './options'
3736

38-
const debug = Debug('plugin-kubectl/controller/kubectl/get/namespace')
39-
4037
/**
4138
* Summarize the resources in the namespace indicated by the last
4239
* positional argument into a table, where resources are histogrammed
@@ -89,33 +86,6 @@ function doSummarizeNamespace(args: Arguments<KubeOptions>): Promise<Table> {
8986
return doSummarizeNamedNamespace(args.tab, ns)
9087
}
9188

92-
/**
93-
* Switch to the namespace indicated by the last positional argument,
94-
* then summarize the resources in that namespace in a table.
95-
*
96-
*/
97-
async function doSwitchNamespace(args: Arguments<KubeOptions>): Promise<true | Table> {
98-
// switch to this namespace
99-
const ns = args.argvNoOptions[args.argvNoOptions.length - 1]
100-
101-
// this does the actual switch
102-
await args.REPL.qexec(`kubectl config set-context --current --namespace=${ns}`)
103-
104-
let summarizeNamespaceOnSwitch = false
105-
try {
106-
summarizeNamespaceOnSwitch = require('@kui-shell/client/config.d/kubectl.json').summarizeNamespaceOnSwitch
107-
} catch (err) {
108-
debug('using default value for summarizeNamespaceOnSwitch', err)
109-
}
110-
111-
if (!summarizeNamespaceOnSwitch) {
112-
// client config told us not to summarize namespace on switch
113-
return true
114-
}
115-
116-
return doSummarizeNamespace(args)
117-
}
118-
11989
/**
12090
* @return the currently active namespace in the currently selected context
12191
*
@@ -178,7 +148,7 @@ async function asRadioTable(args: Arguments<KubeOptions>, { header, body }: Tabl
178148
Object.assign(rtRow, {
179149
onSelect: () => {
180150
const ns = radioTableCellToString(rtRow.cells[rtRow.nameIdx])
181-
args.REPL.pexec(`namespace switch ns ${ns}`)
151+
args.REPL.pexec(`kubectl config set-context --current --namespace=${ns}`)
182152
}
183153
})
184154
)
@@ -232,6 +202,4 @@ export default (commandTree: Registrar) => {
232202

233203
commandTree.listen(`/${commandPrefix}/namespace/current`, doGetCurrentNamespace, flags)
234204
commandTree.listen(`/${commandPrefix}/namespace/summarize`, doSummarizeNamespace, flags)
235-
commandTree.listen(`/${commandPrefix}/namespace/switch`, doSwitchNamespace, flags)
236-
commandTree.listen(`/${commandPrefix}/ns/switch`, doSwitchNamespace, flags)
237205
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ describe(`kubectl namespace ${process.env.MOCHA_RUN_TARGET || ''}`, function(thi
6262
/** switch to default context via command */
6363
const switchToDefault = () => {
6464
it('should switch back to default via command', () => {
65-
return CLI.command(`namespace switch default`, this.app)
65+
return CLI.command(`kubectl config set-context --current --namespace=default`, this.app)
6666
.then(ReplExpect.okWithAny)
6767
.catch(Common.oops(this, true))
6868
})

0 commit comments

Comments
 (0)