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

Commit 1c8341d

Browse files
myan9starpit
authored andcommitted
fix(plugins/plugin-kubectl): allow clients to define a default kubectl CLI
Fixes #7051
1 parent b0460b8 commit 1c8341d

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

plugins/plugin-kubectl/components/src/CurrentContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
i18n
3232
} from '@kui-shell/core'
3333
import {
34+
kubectl,
3435
getAllContexts,
3536
KubeContext,
3637
onKubectlConfigChangeEvents,
@@ -164,7 +165,7 @@ export default class CurrentContext extends React.PureComponent<{}, State> {
164165
label: this.renderName(context.metadata.name),
165166
isSelected: context.spec.isCurrent,
166167
description: context.spec.isCurrent ? strings('This is your current context') : undefined,
167-
command: `kubectl config use-context ${encodeComponent(context.metadata.name)}`
168+
command: `${kubectl} config use-context ${encodeComponent(context.metadata.name)}`
168169
}))
169170

170171
return (

plugins/plugin-kubectl/components/src/CurrentNamespace.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
} from '@kui-shell/core'
3333

3434
import {
35+
kubectl,
3536
KubeContext,
3637
getCurrentDefaultNamespace,
3738
onKubectlConfigChangeEvents,
@@ -90,7 +91,7 @@ export default class CurrentNamespace extends React.PureComponent<{}, State> {
9091
try {
9192
const [currentNamespace, allNamespaces] = await Promise.all([
9293
getCurrentDefaultNamespace(tab),
93-
tab.REPL.qexec<string>('kubectl get ns -o name').then(_ =>
94+
tab.REPL.qexec<string>(`${kubectl} get ns -o name`).then(_ =>
9495
_.split(/\n/).map(_ => _.replace(/^namespace\//, ''))
9596
)
9697
])
@@ -143,7 +144,7 @@ export default class CurrentNamespace extends React.PureComponent<{}, State> {
143144

144145
private listNamespace() {
145146
return (
146-
<a href="#" onClick={() => pexecInCurrentTab('kubectl get namespace')}>
147+
<a href="#" onClick={() => pexecInCurrentTab(`${kubectl} get namespace`)}>
147148
{strings('Show Full Details')}
148149
</a>
149150
)
@@ -177,7 +178,7 @@ export default class CurrentNamespace extends React.PureComponent<{}, State> {
177178
label: ns,
178179
isSelected,
179180
description: isSelected ? strings('This is your current namespace') : undefined,
180-
command: `kubectl config set-context --current --namespace=${ns}`
181+
command: `${kubectl} config set-context --current --namespace=${ns}`
181182
}
182183
}
183184

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2021 The Kubernetes Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import Debug from 'debug'
18+
const debug = Debug('plugin-kubectl/controller/cli')
19+
20+
/**
21+
* The kubectl cli we want to use for all kubectl commands. For example,
22+
* `kubectl = oc `;`${kubectl} get pods`
23+
*
24+
*/
25+
function _kubectl(): string {
26+
const _default = process.env.KUI_DEFAULT_KUBECTL || 'kubectl'
27+
28+
try {
29+
const { defaultKubectl } = require('@kui-shell/client/config.d/exec.json')
30+
return defaultKubectl || _default
31+
} catch (err) {
32+
debug('Client did not define a default kubectl CLI, assuming default kubectl')
33+
return _default
34+
}
35+
}
36+
37+
export default _kubectl()

plugins/plugin-kubectl/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export { doExecRaw, doNativeExec } from './controller/kubectl/raw'
6262

6363
export { default as commandPrefix } from './controller/command-prefix'
6464

65+
export { default as kubectl } from './controller/cli'
66+
6567
export { default as defaultFlags, flags } from './controller/kubectl/flags'
6668

6769
export {

0 commit comments

Comments
 (0)