From 224221bfcabf6c743ed517c0f3880bd18f1e7efc Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Tue, 12 Nov 2024 09:10:43 +0100 Subject: [PATCH 1/2] fix: fetch image metadata when actually needed --- pkg/testworkflows/testworkflowprocessor/processor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/testworkflows/testworkflowprocessor/processor.go b/pkg/testworkflows/testworkflowprocessor/processor.go index ba5239570b..1a0d460a69 100644 --- a/pkg/testworkflows/testworkflowprocessor/processor.go +++ b/pkg/testworkflows/testworkflowprocessor/processor.go @@ -212,7 +212,7 @@ func (p *processor) Bundle(ctx context.Context, workflow *testworkflowsv1.TestWo // Load the image details when necessary hasPodSecurityContextGroup := podConfig.SecurityContext != nil && podConfig.SecurityContext.RunAsGroup != nil - imageNames := root.GetImages(hasPodSecurityContextGroup) + imageNames := root.GetImages(!hasPodSecurityContextGroup) images := make(map[string]*imageinspector.Info) imageNameResolutions := map[string]string{} for image, needsMetadata := range imageNames { From fcaf3930e7b52b5560f6aa45c811b54eca25153c Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Tue, 12 Nov 2024 09:11:35 +0100 Subject: [PATCH 2/2] fix: try to obtain image specific for current platform in Crane fetcher --- pkg/imageinspector/cranefetcher.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/imageinspector/cranefetcher.go b/pkg/imageinspector/cranefetcher.go index d15914f64a..f7beef94eb 100644 --- a/pkg/imageinspector/cranefetcher.go +++ b/pkg/imageinspector/cranefetcher.go @@ -6,12 +6,14 @@ import ( "encoding/json" "fmt" "regexp" + "runtime" "strconv" "strings" "time" "github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/crane" + v1 "github.com/google/go-containerregistry/pkg/v1" corev1 "k8s.io/api/core/v1" "github.com/kubeshop/testkube/pkg/utils" @@ -42,6 +44,7 @@ func (c *craneFetcher) Fetch(ctx context.Context, registry, image string, pullSe } // Select the auth + cranePlatformOption := crane.WithPlatform(&v1.Platform{OS: runtime.GOOS, Architecture: runtime.GOARCH}) craneOptions := []crane.Option{crane.WithContext(ctx)} if len(authConfigs) > 0 { craneOptions = append(craneOptions, crane.WithAuth(authn.FromConfig(authConfigs[0]))) @@ -49,7 +52,13 @@ func (c *craneFetcher) Fetch(ctx context.Context, registry, image string, pullSe // Fetch the image configuration fetchedAt := time.Now() - serializedImageConfig, err := crane.Config(image, craneOptions...) + serializedImageConfig, err := crane.Config(image, append(craneOptions, cranePlatformOption)...) + + // Retry again without specifying platform + if err != nil && (strings.Contains(err.Error(), "no child") || strings.Contains(err.Error(), "not known")) { + serializedImageConfig, err = crane.Config(image, craneOptions...) + } + if err != nil { return nil, err }