diff --git a/api/v1/installation_types.go b/api/v1/installation_types.go index 252337f2ce..7c67dad9fa 100644 --- a/api/v1/installation_types.go +++ b/api/v1/installation_types.go @@ -957,6 +957,14 @@ type CNISpec struct { // +optional // +kubebuilder:validation:Type=string ConfDir *string `json:"confDir,omitempty"` + + // ConfName is the name of the CNI config file. + // If you have changed the name of the CNI configuration file in the container runtime configuration, + // please ensure that this field matches the same name as specified in the container runtime settings. + // Default: "10-calico.conflist" + // +optional + // +kubebuilder:validation:Type=string + ConfName *string `json:"confName,omitempty"` } // InstallationStatus defines the observed state of the Calico or Calico Enterprise installation. diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 069c4d936e..0597bd6266 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -891,6 +891,11 @@ func (in *CNISpec) DeepCopyInto(out *CNISpec) { *out = new(string) **out = **in } + if in.ConfName != nil { + in, out := &in.ConfName, &out.ConfName + *out = new(string) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CNISpec. diff --git a/pkg/controller/installation/core_controller.go b/pkg/controller/installation/core_controller.go index 22cfbc0e5c..d1f24e00fb 100644 --- a/pkg/controller/installation/core_controller.go +++ b/pkg/controller/installation/core_controller.go @@ -636,6 +636,12 @@ func fillDefaults(instance *operatorv1.Installation, currentPools *crdv1.IPPoolL instance.Spec.CNI.BinDir = &defaultCNIBinDir } + // For compatability reasons, default the CNI config name if not specified. + if instance.Spec.CNI.ConfName == nil { + defaultCNIConfName := "10-calico.conflist" + instance.Spec.CNI.ConfName = &defaultCNIConfName + } + // While a number of the fields in this section are relevant to all CNI plugins, // there are some settings which are currently only applicable if using Calico CNI. // Handle those here. diff --git a/pkg/controller/migration/convert/core.go b/pkg/controller/migration/convert/core.go index 83b4bae7e2..161c3bb949 100644 --- a/pkg/controller/migration/convert/core.go +++ b/pkg/controller/migration/convert/core.go @@ -184,7 +184,7 @@ func handleCore(c *components, install *operatorv1.Installation) error { } } - if err := c.node.assertEnv(ctx, c.client, containerInstallCNI, "CNI_CONF_NAME", "10-calico.conflist"); err != nil { + if err := c.node.assertEnv(ctx, c.client, containerInstallCNI, "CNI_CONF_NAME", *install.Spec.CNI.ConfName); err != nil { return err } } diff --git a/pkg/crds/operator/operator.tigera.io_installations.yaml b/pkg/crds/operator/operator.tigera.io_installations.yaml index 83f9ccdf4d..8f73d334db 100644 --- a/pkg/crds/operator/operator.tigera.io_installations.yaml +++ b/pkg/crds/operator/operator.tigera.io_installations.yaml @@ -5410,6 +5410,13 @@ spec: * For KubernetesProvider OpenShift, this field defaults to "/var/run/multus/cni/net.d". * Otherwise, this field defaults to "/etc/cni/net.d". type: string + confName: + description: |- + ConfName is the name of the CNI config file. + If you have changed the name of the CNI configuration file in the container runtime configuration, + please ensure that this field matches the same name as specified in the container runtime settings. + Default: "10-calico.conflist" + type: string ipam: description: |- IPAM specifies the pod IP address management that will be used in the Calico or @@ -14288,6 +14295,13 @@ spec: * For KubernetesProvider OpenShift, this field defaults to "/var/run/multus/cni/net.d". * Otherwise, this field defaults to "/etc/cni/net.d". type: string + confName: + description: |- + ConfName is the name of the CNI config file. + If you have changed the name of the CNI configuration file in the container runtime configuration, + please ensure that this field matches the same name as specified in the container runtime settings. + Default: "10-calico.conflist" + type: string ipam: description: |- IPAM specifies the pod IP address management that will be used in the Calico or diff --git a/pkg/render/node.go b/pkg/render/node.go index 07e705c469..c45e09c470 100644 --- a/pkg/render/node.go +++ b/pkg/render/node.go @@ -1299,7 +1299,7 @@ func (c *nodeComponent) cniEnvvars() []corev1.EnvVar { } envVars := []corev1.EnvVar{ - {Name: "CNI_CONF_NAME", Value: "10-calico.conflist"}, + {Name: "CNI_CONF_NAME", Value: *c.cfg.Installation.CNI.ConfName}, {Name: "SLEEP", Value: "false"}, {Name: "CNI_NET_DIR", Value: *c.cfg.Installation.CNI.ConfDir}, { diff --git a/pkg/render/windows.go b/pkg/render/windows.go index b9e936575f..12d5294bf3 100644 --- a/pkg/render/windows.go +++ b/pkg/render/windows.go @@ -220,7 +220,7 @@ func (c *windowsComponent) cniEnvVars() []corev1.EnvVar { {Name: "SLEEP", Value: "false"}, {Name: "CNI_PLUGIN_TYPE", Value: string(c.cfg.Installation.CNI.Type)}, {Name: "CNI_BIN_DIR", Value: "/host/opt/cni/bin"}, - {Name: "CNI_CONF_NAME", Value: "10-calico.conflist"}, + {Name: "CNI_CONF_NAME", Value: *c.cfg.Installation.CNI.ConfName}, {Name: "CNI_NET_DIR", Value: cniNetDir}, {Name: "KUBERNETES_DNS_SERVERS", Value: strings.Join(c.cfg.K8sDNSServers, ",")}, {Name: "KUBERNETES_SERVICE_CIDRS", Value: strings.Join(c.cfg.Installation.ServiceCIDRs, ",")}, @@ -415,7 +415,7 @@ func (c *windowsComponent) uninstallEnvVars() []corev1.EnvVar { {Name: "SLEEP", Value: "false"}, {Name: "CNI_PLUGIN_TYPE", Value: string(c.cfg.Installation.CNI.Type)}, {Name: "CNI_BIN_DIR", Value: "/host/opt/cni/bin"}, - {Name: "CNI_CONF_NAME", Value: "10-calico.conflist"}, + {Name: "CNI_CONF_NAME", Value: *c.cfg.Installation.CNI.ConfName}, {Name: "CNI_NET_DIR", Value: "/host/etc/cni/net.d"}, }