mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-08-09 11:17:44 +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 {
|
func (op InteractiveSwitchOp) Run(_, stderr io.Writer) error {
|
||||||
// parse kubeconfig just to see if it can be loaded
|
// parse kubeconfig just to see if it can be loaded
|
||||||
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
kc := new(kubeconfig.Kubeconfig).WithLoader(kubeconfig.DefaultLoader)
|
||||||
|
|
||||||
if err := kc.Parse(); err != nil {
|
if err := kc.Parse(); err != nil {
|
||||||
if cmdutil.IsNotFoundErr(err) {
|
if cmdutil.IsNotFoundErr(err) {
|
||||||
printer.Warning(stderr, "kubeconfig file not found")
|
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")
|
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()
|
kc.Close()
|
||||||
|
|
||||||
cmd := exec.Command("fzf", "--ansi", "--no-preview")
|
cmd := exec.Command("fzf", "--ansi", "--no-preview")
|
||||||
|
@ -41,6 +41,10 @@ func (_ ListOp) Run(stdout, stderr io.Writer) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctxs := kc.ContextNames()
|
ctxs := kc.ContextNames()
|
||||||
|
if ctxs == nil {
|
||||||
|
err := printer.Warning(stderr, "No kubectl context found")
|
||||||
|
return errors.Wrap(err, "kubeconfig error")
|
||||||
|
}
|
||||||
natsort.Sort(ctxs)
|
natsort.Sort(ctxs)
|
||||||
|
|
||||||
cur := kc.GetCurrentContext()
|
cur := kc.GetCurrentContext()
|
||||||
|
@ -214,7 +214,7 @@ load common
|
|||||||
run ${COMMAND}
|
run ${COMMAND}
|
||||||
echo "$output"
|
echo "$output"
|
||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[[ "$output" = "" ]]
|
[[ "$output" = "warning: No kubectl context found" ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "delete several contexts including a non existent one" {
|
@test "delete several contexts including a non existent one" {
|
||||||
@ -242,3 +242,11 @@ load common
|
|||||||
run ${COMMAND} -c
|
run ${COMMAND} -c
|
||||||
[ "$status" -ne 0 ]
|
[ "$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