-
Notifications
You must be signed in to change notification settings - Fork 567
OCPBUGS-85585: tighten registry override matching to strict longest-prefix across release-image consumers #8509
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
openshift-merge-bot
merged 6 commits into
openshift:main
from
raelga:raelga/fix-cpo-registry-overrides-init-containers
Jun 22, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
543f27f
fix: apply registry overrides to component images in CPO sub-resources
raelga 09e03b1
feat(support/util/registryoverride): add Replace helper with strict p…
raelga 4e0f3f1
fix(support/releaseinfo): tighten registry override matching in Regis…
raelga 7e79111
refactor(imageprovider): deduplicate registry-override logic with the…
raelga d96d751
test(imageprovider): add mutation-safety and idempotency tests for re…
raelga 55b6fda
test(hostedcontrolplane): exercise non-empty registry overrides in co…
raelga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // Package registryoverride applies registry-prefix overrides to image | ||
| // references with strict, deterministic matching semantics. It is intentionally | ||
| // a leaf package with no project-internal imports so it can be used both from | ||
| // support/releaseinfo and from sub-packages that depend on it. | ||
| package registryoverride | ||
|
|
||
| import "strings" | ||
|
|
||
| // Replace remaps an image reference using a set of registry-prefix overrides. | ||
| // The overrides map keys are source registry prefixes and values are | ||
| // replacement prefixes. | ||
| // | ||
| // Matching is strict: an override applies only when the image reference is | ||
| // exactly equal to the source key or starts with the source key followed by a | ||
| // "/" separator. This prevents accidental substring matches (e.g. an override | ||
| // for "quay.io" must not match "quay.io.example.com/foo"). | ||
| // | ||
| // When several override keys match the same image, the longest key wins. This | ||
| // makes the result deterministic regardless of map iteration order and lets | ||
| // callers express both broad ("quay.io") and narrow | ||
| // ("quay.io/openshift-release-dev") overrides simultaneously. | ||
| // | ||
| // If no override matches, image is returned unchanged. | ||
| func Replace(image string, overrides map[string]string) string { | ||
| if image == "" || len(overrides) == 0 { | ||
| return image | ||
| } | ||
|
|
||
| var bestSource, bestTarget string | ||
| for source, target := range overrides { | ||
| if source == "" { | ||
| continue | ||
| } | ||
| if image != source && !strings.HasPrefix(image, source+"/") { | ||
| continue | ||
| } | ||
| if len(source) > len(bestSource) { | ||
| bestSource, bestTarget = source, target | ||
| } | ||
| } | ||
| if bestSource == "" { | ||
| return image | ||
| } | ||
| return bestTarget + image[len(bestSource):] | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.