diff --git a/cmd/minikube/cmd/config/profile.go b/cmd/minikube/cmd/config/profile.go index 9dd9b4e6efa778fb6daaa6d9bee559f25189a384..770e5f6bf25de9222e262a47da320f45ea73125d 100644 --- a/cmd/minikube/cmd/config/profile.go +++ b/cmd/minikube/cmd/config/profile.go @@ -53,16 +53,19 @@ var ProfileCmd = &cobra.Command{ exit.WithError("Setting profile failed", err) } cc, err := pkgConfig.Load() + // might err when loading older version of cfg file that doesn't have KeepContext field if err != nil && !os.IsNotExist(err) { console.ErrLn("Error loading profile config: %v", err) } - if cc.MachineConfig.KeepContext { - console.Success("Skipped switching kubectl context for %s , because --keep-context", profile) - console.Success("To connect to this cluster, use: kubectl --context=%s", profile) - } else { - err := pkgutil.SetCurrentContext(constants.KubeconfigPath, profile) - if err != nil { - console.ErrLn("error while setting kubectl current context : %v", err) + if err == nil { + if cc.MachineConfig.KeepContext { + console.Success("Skipped switching kubectl context for %s , because --keep-context", profile) + console.Success("To connect to this cluster, use: kubectl --context=%s", profile) + } else { + err := pkgutil.SetCurrentContext(constants.KubeconfigPath, profile) + if err != nil { + console.ErrLn("Error while setting kubectl current context : %v", err) + } } } console.Success("minikube profile was successfully set to %s", profile)