Merge pull request #8697 from medyagh/improv_sa_apply

improve applying default service account
pull/8806/head
Medya Ghazizadeh 2020-07-22 11:00:07 -07:00 committed by GitHub
commit f2100e365d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 2 deletions

View File

@ -864,7 +864,7 @@ func (k *Bootstrapper) elevateKubeSystemPrivileges(cfg config.ClusterConfig) err
}()
// Allow no more than 5 seconds for creating cluster role bindings
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), applyTimeoutSeconds*time.Second)
defer cancel()
rbacName := "minikube-rbac"
// kubectl create clusterrolebinding minikube-rbac --clusterrole=cluster-admin --serviceaccount=kube-system:default
@ -873,10 +873,14 @@ func (k *Bootstrapper) elevateKubeSystemPrivileges(cfg config.ClusterConfig) err
fmt.Sprintf("--kubeconfig=%s", path.Join(vmpath.GuestPersistentDir, "kubeconfig")))
rr, err := k.c.RunCmd(cmd)
if err != nil {
if ctx.Err() == context.DeadlineExceeded {
return errors.Wrapf(err, "timeout apply sa")
}
// Error from server (AlreadyExists): clusterrolebindings.rbac.authorization.k8s.io "minikube-rbac" already exists
if strings.Contains(rr.Output(), "Error from server (AlreadyExists)") {
glog.Infof("rbac %q already exists not need to re-create.", rbacName)
return nil
} else {
return errors.Wrapf(err, "apply sa")
}
}