Skip to content

Commit

Permalink
Avoid name conflict by using deployment+delimiter+container as the key (
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent committed Mar 31, 2020
1 parent 150e717 commit 5e56c24
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/reconciler/knativeeventing/common/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
var (
// The string to be replaced by the container name
containerNameVariable = "${NAME}"
delimiter = "/"
)

// DeploymentTransform updates the links of images with customized registries for all deployments
Expand Down Expand Up @@ -77,16 +78,19 @@ func updateDeploymentImage(deployment *appsv1.Deployment, registry *eventingv1al
containers := deployment.Spec.Template.Spec.Containers
for index := range containers {
container := &containers[index]
newImage := getNewImage(registry, container.Name)
newImage := getNewImage(registry, container.Name, deployment.Name)
if newImage != "" {
updateContainer(container, newImage, log)
}
}
log.Debugw("Finished updating images", "name", deployment.GetName(), "containers", deployment.Spec.Template.Spec.Containers)
}

func getNewImage(registry *eventingv1alpha1.Registry, containerName string) string {
overrideImage := registry.Override[containerName]
func getNewImage(registry *eventingv1alpha1.Registry, containerName, deploymentName string) string {
overrideImage := registry.Override[deploymentName+delimiter+containerName]
if overrideImage == "" {
overrideImage = registry.Override[containerName]
}
if overrideImage != "" {
return overrideImage
}
Expand Down
73 changes: 73 additions & 0 deletions pkg/reconciler/knativeeventing/common/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,78 @@ var updateDeploymentImageTests = []updateDeploymentImageTest{
registry: eventingv1alpha1.Registry{},
expected: []string{"gcr.io/knative-releases/github.com/knative/eventing/cmd/queue@sha256:1e40c99ff5977daa2d69873fff604c6d09651af1f9ff15aadf8849b3ee77ab45"},
},
{
name: "OverrideWithDeploymentContainer",
containers: []corev1.Container{
{
Name: "container1",
Image: "gcr.io/cmd/queue:test",
},
{
Name: "container2",
Image: "gcr.io/cmd/queue:test",
},
},
registry: eventingv1alpha1.Registry{
Override: map[string]string{
"container1": "new-registry.io/test/path/new-container-1:new-tag",
"container2": "new-registry.io/test/path/new-container-2:new-tag",
"OverrideWithDeploymentContainer/container1": "new-registry.io/test/path/OverrideWithDeploymentContainer/container-1:new-tag",
"OverrideWithDeploymentContainer/container2": "new-registry.io/test/path/OverrideWithDeploymentContainer/container-2:new-tag",
},
},
expected: []string{
"new-registry.io/test/path/OverrideWithDeploymentContainer/container-1:new-tag",
"new-registry.io/test/path/OverrideWithDeploymentContainer/container-2:new-tag",
},
},
{
name: "OverridePartialWithDeploymentContainer",
containers: []corev1.Container{
{
Name: "container1",
Image: "gcr.io/cmd/queue:test",
},
{
Name: "container2",
Image: "gcr.io/cmd/queue:test",
},
},
registry: eventingv1alpha1.Registry{
Override: map[string]string{
"container1": "new-registry.io/test/path/new-container-1:new-tag",
"container2": "new-registry.io/test/path/new-container-2:new-tag",
"OverridePartialWithDeploymentContainer/container1": "new-registry.io/test/path/OverridePartialWithDeploymentContainer/container-1:new-tag",
},
},
expected: []string{
"new-registry.io/test/path/OverridePartialWithDeploymentContainer/container-1:new-tag",
"new-registry.io/test/path/new-container-2:new-tag",
},
},
{
name: "OverrideWithDeploymentName",
containers: []corev1.Container{
{
Name: "container1",
Image: "gcr.io/cmd/queue:test",
},
{
Name: "container2",
Image: "gcr.io/cmd/queue:test",
},
},
registry: eventingv1alpha1.Registry{
Override: map[string]string{
"OverrideWithDeploymentName/container1": "new-registry.io/test/path/OverrideWithDeploymentName/container-1:new-tag",
"OverrideWithDeploymentName/container2": "new-registry.io/test/path/OverrideWithDeploymentName/container-2:new-tag",
},
},
expected: []string{
"new-registry.io/test/path/OverrideWithDeploymentName/container-1:new-tag",
"new-registry.io/test/path/OverrideWithDeploymentName/container-2:new-tag",
},
},
}

func TestDeploymentTransform(t *testing.T) {
Expand All @@ -116,6 +188,7 @@ func TestDeploymentTransform(t *testing.T) {
})
}
}

func runDeploymentTransformTest(t *testing.T, tt *updateDeploymentImageTest) {
unstructuredDeployment := makeUnstructured(t, makeDeployment(t, tt.name, corev1.PodSpec{Containers: tt.containers}))
instance := &eventingv1alpha1.KnativeEventing{
Expand Down

0 comments on commit 5e56c24

Please sign in to comment.