From 7cd8751949fe8136d4484d35ed5fc2e45bb939f3 Mon Sep 17 00:00:00 2001 From: Dhruv Gautam Date: Wed, 3 Jun 2026 14:52:49 +0530 Subject: [PATCH] fix(support): sort mirrors per source in OPENSHIFT_IMG_OVERRIDES The prior fix for OCPBUGS-57626 sorted ICSP items by name to ensure deterministic ordering of OPENSHIFT_IMG_OVERRIDES. However, when overlapping mirror definitions exist across multiple IDMS and/or ICSP objects for the same source registry, the mirrors within each source were not sorted. This caused the final OPENSHIFT_IMG_OVERRIDES string to vary between reconciliation cycles, triggering repeated CPO Deployment rollouts. Sort mirrors alphabetically per source in ConvertOpenShiftImageRegistryOverridesToCommandLineFlag() to guarantee a deterministic output regardless of the order mirrors are collected from IDMS/ICSP objects. --- support/util/util.go | 1 + support/util/util_test.go | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/support/util/util.go b/support/util/util.go index 20ba8b2a010..5f3d5e3376a 100644 --- a/support/util/util.go +++ b/support/util/util.go @@ -251,6 +251,7 @@ func ConvertOpenShiftImageRegistryOverridesToCommandLineFlag(registryOverrides m for _, registrySource := range sortedRegistrySources { registryReplacements := registryOverrides[registrySource] + sort.Strings(registryReplacements) for _, registryReplacement := range registryReplacements { commandLineFlagArray = append(commandLineFlagArray, fmt.Sprintf("%s=%s", registrySource, registryReplacement)) } diff --git a/support/util/util_test.go b/support/util/util_test.go index 102e29e8733..da77760dd5f 100644 --- a/support/util/util_test.go +++ b/support/util/util_test.go @@ -142,6 +142,21 @@ func TestConvertOpenShiftImageRegistryOverridesToCommandLineFlag(t *testing.T) { }, expectedFlag: "registry1=mirror1.1,registry1=mirror1.2,registry1=mirror1.3,registry2=mirror2.1,registry2=mirror2.2,registry3=mirror3.1", }, + { + name: "When mirrors are in non-alphabetical order, it should sort them deterministically", + registryOverrides: map[string][]string{ + "cp.icr.io/cp": { + "mirror-c.example.com", + "mirror-a.example.com", + "mirror-b.example.com", + }, + "icr.io/cpopen": { + "mirror-z.example.com", + "mirror-x.example.com", + }, + }, + expectedFlag: "cp.icr.io/cp=mirror-a.example.com,cp.icr.io/cp=mirror-b.example.com,cp.icr.io/cp=mirror-c.example.com,icr.io/cpopen=mirror-x.example.com,icr.io/cpopen=mirror-z.example.com", + }, } t.Parallel()