Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Gracefully handle error when kubeconfig not present
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicayuen committed Nov 15, 2017
1 parent 1170074 commit d252456
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ func resolveContext(context *string) (server, namespace string, err error) {
}
ctx := rawConfig.Contexts[ctxName]
if ctx == nil {
return "", "", fmt.Errorf("context '%s' does not exist in the kubeconfig file", *context)
if len(ctxName) == 0 && ctxName == rawConfig.CurrentContext {
// User likely does not have a kubeconfig file.
return "", "", fmt.Errorf("No current context found. Make sure a kubeconfig file is present")
}

return "", "", fmt.Errorf("context '%s' does not exist in the kubeconfig file", ctxName)
}

log.Infof("Using context '%s'", ctxName)
Expand Down

0 comments on commit d252456

Please sign in to comment.