Skip to content

Commit d8c7bc0

Browse files
GrimmiMeloniclaude
andcommitted
Use actual image references from detection in CSV patching
Previously, CSV patching reconstructed image paths using the current branding organization. This broke for collector, which only builds with stackrox-io but would be patched with rhacs-eng when that was the current branding. Now, CSV patching uses the actual image reference from the localImages map that was detected. This handles fallback branding correctly - if collector was detected at quay.io/stackrox-io, that's the exact path used in the CSV. Also updated tests to use quay.io paths instead of localhost paths, matching the removal of localhost support in detection. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent bc376ad commit d8c7bc0

2 files changed

Lines changed: 25 additions & 36 deletions

File tree

internal/deployer/operator.go

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"gopkg.in/yaml.v3"
1717

1818
"github.com/stackrox/roxie/internal/helpers"
19-
"github.com/stackrox/roxie/internal/localimages"
2019
)
2120

2221
const (
@@ -361,11 +360,10 @@ func patchCSVWithLocalImages(csvFile, mainImageTag string, localImages map[strin
361360
}
362361

363362
// Patch operator image if it exists in localImages
364-
// We construct the quay.io path to avoid Kubernetes prepending docker.io/ to localhost/ references
363+
// Use the actual detected image reference to handle fallback branding cases
365364
operatorImageKey := "stackrox-operator:" + mainImageTag
366-
if _, ok := localImages[operatorImageKey]; ok {
367-
brandingOrg := localimages.GetBrandingOrganization()
368-
container["image"] = fmt.Sprintf("quay.io/%s/stackrox-operator:%s", brandingOrg, mainImageTag)
365+
if imageRef, ok := localImages[operatorImageKey]; ok {
366+
container["image"] = imageRef
369367
}
370368

371369
// Patch RELATED_IMAGE_* environment variables
@@ -374,16 +372,14 @@ func patchCSVWithLocalImages(csvFile, mainImageTag string, localImages map[strin
374372
return errors.New("CSV missing container env variables")
375373
}
376374

377-
// Get branding organization for constructing image paths
378-
brandingOrg := localimages.GetBrandingOrganization()
379-
380-
// Build a reverse map from image name to local image refs for quick lookup
381-
imageNameToKey := make(map[string]string)
382-
for imageKey := range localImages {
375+
// Build a reverse map from image name to full image reference for quick lookup
376+
// Map[imagename] -> "quay.io/org/imagename:tag"
377+
imageNameToRef := make(map[string]string)
378+
for imageKey, imageRef := range localImages {
383379
// Extract image name from "imagename:tag"
384380
parts := strings.SplitN(imageKey, ":", 2)
385381
if len(parts) == 2 {
386-
imageNameToKey[parts[0]] = imageKey
382+
imageNameToRef[parts[0]] = imageRef
387383
}
388384
}
389385

@@ -413,17 +409,10 @@ func patchCSVWithLocalImages(csvFile, mainImageTag string, localImages map[strin
413409
imageName = "scanner-v4"
414410
}
415411

416-
// Check if we have this image locally
417-
if imageKey, found := imageNameToKey[imageName]; found {
418-
// Extract the tag from the imageKey
419-
parts := strings.SplitN(imageKey, ":", 2)
420-
if len(parts) != 2 {
421-
continue
422-
}
423-
tag := parts[1]
424-
425-
// Construct quay.io path to avoid Kubernetes prepending docker.io/ to localhost/ references
426-
envMap["value"] = fmt.Sprintf("quay.io/%s/%s:%s", brandingOrg, imageName, tag)
412+
// Check if we have this image locally and use the actual detected reference
413+
// This handles cases where an image was found at a fallback branding org
414+
if imageRef, found := imageNameToRef[imageName]; found {
415+
envMap["value"] = imageRef
427416
}
428417
}
429418

internal/deployer/operator_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ spec:
6969

7070
// Only have scanner-v4 locally (not separate indexer/matcher)
7171
localImages := map[string]string{
72-
"scanner-v4:4.0.0-local": "localhost/stackrox/scanner-v4:4.0.0-local",
72+
"scanner-v4:4.0.0-local": "quay.io/rhacs-eng/scanner-v4:4.0.0-local",
7373
}
7474

7575
err := patchCSVWithLocalImages(csvFile, "4.0.0-local", localImages)
@@ -169,13 +169,13 @@ spec:
169169

170170
// Create local images map with all images
171171
localImages := map[string]string{
172-
"stackrox-operator:4.0.0": "localhost/stackrox/stackrox-operator:4.0.0",
173-
"main:4.0.0": "localhost/stackrox/main:4.0.0",
174-
"scanner:4.0.0": "localhost/stackrox/scanner:4.0.0",
175-
"scanner-db:4.0.0": "localhost/stackrox/scanner-db:4.0.0",
176-
"central-db:4.0.0": "localhost/stackrox/central-db:4.0.0",
177-
"scanner-v4-db:4.0.0": "localhost/stackrox/scanner-v4-db:4.0.0",
178-
"scanner-v4-matcher:4.0.0": "localhost/stackrox/scanner-v4-matcher:4.0.0",
172+
"stackrox-operator:4.0.0": "quay.io/rhacs-eng/stackrox-operator:4.0.0",
173+
"main:4.0.0": "quay.io/rhacs-eng/main:4.0.0",
174+
"scanner:4.0.0": "quay.io/rhacs-eng/scanner:4.0.0",
175+
"scanner-db:4.0.0": "quay.io/rhacs-eng/scanner-db:4.0.0",
176+
"central-db:4.0.0": "quay.io/rhacs-eng/central-db:4.0.0",
177+
"scanner-v4-db:4.0.0": "quay.io/rhacs-eng/scanner-v4-db:4.0.0",
178+
"scanner-v4-matcher:4.0.0": "quay.io/rhacs-eng/scanner-v4-matcher:4.0.0",
179179
}
180180

181181
// Patch the CSV
@@ -274,8 +274,8 @@ spec:
274274

275275
// Only main and scanner are local
276276
localImages := map[string]string{
277-
"main:4.0.0": "localhost/stackrox/main:4.0.0",
278-
"scanner:4.0.0": "localhost/stackrox/scanner:4.0.0",
277+
"main:4.0.0": "quay.io/rhacs-eng/main:4.0.0",
278+
"scanner:4.0.0": "quay.io/rhacs-eng/scanner:4.0.0",
279279
}
280280

281281
err := patchCSVWithLocalImages(csvFile, "4.0.0", localImages)
@@ -419,7 +419,7 @@ func TestPatchCSVWithLocalImages_MalformedCSV(t *testing.T) {
419419
}
420420

421421
localImages := map[string]string{
422-
"main:4.0.0": "localhost/stackrox/main:4.0.0",
422+
"main:4.0.0": "quay.io/rhacs-eng/main:4.0.0",
423423
}
424424

425425
err := patchCSVWithLocalImages(csvFile, "4.0.0", localImages)
@@ -431,7 +431,7 @@ func TestPatchCSVWithLocalImages_MalformedCSV(t *testing.T) {
431431
// TestPatchCSVWithLocalImages_MissingFile tests error handling for missing CSV file
432432
func TestPatchCSVWithLocalImages_MissingFile(t *testing.T) {
433433
localImages := map[string]string{
434-
"main:4.0.0": "localhost/stackrox/main:4.0.0",
434+
"main:4.0.0": "quay.io/rhacs-eng/main:4.0.0",
435435
}
436436

437437
err := patchCSVWithLocalImages("/nonexistent/file.yaml", "4.0.0", localImages)
@@ -484,7 +484,7 @@ spec:
484484
}
485485

486486
localImages := map[string]string{
487-
"main:4.0.0": "localhost/stackrox/main:4.0.0",
487+
"main:4.0.0": "quay.io/rhacs-eng/main:4.0.0",
488488
}
489489

490490
err := patchCSVWithLocalImages(csvFile, "4.0.0", localImages)

0 commit comments

Comments
 (0)