From 2a39d993ea8349b87a373fadb7ef787bf83f0091 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 25 Jun 2020 14:36:39 -0700 Subject: [PATCH] Address lint comments, remove confusing multi-runner API --- cmd/minikube/cmd/start_flags.go | 4 ++-- pkg/minikube/bootstrapper/kubeadm/kubeadm.go | 2 +- pkg/minikube/cni/bridge.go | 12 ++++++++++-- pkg/minikube/cni/cni.go | 15 ++------------- pkg/minikube/cni/custom.go | 4 ++-- pkg/minikube/cni/disabled.go | 2 +- pkg/minikube/cni/flannel.go | 4 ++-- pkg/minikube/cni/kindnet.go | 4 ++-- pkg/minikube/node/start.go | 2 +- 9 files changed, 23 insertions(+), 26 deletions(-) diff --git a/cmd/minikube/cmd/start_flags.go b/cmd/minikube/cmd/start_flags.go index 4ee4e71ea7..35ff7631ee 100644 --- a/cmd/minikube/cmd/start_flags.go +++ b/cmd/minikube/cmd/start_flags.go @@ -133,8 +133,8 @@ func initMinikubeFlags() { startCmd.Flags().StringArrayVar(&config.AddonList, "addons", nil, "Enable addons. see `minikube addons list` for a list of valid addon names.") startCmd.Flags().String(criSocket, "", "The cri socket path to be used.") startCmd.Flags().String(networkPlugin, "", "Kubelet network plug-in to use (default: auto)") - startCmd.Flags().Bool(enableDefaultCNI, false, "DEPRECATED: Replaced by --cni=custom") - startCmd.Flags().String(cniFlag, "", "CNI plug-in to use. Valid options: auto, calico, custom, flannel, kindnet (default: auto)") + startCmd.Flags().Bool(enableDefaultCNI, false, "DEPRECATED: Replaced by --cni=bridge") + startCmd.Flags().String(cniFlag, "", "CNI plug-in to use. Valid options: auto, bridge, flannel, kindnet, or path to a CNI manifest (default: auto)") startCmd.Flags().StringSlice(waitComponents, kverify.DefaultWaitList, fmt.Sprintf("comma separated list of Kubernetes components to verify and wait for after starting a cluster. defaults to %q, available options: %q . other acceptable values are 'all' or 'none', 'true' and 'false'", strings.Join(kverify.DefaultWaitList, ","), strings.Join(kverify.AllComponentsList, ","))) startCmd.Flags().Duration(waitTimeout, 6*time.Minute, "max time to wait per Kubernetes core services to be healthy.") startCmd.Flags().Bool(nativeSSH, true, "Use native Golang SSH client (default true). Set to 'false' to use the command line 'ssh' command when accessing the docker machine. Useful for the machine drivers when they will not start with 'Waiting for SSH'.") diff --git a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go index 7d5cea08bf..138e7c8cce 100644 --- a/pkg/minikube/bootstrapper/kubeadm/kubeadm.go +++ b/pkg/minikube/bootstrapper/kubeadm/kubeadm.go @@ -277,7 +277,7 @@ func (k *Bootstrapper) applyCNI(cfg config.ClusterConfig) error { out.T(out.CNI, "Configuring {{.name}} (Container Networking Interface) ...", out.V{"name": cnm.String()}) - if err := cnm.Apply(k.c, []cni.Runner{k.c}); err != nil { + if err := cnm.Apply(k.c); err != nil { return errors.Wrap(err, "cni apply") } diff --git a/pkg/minikube/cni/bridge.go b/pkg/minikube/cni/bridge.go index 0340b92fc9..b24025d977 100644 --- a/pkg/minikube/cni/bridge.go +++ b/pkg/minikube/cni/bridge.go @@ -18,6 +18,7 @@ package cni import ( "bytes" + "fmt" "text/template" "github.com/pkg/errors" @@ -68,13 +69,20 @@ func (c Bridge) netconf() (assets.CopyableFile, error) { } // Apply enables the CNI -func (c Bridge) Apply(_ Runner, nodes []Runner) error { +func (c Bridge) Apply(r Runner) error { + if len(c.cc.Nodes) > 1 { + return fmt.Errorf("bridge CNI is incompatible with multi-node clusters") + } + f, err := c.netconf() if err != nil { return errors.Wrap(err, "netconf") } - return applyNetConf(nodes, f) + if err := r.Copy(f); err != nil { + return errors.Wrapf(err, "copy") + } + return nil } // CIDR returns the default CIDR used by this CNI diff --git a/pkg/minikube/cni/cni.go b/pkg/minikube/cni/cni.go index 947ac8d20f..eb54a262e9 100644 --- a/pkg/minikube/cni/cni.go +++ b/pkg/minikube/cni/cni.go @@ -46,8 +46,8 @@ type Runner interface { // Manager is a common interface for CNI type Manager interface { - // Enable enables the CNI - Apply(Runner, []Runner) error + // Apply a CNI. The provided runner is for the control plane + Apply(Runner) error // CIDR returns the default CIDR used by this CNI CIDR() string @@ -147,14 +147,3 @@ func applyManifest(cc config.ClusterConfig, r Runner, f assets.CopyableFile) err return nil } - -// applyNetConf applies a netconf file across nodes -func applyNetConf(rs []Runner, f assets.CopyableFile) error { - for _, r := range rs { - if err := r.Copy(f); err != nil { - return errors.Wrapf(err, "copy") - } - } - - return nil -} diff --git a/pkg/minikube/cni/custom.go b/pkg/minikube/cni/custom.go index a857a55483..6592d513ae 100644 --- a/pkg/minikube/cni/custom.go +++ b/pkg/minikube/cni/custom.go @@ -51,13 +51,13 @@ func NewCustom(cc config.ClusterConfig, manifest string) (Custom, error) { } // Apply enables the CNI -func (c Custom) Apply(master Runner, nodes []Runner) error { +func (c Custom) Apply(r Runner) error { m, err := assets.NewFileAsset(c.manifest, path.Dir(manifestPath()), path.Base(manifestPath()), "0644") if err != nil { return errors.Wrap(err, "manifest") } - return applyManifest(c.cc, master, m) + return applyManifest(c.cc, r, m) } // CIDR returns the default CIDR used by this CNI diff --git a/pkg/minikube/cni/disabled.go b/pkg/minikube/cni/disabled.go index 9eb49d729d..1c46ab40de 100644 --- a/pkg/minikube/cni/disabled.go +++ b/pkg/minikube/cni/disabled.go @@ -33,7 +33,7 @@ func (c Disabled) String() string { } // Apply enables the CNI -func (c Disabled) Apply(master Runner, nodes []Runner) error { +func (c Disabled) Apply(r Runner) error { if driver.IsKIC(c.cc.Driver) && c.cc.KubernetesConfig.ContainerRuntime != "docker" { glog.Warningf("CNI is recommended for %q driver and %q runtime - expect networking issues", c.cc.Driver, c.cc.KubernetesConfig.ContainerRuntime) } diff --git a/pkg/minikube/cni/flannel.go b/pkg/minikube/cni/flannel.go index f8a8cf30fa..4986b4d12e 100644 --- a/pkg/minikube/cni/flannel.go +++ b/pkg/minikube/cni/flannel.go @@ -636,8 +636,8 @@ func (c Flannel) String() string { } // Apply enables the CNI -func (c Flannel) Apply(master Runner, nodes []Runner) error { - return applyManifest(c.cc, master, manifestAsset([]byte(flannelTmpl))) +func (c Flannel) Apply(r Runner) error { + return applyManifest(c.cc, r, manifestAsset([]byte(flannelTmpl))) } // CIDR returns the default CIDR used by this CNI diff --git a/pkg/minikube/cni/kindnet.go b/pkg/minikube/cni/kindnet.go index fc6c178f87..6178c6715f 100644 --- a/pkg/minikube/cni/kindnet.go +++ b/pkg/minikube/cni/kindnet.go @@ -167,12 +167,12 @@ func (c KindNet) manifest() (assets.CopyableFile, error) { } // Apply enables the CNI -func (c KindNet) Apply(master Runner, nodes []Runner) error { +func (c KindNet) Apply(r Runner) error { m, err := c.manifest() if err != nil { return errors.Wrap(err, "manifest") } - return applyManifest(c.cc, master, m) + return applyManifest(c.cc, r, m) } // CIDR returns the default CIDR used by this CNI diff --git a/pkg/minikube/node/start.go b/pkg/minikube/node/start.go index e30e9ee343..6541568c06 100644 --- a/pkg/minikube/node/start.go +++ b/pkg/minikube/node/start.go @@ -191,7 +191,7 @@ func Start(starter Starter, apiServer bool) (*kubeconfig.Settings, error) { return nil, errors.Wrap(err, "cni") } - if err := cnm.Apply(cpr, []cni.Runner{cpr, starter.Runner}); err != nil { + if err := cnm.Apply(cpr); err != nil { return nil, errors.Wrap(err, "cni apply") } }