Skip to content

Commit

Permalink
fix(plugins/plugin-kubectl): oc login does not switch kube proxy in b…
Browse files Browse the repository at this point in the history
…rowser clients

part of #7742
  • Loading branch information
starpit authored and k8s-ci-robot committed Jun 29, 2021
1 parent a8d99a7 commit 8ca795f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion plugins/plugin-kubectl/oc/src/controller/oc/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,22 @@ import { doExecWithPty, emitKubectlConfigChangeEvent } from '@kui-shell/plugin-k

export default function registerOcLogin(registrar: Registrar) {
registrar.listen('/oc/login', async args => {
const response = await doExecWithPty(args)
const command = args.command.replace(/login/, '_login')
const response = await args.REPL.qexec(command)
emitKubectlConfigChangeEvent('SetNamespaceOrContext')
return response
})

registrar.listen(
'/oc/_login',
async args => {
args.command = args.command.replace(/_login/, 'login')
args.argvNoOptions[1] = 'login'
args.argv[1] = 'login'
const response = await doExecWithPty(args, undefined, 'oc')
emitKubectlConfigChangeEvent('SetNamespaceOrContext')
return response
},
{ requiresLocal: true }
)
}
4 changes: 2 additions & 2 deletions plugins/plugin-kubectl/src/controller/kubectl/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export async function doExecWithPty<
Content = void,
Response extends KResponse<Content> = KResponse<Content>,
O extends KubeOptions = KubeOptions
>(args: Arguments<O>, prepare: Prepare<O> = NoPrepare): Promise<string | Response> {
>(args: Arguments<O>, prepare: Prepare<O> = NoPrepare, exec?: string): Promise<string | Response> {
if (!reallyNeedsPty(args) && (isHeadless() || (!inBrowser() && args.execOptions.raw))) {
return doExecWithStdout(args, prepare)
return doExecWithStdout(args, prepare, exec)
} else {
//
// For commands `kubectl (--help/-h)` and `k (--help/-h)`, render usage model;
Expand Down

0 comments on commit 8ca795f

Please sign in to comment.