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

Improve reliability of cluster role binding creation for containerd/cri-o #7705

Merged
merged 8 commits into from
Apr 16, 2020
Merged
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
40 changes: 30 additions & 10 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/docker/machine/libmachine/state"
"github.com/golang/glog"
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/client-go/kubernetes"
kconst "k8s.io/kubernetes/cmd/kubeadm/app/constants"
"k8s.io/minikube/pkg/drivers/kic"
Expand Down Expand Up @@ -202,9 +203,13 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
}

var wg sync.WaitGroup
wg.Add(4)
wg.Add(3)

go func() {
// we need to have cluster role binding before applying overlay to avoid #7428
if err := k.elevateKubeSystemPrivileges(cfg); err != nil {
glog.Errorf("unable to create cluster role binding, some addons might not work: %v", err)
}
// the overlay is required for containerd and cri-o runtime: see #7428
if driver.IsKIC(cfg.Driver) && cfg.KubernetesConfig.ContainerRuntime != "docker" {
if err := k.applyKICOverlay(cfg); err != nil {
Expand All @@ -228,13 +233,6 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error {
wg.Done()
}()

go func() {
if err := k.elevateKubeSystemPrivileges(cfg); err != nil {
glog.Warningf("unable to create cluster role binding, some addons might not work: %v", err)
}
wg.Done()
}()

wg.Wait()
return nil
}
Expand Down Expand Up @@ -820,6 +818,10 @@ func (k *Bootstrapper) applyNodeLabels(cfg config.ClusterConfig) error {
// elevateKubeSystemPrivileges gives the kube-system service account cluster admin privileges to work with RBAC.
func (k *Bootstrapper) elevateKubeSystemPrivileges(cfg config.ClusterConfig) error {
start := time.Now()
defer func() {
glog.Infof("duration metric: took %s to wait for elevateKubeSystemPrivileges.", time.Since(start))
}()

// Allow no more than 5 seconds for creating cluster role bindings
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand All @@ -836,6 +838,24 @@ func (k *Bootstrapper) elevateKubeSystemPrivileges(cfg config.ClusterConfig) err
return nil
}
}
glog.Infof("duration metric: took %s to wait for elevateKubeSystemPrivileges.", time.Since(start))
return err

if cfg.VerifyComponents[kverify.DefaultSAWaitKey] {
// double checking defalut sa was created.
// good for ensuring using minikube in CI is robust.
checkSA := func() (bool, error) {
cmd = exec.Command("sudo", kubectlPath(cfg),
"get", "sa", "default", fmt.Sprintf("--kubeconfig=%s", path.Join(vmpath.GuestPersistentDir, "kubeconfig")))
rr, err = k.c.RunCmd(cmd)
if err != nil {
return false, nil
}
return true, nil
}

// retry up to make sure SA is created
if err := wait.PollImmediate(kconst.APICallRetryInterval, time.Minute, checkSA); err != nil {
return errors.Wrap(err, "ensure sa was created")
}
}
return nil
}