Skip to content
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

fix: load image metadata when needed / load platform-specific manifest with Crane fetcher #6018

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading