File tree 3 files changed +22
-0
lines changed
3 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 31
31
kubectx -d <NAME> : delete context <NAME> ('.' for current-context)
32
32
(this command won't delete the user/cluster entry
33
33
that is used by the context)
34
+ kubectx -u, --unset : unset the current context
34
35
```
35
36
36
37
### Usage
Original file line number Diff line number Diff line change 43
43
$SELF -d <NAME> [<NAME...>] : delete context <NAME> ('.' for current-context)
44
44
(this command won't delete the user/cluster entry
45
45
that is used by the context)
46
+ $SELF -u, --unset : unset the current context
46
47
47
48
$SELF -h,--help : show this message
48
49
EOF
@@ -185,6 +186,11 @@ delete_context() {
185
186
$KUBECTL config delete-context " ${ctx} "
186
187
}
187
188
189
+ unset_context () {
190
+ echo " Unsetting current context." >&2
191
+ $KUBECTL config unset current-context
192
+ }
193
+
188
194
main () {
189
195
if hash kubectl 2> /dev/null; then
190
196
KUBECTL=kubectl
@@ -220,6 +226,8 @@ main() {
220
226
# - it does not fail when current-context property is not set
221
227
# - it does not return a trailing newline
222
228
kubectl config current-context
229
+ elif [[ " ${1} " == ' -u' || " ${1} " == ' --unset' ]]; then
230
+ unset_context
223
231
elif [[ " ${1} " == ' -h' || " ${1} " == ' --help' ]]; then
224
232
usage
225
233
elif [[ " ${1} " =~ ^-(.* ) ]]; then
Original file line number Diff line number Diff line change @@ -239,3 +239,16 @@ load common
239
239
[ " $status " -eq 0 ]
240
240
[[ " $output " = " user2@cluster1" ]]
241
241
}
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