From c70739d439c438fea615f7fd428b671ee12e4a48 Mon Sep 17 00:00:00 2001 From: Juan Manuel Parrilla Madrid Date: Wed, 11 Sep 2024 15:59:34 +0200 Subject: [PATCH] OCPBUGS-38425: Return the right tagReference on Catalogs ImageStream Signed-off-by: Juan Manuel Parrilla Madrid --- .../hostedcontrolplane/olm/catalogs.go | 4 +- .../hostedcontrolplane/olm/catalogs_test.go | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 control-plane-operator/controllers/hostedcontrolplane/olm/catalogs_test.go diff --git a/control-plane-operator/controllers/hostedcontrolplane/olm/catalogs.go b/control-plane-operator/controllers/hostedcontrolplane/olm/catalogs.go index ff32baef4f..22f18d07c5 100644 --- a/control-plane-operator/controllers/hostedcontrolplane/olm/catalogs.go +++ b/control-plane-operator/controllers/hostedcontrolplane/olm/catalogs.go @@ -110,9 +110,9 @@ func reconcileCatalogDeployment(deployment *appsv1.Deployment, ownerRef config.O } func findTagReference(tags []imagev1.TagReference, name string) *imagev1.TagReference { - for _, tag := range tags { + for i, tag := range tags { if tag.Name == name { - return &tag + return &tags[i] } } return nil diff --git a/control-plane-operator/controllers/hostedcontrolplane/olm/catalogs_test.go b/control-plane-operator/controllers/hostedcontrolplane/olm/catalogs_test.go new file mode 100644 index 0000000000..fcd1841a15 --- /dev/null +++ b/control-plane-operator/controllers/hostedcontrolplane/olm/catalogs_test.go @@ -0,0 +1,54 @@ +package olm + +import ( + "testing" + + . "github.com/onsi/gomega" +) + +func TestGetCatalogToImageWithISImageRegistryOverrides(t *testing.T) { + tests := []struct { + name string + catalogToImage map[string]string + isImageRegistryOverrides map[string][]string + expected map[string]string + }{ + { + name: "No overrides", + catalogToImage: map[string]string{ + "certified-operators": "registry.redhat.io/redhat/certified-operator-index:v4.16", + "community-operators": "registry.redhat.io/redhat/community-operator-index:v4.16", + }, + isImageRegistryOverrides: map[string][]string{}, + expected: map[string]string{ + "certified-operators": "registry.redhat.io/redhat/certified-operator-index:v4.16", + "community-operators": "registry.redhat.io/redhat/community-operator-index:v4.16", + }, + }, + { + name: "Single override and different tag", + catalogToImage: map[string]string{ + "certified-operators": "registry.redhat.io/redhat/certified-operator-index:v4.17", + "community-operators": "registry.redhat.io/redhat/community-operator-index:v4.17", + }, + isImageRegistryOverrides: map[string][]string{ + "registry.redhat.io": {"custom.registry.io"}, + }, + expected: map[string]string{ + "certified-operators": "custom.registry.io/redhat/certified-operator-index:v4.17", + "community-operators": "custom.registry.io/redhat/community-operator-index:v4.17", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + g := NewWithT(t) + result := getCatalogToImageWithISImageRegistryOverrides(tt.catalogToImage, tt.isImageRegistryOverrides) + g.Expect(result).To(Equal(tt.expected), "Expected %d entries, but got %d", len(tt.expected), len(result)) + for key, expectedValue := range tt.expected { + g.Expect(expectedValue).To(Equal(result[key]), "For key %s, expected %s, but got %s", key, expectedValue, result[key]) + } + }) + } +}