forked from vscode-kubernetes-tools/vscode-kubernetes-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow switching namespace via the command palette (vscode-kubernetes-…
- Loading branch information
1 parent
6414a1f
commit 5b09863
Showing
3 changed files
with
58 additions
and
11 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,38 @@ | ||
import { refreshExplorer, promptKindName } from './extension'; | ||
import * as kubectlUtils from './kubectlUtils'; | ||
import * as kuberesources from './kuberesources'; | ||
import * as explorer from './explorer'; | ||
import { Kubectl } from './kubectl'; | ||
|
||
export async function useNamespaceKubernetes(explorerNode: explorer.KubernetesObject, kubectl: Kubectl) { | ||
if (explorerNode) { | ||
if (await kubectlUtils.switchNamespace(kubectl, explorerNode.id)) { | ||
refreshExplorer(); | ||
return; | ||
} | ||
} else { | ||
const currentNS = await kubectlUtils.currentNamespace(kubectl); | ||
promptKindName([kuberesources.allKinds.namespace], undefined, | ||
{ | ||
prompt: 'What namespace do you want to use?', | ||
placeHolder: 'Enter the namespace to switch to or press enter to select from available list', | ||
filterNames: [currentNS] | ||
}, | ||
async (resource) => { | ||
if (resource) { | ||
let toSwitchNamespace = resource; | ||
// resource will be of format <kind>/<name>, when picked up from the quickpick | ||
if (toSwitchNamespace.lastIndexOf('/') !== -1) { | ||
toSwitchNamespace = toSwitchNamespace.substring(toSwitchNamespace.lastIndexOf('/') + 1); | ||
} | ||
// Switch if an only if the currentNS and toSwitchNamespace are different | ||
if (toSwitchNamespace && currentNS !== toSwitchNamespace) { | ||
const promiseSwitchNS = await kubectlUtils.switchNamespace(kubectl, toSwitchNamespace); | ||
if (promiseSwitchNS) { | ||
refreshExplorer(); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
} |