From 80d4ae529a6ef278b0374bd8ebd34dc5bb3cfde1 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 9 Apr 2020 22:41:00 -0700 Subject: [PATCH 1/3] Restart crio after applying the kic overlay (in background) --- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 34 ++++++++++++++------ 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index b97707a5cf98..ddfd8f029256 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -212,15 +212,18 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error { return errors.Wrap(err, "run") } - // this is required for containerd and cri-o runtime. till we close https://github.com/kubernetes/minikube/issues/7428 - if driver.IsKIC(cfg.Driver) && cfg.KubernetesConfig.ContainerRuntime != "docker" { - if err := k.applyKicOverlay(cfg); err != nil { - return errors.Wrap(err, "apply kic overlay") - } - } - var wg sync.WaitGroup - wg.Add(3) + wg.Add(4) + + go func() { + // this is required for containerd and cri-o runtime. till we close https://github.com/kubernetes/minikube/issues/7428 + if driver.IsKIC(cfg.Driver) && cfg.KubernetesConfig.ContainerRuntime != "docker" { + if err := k.applyKicOverlay(cfg); err != nil { + glog.Errorf("failed to apply kic overlay: %v", err) + } + } + wg.Done() + }() go func() { if err := k.applyNodeLabels(cfg); err != nil { @@ -242,6 +245,7 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error { } wg.Done() }() + wg.Wait() return nil } @@ -762,20 +766,30 @@ func startKubeletIfRequired(runner command.Runner, sm sysinit.Manager) error { // applyKicOverlay applies the CNI plugin needed to make kic work func (k *Bootstrapper) applyKicOverlay(cfg config.ClusterConfig) error { - // Allow no more than 5 seconds for apply kic overlay - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() + cmd := exec.CommandContext(ctx, "sudo", path.Join(vmpath.GuestPersistentDir, "binaries", cfg.KubernetesConfig.KubernetesVersion, "kubectl"), "create", fmt.Sprintf("--kubeconfig=%s", path.Join(vmpath.GuestPersistentDir, "kubeconfig")), "-f", "-") + b := bytes.Buffer{} if err := kicCNIConfig.Execute(&b, struct{ ImageName string }{ImageName: kic.OverlayImage}); err != nil { return err } + cmd.Stdin = bytes.NewReader(b.Bytes()) if rr, err := k.c.RunCmd(cmd); err != nil { return errors.Wrapf(err, "cmd: %s output: %s", rr.Command(), rr.Output()) } + + // CRIO needs to eventually know about CNI changes (#7380) + if cfg.KubernetesConfig.ContainerRuntime == "crio" { + sm := sysinit.New(k.c) + err := sm.Restart("crio") + return errors.Wrap(err, "restart crio") + } + return nil } From 94a1e87f13e0bce1b42d8cafd802fa6a94c2aea2 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 9 Apr 2020 22:43:03 -0700 Subject: [PATCH 2/3] Shorten comment --- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index ddfd8f029256..618437ef1782 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -216,7 +216,7 @@ func (k *Bootstrapper) init(cfg config.ClusterConfig) error { wg.Add(4) go func() { - // this is required for containerd and cri-o runtime. till we close https://github.com/kubernetes/minikube/issues/7428 + // 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 { glog.Errorf("failed to apply kic overlay: %v", err) From fbde33d10d110f9ff3a4628135dc8c51eee1a46b Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 9 Apr 2020 22:44:23 -0700 Subject: [PATCH 3/3] simplify --- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 618437ef1782..735032af120c 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -783,11 +783,11 @@ func (k *Bootstrapper) applyKicOverlay(cfg config.ClusterConfig) error { return errors.Wrapf(err, "cmd: %s output: %s", rr.Command(), rr.Output()) } - // CRIO needs to eventually know about CNI changes (#7380) + // Inform cri-o that the CNI has changed if cfg.KubernetesConfig.ContainerRuntime == "crio" { - sm := sysinit.New(k.c) - err := sm.Restart("crio") - return errors.Wrap(err, "restart crio") + if err := sysinit.New(k.c).Restart("crio"); err != nil { + return errors.Wrap(err, "restart crio") + } } return nil