diff --git a/api/v1alpha2/provider_types.go b/api/v1alpha2/provider_types.go index 4fb8c53eb..2fe8d02be 100644 --- a/api/v1alpha2/provider_types.go +++ b/api/v1alpha2/provider_types.go @@ -184,7 +184,7 @@ type ContainerSpec struct { // Name of the container. Cannot be updated. Name string `json:"name"` - // Container Image URL + // Container Image URL. If container is "manager" and version is not specified, it will be set to the provider version. // +optional ImageURL *string `json:"imageUrl,omitempty"` diff --git a/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml index 100e9ad78..49db0a623 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_addonproviders.yaml @@ -1101,7 +1101,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -2514,7 +2516,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. diff --git a/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml index cf497674f..8e767227c 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_bootstrapproviders.yaml @@ -2686,7 +2686,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -4099,7 +4101,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. diff --git a/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml index 6b2d3cbc0..354806a3b 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_controlplaneproviders.yaml @@ -2688,7 +2688,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -4101,7 +4103,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. diff --git a/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml index 6064e9f55..5e2915ab4 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml @@ -2686,7 +2686,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -4099,7 +4101,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. diff --git a/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml index 089463a1c..19aa45132 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_infrastructureproviders.yaml @@ -2688,7 +2688,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -4101,7 +4103,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. diff --git a/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml index aaa6fa997..b21430689 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml @@ -1101,7 +1101,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -2514,7 +2516,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. diff --git a/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml b/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml index dc044229f..9b80ee0e8 100644 --- a/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml +++ b/config/crd/bases/operator.cluster.x-k8s.io_runtimeextensionproviders.yaml @@ -1103,7 +1103,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -2516,7 +2518,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. diff --git a/internal/controller/component_customizer.go b/internal/controller/component_customizer.go index d714282f4..a008b6097 100644 --- a/internal/controller/component_customizer.go +++ b/internal/controller/component_customizer.go @@ -82,6 +82,7 @@ func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstruc providerDeployment := provider.GetSpec().Deployment providerManager := provider.GetSpec().Manager + providerVersion := provider.GetSpec().Version // If there are multiple deployments, check if we specify customizations for those deployments. // We need to skip the deployment customization if there are several deployments available @@ -107,7 +108,7 @@ func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstruc providerManager = additionalProviderCustomization.Manager } - if err := customizeDeployment(providerDeployment, providerManager, d); err != nil { + if err := customizeDeployment(providerDeployment, providerManager, d, providerVersion); err != nil { return nil, err } @@ -124,7 +125,7 @@ func customizeObjectsFn(provider operatorv1.GenericProvider) func(objs []unstruc } // customizeDeployment customize provider deployment base on provider spec input. -func customizeDeployment(dSpec *operatorv1.DeploymentSpec, mSpec *operatorv1.ManagerSpec, d *appsv1.Deployment) error { +func customizeDeployment(dSpec *operatorv1.DeploymentSpec, mSpec *operatorv1.ManagerSpec, d *appsv1.Deployment, providerVersion string) error { // Customize deployment spec first. if dSpec != nil { customizeDeploymentSpec(*dSpec, d) @@ -137,7 +138,7 @@ func customizeDeployment(dSpec *operatorv1.DeploymentSpec, mSpec *operatorv1.Man return fmt.Errorf("cannot find %q container in deployment %q", managerContainerName, d.Name) } - customizeManagerContainer(mSpec, container) + customizeManagerContainer(mSpec, container, providerVersion) } return nil @@ -183,7 +184,9 @@ func findManagerContainer(dSpec *appsv1.DeploymentSpec) *corev1.Container { } // customizeManagerContainer customize manager container base on provider spec input. -func customizeManagerContainer(mSpec *operatorv1.ManagerSpec, c *corev1.Container) { +func customizeManagerContainer(mSpec *operatorv1.ManagerSpec, c *corev1.Container, providerVersion string) { + c.Image = addImageVersionIfMissing(c.Image, providerVersion) + // ControllerManagerConfigurationSpec fields if mSpec.Controller != nil { // TODO can't find an arg for CacheSyncTimeout @@ -378,3 +381,11 @@ func isMultipleDeployments(objs []unstructured.Unstructured) bool { func isProviderManagerDeploymentName(name string) bool { return strings.HasPrefix(name, "ca") && strings.HasSuffix(name, "-controller-manager") } + +func addImageVersionIfMissing(image, version string) string { + if strings.Contains(image, ":") || strings.Contains(image, "@sha256:") { + return image + } + + return fmt.Sprintf("%s:%s", image, version) +} diff --git a/internal/controller/component_customizer_test.go b/internal/controller/component_customizer_test.go index 17583f65f..575cebaa6 100644 --- a/internal/controller/component_customizer_test.go +++ b/internal/controller/component_customizer_test.go @@ -51,7 +51,7 @@ func TestCustomizeDeployment(t *testing.T) { Spec: corev1.PodSpec{ Containers: []corev1.Container{{ Name: "manager", - Image: "registry.k8s.io/a-manager:1.6.2", + Image: "registry.k8s.io/a-manager", Env: []corev1.EnvVar{ { Name: "test1", @@ -503,7 +503,7 @@ func TestCustomizeDeployment(t *testing.T) { Containers: []corev1.Container{ { Name: "manager", - Image: "registry.k8s.io/a-manager:1.6.2", + Image: "registry.k8s.io/a-manager:v1.6.2", Env: []corev1.EnvVar{ { Name: "test1", @@ -557,7 +557,7 @@ func TestCustomizeDeployment(t *testing.T) { for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { deployment := managerDepl.DeepCopy() - if err := customizeDeployment(tc.inputDeploymentSpec, tc.inputManagerSpec, deployment); err != nil { + if err := customizeDeployment(tc.inputDeploymentSpec, tc.inputManagerSpec, deployment, "v1.6.2"); err != nil { t.Error(err) } diff --git a/test/e2e/resources/full-chart-install.yaml b/test/e2e/resources/full-chart-install.yaml index 1abfe4327..2da34d5b3 100644 --- a/test/e2e/resources/full-chart-install.yaml +++ b/test/e2e/resources/full-chart-install.yaml @@ -1126,7 +1126,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -2539,7 +2541,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. @@ -5721,7 +5725,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -7134,7 +7140,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. @@ -10318,7 +10326,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -11731,7 +11741,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. @@ -14914,7 +14926,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -16327,7 +16341,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. @@ -19511,7 +19527,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -20924,7 +20942,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. @@ -22522,7 +22542,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -23935,7 +23957,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated. @@ -25534,7 +25558,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is + "manager" and version is not specified, it will + be set to the provider version. type: string name: description: Name of the container. Cannot be updated. @@ -26947,7 +26973,9 @@ spec: type: object type: array imageUrl: - description: Container Image URL + description: Container Image URL. If container is "manager" + and version is not specified, it will be set to the provider + version. type: string name: description: Name of the container. Cannot be updated.