File tree Expand file tree Collapse file tree 3 files changed +22
-0
lines changed
Expand file tree Collapse file tree 3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 3131 kubectx -d <NAME> : delete context <NAME> ('.' for current-context)
3232 (this command won't delete the user/cluster entry
3333 that is used by the context)
34+ kubectx -u, --unset : unset the current context
3435```
3536
3637### Usage
Original file line number Diff line number Diff line change 4343 $SELF -d <NAME> [<NAME...>] : delete context <NAME> ('.' for current-context)
4444 (this command won't delete the user/cluster entry
4545 that is used by the context)
46+ $SELF -u, --unset : unset the current context
4647
4748 $SELF -h,--help : show this message
4849EOF
@@ -185,6 +186,11 @@ delete_context() {
185186 $KUBECTL config delete-context " ${ctx} "
186187}
187188
189+ unset_context () {
190+ echo " Unsetting current context." >&2
191+ $KUBECTL config unset current-context
192+ }
193+
188194main () {
189195 if hash kubectl 2> /dev/null; then
190196 KUBECTL=kubectl
@@ -220,6 +226,8 @@ main() {
220226 # - it does not fail when current-context property is not set
221227 # - it does not return a trailing newline
222228 kubectl config current-context
229+ elif [[ " ${1} " == ' -u' || " ${1} " == ' --unset' ]]; then
230+ unset_context
223231 elif [[ " ${1} " == ' -h' || " ${1} " == ' --help' ]]; then
224232 usage
225233 elif [[ " ${1} " =~ ^-(.* ) ]]; then
Original file line number Diff line number Diff line change @@ -239,3 +239,16 @@ load common
239239 [ " $status " -eq 0 ]
240240 [[ " $output " = " user2@cluster1" ]]
241241}
242+
243+ @test " unset selected context" {
244+ use_config config2
245+
246+ run ${COMMAND} user1@cluster1
247+ [ " $status " -eq 0 ]
248+
249+ run ${COMMAND} -u
250+ [ " $status " -eq 0 ]
251+
252+ run ${COMMAND} -c
253+ [ " $status " -ne 0 ]
254+ }
You can’t perform that action at this time.
0 commit comments