Skip to content

Add image repository respected for calico #10433

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

Merged
merged 1 commit into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions pkg/minikube/bootstrapper/images/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
39 changes: 34 additions & 5 deletions pkg/minikube/cni/calico.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down