Skip to content
Closed
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
2 changes: 1 addition & 1 deletion api/v1alpha2/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
19 changes: 15 additions & 4 deletions internal/controller/component_customizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions internal/controller/component_customizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}

Expand Down
Loading