Skip to content

Commit 7fdfcd1

Browse files
author
priyawadhwa
authored
Merge pull request #10433 from BLasan/issue-10156
Add image repository respected for calico
2 parents 3512e88 + 7a7439c commit 7fdfcd1

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

pkg/minikube/bootstrapper/images/images.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,19 @@ func KindNet(repo string) string {
147147
}
148148
return path.Join(repo, "kindnetd:0.5.4")
149149
}
150+
151+
// CalicoDaemonSet returns the image used for calicoDaemonSet
152+
func CalicoDaemonSet(repo string) string {
153+
if repo == "" {
154+
repo = "calico"
155+
}
156+
return path.Join(repo, "node:v3.14.1")
157+
}
158+
159+
// CalicoDeployment returns the image used for calicoDeployment
160+
func CalicoDeployment(repo string) string {
161+
if repo == "" {
162+
repo = "calico"
163+
}
164+
return path.Join(repo, "kube-controllers:v3.14.1")
165+
}

pkg/minikube/cni/calico.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ limitations under the License.
1717
package cni
1818

1919
import (
20+
"bytes"
21+
"text/template"
22+
23+
"github.com/pkg/errors"
24+
"k8s.io/minikube/pkg/minikube/assets"
25+
"k8s.io/minikube/pkg/minikube/bootstrapper/images"
2026
"k8s.io/minikube/pkg/minikube/config"
2127
)
2228

2329
// calicoTmpl is from https://docs.projectcalico.org/manifests/calico.yaml
24-
var calicoTmpl = `---
30+
var calicoTmpl = template.Must(template.New("calico").Parse(`---
2531
# Source: calico/templates/calico-config.yaml
2632
# This ConfigMap is used to configure a self-hosted Calico installation.
2733
kind: ConfigMap
@@ -649,7 +655,7 @@ spec:
649655
# container programs network policy and routes on each
650656
# host.
651657
- name: calico-node
652-
image: calico/node:v3.14.1
658+
image: {{ .DaemonSetImageName }}
653659
env:
654660
# Use Kubernetes API as the backing datastore.
655661
- name: DATASTORE_TYPE
@@ -834,7 +840,7 @@ spec:
834840
priorityClassName: system-cluster-critical
835841
containers:
836842
- name: calico-kube-controllers
837-
image: calico/kube-controllers:v3.14.1
843+
image: {{ .DeploymentImageName }}
838844
env:
839845
# Choose which controllers to run.
840846
- name: ENABLED_CONTROLLERS
@@ -864,21 +870,44 @@ metadata:
864870
---
865871
# Source: calico/templates/configure-canal.yaml
866872
867-
`
873+
`))
868874

869875
// Calico is the Calico CNI manager
870876
type Calico struct {
871877
cc config.ClusterConfig
872878
}
873879

880+
type calicoTmplStruct struct {
881+
DeploymentImageName string
882+
DaemonSetImageName string
883+
}
884+
874885
// String returns a string representation of this CNI
875886
func (c Calico) String() string {
876887
return "Calico"
877888
}
878889

890+
// manifest returns a Kubernetes manifest for a CNI
891+
func (c Calico) manifest() (assets.CopyableFile, error) {
892+
input := &calicoTmplStruct{
893+
DeploymentImageName: images.CalicoDeployment(c.cc.KubernetesConfig.ImageRepository),
894+
DaemonSetImageName: images.CalicoDaemonSet(c.cc.KubernetesConfig.ImageRepository),
895+
}
896+
897+
b := bytes.Buffer{}
898+
if err := calicoTmpl.Execute(&b, input); err != nil {
899+
return nil, err
900+
}
901+
return manifestAsset(b.Bytes()), nil
902+
}
903+
879904
// Apply enables the CNI
880905
func (c Calico) Apply(r Runner) error {
881-
return applyManifest(c.cc, r, manifestAsset([]byte(calicoTmpl)))
906+
m, err := c.manifest()
907+
if err != nil {
908+
return errors.Wrap(err, "manifest")
909+
}
910+
return applyManifest(c.cc, r, m)
882911
}
883912

884913
// CIDR returns the default CIDR used by this CNI

0 commit comments

Comments
 (0)