@@ -17,11 +17,17 @@ limitations under the License.
17
17
package cni
18
18
19
19
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"
20
26
"k8s.io/minikube/pkg/minikube/config"
21
27
)
22
28
23
29
// calicoTmpl is from https://docs.projectcalico.org/manifests/calico.yaml
24
- var calicoTmpl = `---
30
+ var calicoTmpl = template . Must ( template . New ( "calico" ). Parse ( `---
25
31
# Source: calico/templates/calico-config.yaml
26
32
# This ConfigMap is used to configure a self-hosted Calico installation.
27
33
kind: ConfigMap
@@ -649,7 +655,7 @@ spec:
649
655
# container programs network policy and routes on each
650
656
# host.
651
657
- name: calico-node
652
- image: calico/node:v3.14.1
658
+ image: {{ .DaemonSetImageName }}
653
659
env:
654
660
# Use Kubernetes API as the backing datastore.
655
661
- name: DATASTORE_TYPE
@@ -834,7 +840,7 @@ spec:
834
840
priorityClassName: system-cluster-critical
835
841
containers:
836
842
- name: calico-kube-controllers
837
- image: calico/kube-controllers:v3.14.1
843
+ image: {{ .DeploymentImageName }}
838
844
env:
839
845
# Choose which controllers to run.
840
846
- name: ENABLED_CONTROLLERS
@@ -864,21 +870,44 @@ metadata:
864
870
---
865
871
# Source: calico/templates/configure-canal.yaml
866
872
867
- `
873
+ ` ))
868
874
869
875
// Calico is the Calico CNI manager
870
876
type Calico struct {
871
877
cc config.ClusterConfig
872
878
}
873
879
880
+ type calicoTmplStruct struct {
881
+ DeploymentImageName string
882
+ DaemonSetImageName string
883
+ }
884
+
874
885
// String returns a string representation of this CNI
875
886
func (c Calico ) String () string {
876
887
return "Calico"
877
888
}
878
889
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
+
879
904
// Apply enables the CNI
880
905
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 )
882
911
}
883
912
884
913
// CIDR returns the default CIDR used by this CNI
0 commit comments