Skip to content

Commit

Permalink
fix: load image metadata when needed / load platform-specific manifes…
Browse files Browse the repository at this point in the history
…t with Crane fetcher (#6018)

* fix: fetch image metadata when actually needed
* fix: try to obtain image specific for current platform in Crane fetcher
  • Loading branch information
rangoo94 authored Nov 12, 2024
1 parent 8b26e37 commit 6410a5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pkg/imageinspector/cranefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -42,14 +44,21 @@ 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])))
}

// 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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/testworkflows/testworkflowprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 6410a5b

Please sign in to comment.