Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair kubecontext before checking cluster health #9143

Merged
merged 1 commit into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
"k8s.io/minikube/pkg/minikube/constants"
"k8s.io/minikube/pkg/minikube/cruntime"
"k8s.io/minikube/pkg/minikube/driver"
"k8s.io/minikube/pkg/minikube/kubeconfig"
"k8s.io/minikube/pkg/minikube/machine"
"k8s.io/minikube/pkg/minikube/out"
"k8s.io/minikube/pkg/minikube/out/register"
Expand Down Expand Up @@ -538,6 +539,12 @@ func (k *Bootstrapper) restartControlPlane(cfg config.ClusterConfig) error {
return errors.Wrap(err, "control plane")
}

// Save the costly tax of reinstalling Kubernetes if the only issue is a missing kube context
_, err = kubeconfig.UpdateEndpoint(cfg.Name, hostname, port, kubeconfig.PathFromEnv())
if err != nil {
glog.Warningf("unable to update kubeconfig (cluster will likely require a reset): %v", err)
}

client, err := k.client(hostname, port)
if err != nil {
return errors.Wrap(err, "getting k8s client")
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func UpdateEndpoint(contextName string, hostname string, port int, confpath stri

// if the cluster setting is missed in the kubeconfig, create new one
if _, ok := cfg.Clusters[contextName]; !ok {
glog.Infof("%q context is missing from %s - will repair!", contextName, confpath)
lp := localpath.Profile(contextName)
gp := localpath.MiniPath()
kcs := &Settings{
Expand Down