From 7a7439c0942c828d175a53bbcb0243429d7038c6 Mon Sep 17 00:00:00 2001 From: BLasan Date: Wed, 10 Feb 2021 17:07:17 +0530 Subject: [PATCH] Add image repository respected for calico --- pkg/minikube/bootstrapper/images/images.go | 16 +++++++++ pkg/minikube/cni/calico.go | 39 +++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/bootstrapper/images/images.go b/pkg/minikube/bootstrapper/images/images.go index 7d5226de0..7b374fdd3 100644 --- a/pkg/minikube/bootstrapper/images/images.go +++ b/pkg/minikube/bootstrapper/images/images.go @@ -147,3 +147,19 @@ func KindNet(repo string) string { } return path.Join(repo, "kindnetd:0.5.4") } + +// CalicoDaemonSet returns the image used for calicoDaemonSet +func CalicoDaemonSet(repo string) string { + if repo == "" { + repo = "calico" + } + return path.Join(repo, "node:v3.14.1") +} + +// CalicoDeployment returns the image used for calicoDeployment +func CalicoDeployment(repo string) string { + if repo == "" { + repo = "calico" + } + return path.Join(repo, "kube-controllers:v3.14.1") +} diff --git a/pkg/minikube/cni/calico.go b/pkg/minikube/cni/calico.go index 5a27050ad..fee66bfd0 100644 --- a/pkg/minikube/cni/calico.go +++ b/pkg/minikube/cni/calico.go @@ -17,11 +17,17 @@ limitations under the License. package cni import ( + "bytes" + "text/template" + + "github.com/pkg/errors" + "k8s.io/minikube/pkg/minikube/assets" + "k8s.io/minikube/pkg/minikube/bootstrapper/images" "k8s.io/minikube/pkg/minikube/config" ) // calicoTmpl is from https://docs.projectcalico.org/manifests/calico.yaml -var calicoTmpl = `--- +var calicoTmpl = template.Must(template.New("calico").Parse(`--- # Source: calico/templates/calico-config.yaml # This ConfigMap is used to configure a self-hosted Calico installation. kind: ConfigMap @@ -649,7 +655,7 @@ spec: # container programs network policy and routes on each # host. - name: calico-node - image: calico/node:v3.14.1 + image: {{ .DaemonSetImageName }} env: # Use Kubernetes API as the backing datastore. - name: DATASTORE_TYPE @@ -834,7 +840,7 @@ spec: priorityClassName: system-cluster-critical containers: - name: calico-kube-controllers - image: calico/kube-controllers:v3.14.1 + image: {{ .DeploymentImageName }} env: # Choose which controllers to run. - name: ENABLED_CONTROLLERS @@ -864,21 +870,44 @@ metadata: --- # Source: calico/templates/configure-canal.yaml -` +`)) // Calico is the Calico CNI manager type Calico struct { cc config.ClusterConfig } +type calicoTmplStruct struct { + DeploymentImageName string + DaemonSetImageName string +} + // String returns a string representation of this CNI func (c Calico) String() string { return "Calico" } +// manifest returns a Kubernetes manifest for a CNI +func (c Calico) manifest() (assets.CopyableFile, error) { + input := &calicoTmplStruct{ + DeploymentImageName: images.CalicoDeployment(c.cc.KubernetesConfig.ImageRepository), + DaemonSetImageName: images.CalicoDaemonSet(c.cc.KubernetesConfig.ImageRepository), + } + + b := bytes.Buffer{} + if err := calicoTmpl.Execute(&b, input); err != nil { + return nil, err + } + return manifestAsset(b.Bytes()), nil +} + // Apply enables the CNI func (c Calico) Apply(r Runner) error { - return applyManifest(c.cc, r, manifestAsset([]byte(calicoTmpl))) + m, err := c.manifest() + if err != nil { + return errors.Wrap(err, "manifest") + } + return applyManifest(c.cc, r, m) } // CIDR returns the default CIDR used by this CNI -- GitLab