Skip to content

Commit 6a750e8

Browse files
UPSTREAM: <carry>: [DefaultCatalogTests]: Moving parse of ENVVAR to the caller (follow-up 345)
1 parent f009adb commit 6a750e8

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

openshift/default-catalog-consistency/pkg/extract/extract.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (r *ExtractedImage) Cleanup() {
3939
}
4040

4141
// UnpackImage pulls the image, extracts it to disk, and opens it as an OCI store.
42-
func UnpackImage(ctx context.Context, imageRef, name string) (res *ExtractedImage, err error) {
42+
func UnpackImage(ctx context.Context, imageRef, name string, sysCtx *types.SystemContext) (res *ExtractedImage, err error) {
4343
tmpDir, err := os.MkdirTemp("", fmt.Sprintf("oci-%s-", name))
4444
if err != nil {
4545
return nil, fmt.Errorf("create temp dir: %w", err)
@@ -53,27 +53,6 @@ func UnpackImage(ctx context.Context, imageRef, name string) (res *ExtractedImag
5353
return nil, fmt.Errorf("parse image ref: %w", err)
5454
}
5555

56-
// Force image resolution to Linux to avoid OS mismatch errors on macOS,
57-
// like: "no image found for architecture 'arm64', OS 'darwin'".
58-
//
59-
// Setting OSChoice = "linux" ensures we always get a Linux image,
60-
// even when running on macOS.
61-
//
62-
// This skips the full multi-arch index and gives us just one manifest.
63-
// To check all supported architectures (e.g., amd64, arm64, ppc64le, s390x),
64-
// we’d need to avoid setting OSChoice and inspect the full index manually.
65-
//
66-
// TODO: Update this to support checking all architectures.
67-
// See: https://issues.redhat.com/browse/OPRUN-3793
68-
sysCtx := &types.SystemContext{
69-
OSChoice: "linux",
70-
}
71-
72-
if authPath := os.Getenv("REGISTRY_AUTH_FILE"); authPath != "" {
73-
fmt.Println("Using registry auth file:", authPath)
74-
sysCtx.AuthFilePath = authPath
75-
}
76-
7756
policyCtx, err := loadPolicyContext(sysCtx, imageRef)
7857
if err != nil {
7958
return nil, fmt.Errorf("create policy context: %w", err)

openshift/default-catalog-consistency/test/validate/suite_test.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package validate
33
import (
44
"context"
55
"fmt"
6+
"github.com/containers/image/v5/types"
7+
"os"
8+
"runtime"
69
"testing"
710

811
. "github.com/onsi/ginkgo/v2"
@@ -23,6 +26,34 @@ var _ = Describe("Check Catalog Consistency", func() {
2326
images, err := utils.ParseImageRefsFromCatalog(catalogsPath)
2427
Expect(err).ToNot(HaveOccurred())
2528
Expect(images).ToNot(BeEmpty(), "no images found")
29+
authPath := os.Getenv("REGISTRY_AUTH_FILE")
30+
osChoice := os.Getenv("OS_CHOICE")
31+
32+
sysCtx := &types.SystemContext{}
33+
if authPath != "" {
34+
fmt.Println("Using registry auth file:", authPath)
35+
sysCtx.AuthFilePath = authPath
36+
}
37+
38+
// Force image resolution to Linux to avoid OS mismatch errors on macOS,
39+
// like: "no image found for architecture 'arm64', OS 'darwin'".
40+
//
41+
// Setting OSChoice = "linux" ensures we always get a Linux image,
42+
// even when running on macOS.
43+
//
44+
// This skips the full multi-arch index and gives us just one manifest.
45+
// To check all supported architectures (e.g., amd64, arm64, ppc64le, s390x),
46+
// we’d need to avoid setting OSChoice and inspect the full index manually.
47+
//
48+
// TODO: Update this to support checking all architectures.
49+
// See: https://issues.redhat.com/browse/OPRUN-3793
50+
if osChoice != "" {
51+
fmt.Println("Using OS choice:", osChoice)
52+
sysCtx.OSChoice = osChoice
53+
} else if runtime.GOOS == "darwin" {
54+
fmt.Println("Detected macOS; forcing OS choice to 'linux'")
55+
sysCtx.OSChoice = "linux"
56+
}
2657

2758
for _, url := range images {
2859
name := utils.ImageNameFromRef(url)
@@ -31,7 +62,7 @@ var _ = Describe("Check Catalog Consistency", func() {
3162
ctx := context.Background()
3263
By(fmt.Sprintf("Validating image: %s", url))
3364

34-
extractedImage, err := extract.UnpackImage(ctx, url, name)
65+
extractedImage, err := extract.UnpackImage(ctx, url, name, sysCtx)
3566
Expect(err).ToNot(HaveOccurred())
3667
Expect(check.Check(ctx, extractedImage, check.AllChecks())).To(Succeed())
3768
extractedImage.Cleanup()

0 commit comments

Comments
 (0)