mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-08-01 23:41:19 +00:00
Merge 39f8e1ab7c
into 013b6bc252
This commit is contained in:
commit
1680b370dc
@ -41,6 +41,7 @@ type InteractiveDeleteOp struct {
|
||||
func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
// parse kubeconfig just to see if it can be loaded
|
||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||
|
||||
if err := kc.Parse(); err != nil {
|
||||
if cmdutil.IsNotFoundErr(err) {
|
||||
printer.Warning(stderr, "kubeconfig file not found")
|
||||
@ -48,6 +49,12 @@ func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||
}
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
|
||||
ctxs := kc.ContextNames()
|
||||
if ctxs == nil {
|
||||
err := printer.Warning(stderr, "No kubectl context found")
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
kc.Close()
|
||||
|
||||
cmd := exec.Command("fzf", "--ansi", "--no-preview")
|
||||
|
@ -41,6 +41,10 @@ func (_ ListOp) Run(stdout, stderr io.Writer) error {
|
||||
}
|
||||
|
||||
ctxs := kc.ContextNames()
|
||||
if ctxs == nil {
|
||||
err := printer.Warning(stderr, "No kubectl context found")
|
||||
return errors.Wrap(err, "kubeconfig error")
|
||||
}
|
||||
natsort.Sort(ctxs)
|
||||
|
||||
cur := kc.GetCurrentContext()
|
||||
|
@ -214,7 +214,7 @@ load common
|
||||
run ${COMMAND}
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" = "" ]]
|
||||
[[ "$output" = "warning: No kubectl context found" ]]
|
||||
}
|
||||
|
||||
@test "delete several contexts including a non existent one" {
|
||||
@ -242,3 +242,11 @@ load common
|
||||
run ${COMMAND} -c
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "display msg on empty context" {
|
||||
use_config config3
|
||||
run ${COMMAND}
|
||||
echo "$output"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" = "warning: No kubectl context found" ]]
|
||||
}
|
||||
|
15
test/testdata/config3
vendored
Normal file
15
test/testdata/config3
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
# config with no context
|
||||
|
||||
apiVersion: v1
|
||||
clusters:
|
||||
- cluster:
|
||||
server: ""
|
||||
name: cluster1
|
||||
contexts:
|
||||
- context:
|
||||
current-context: ""
|
||||
kind: Config
|
||||
preferences: {}
|
||||
users:
|
||||
- name: user1
|
||||
user: {}
|
Loading…
Reference in New Issue
Block a user