Skip to content

Commit

Permalink
Merge pull request containers#1065 from vrothberg/fix-warnings
Browse files Browse the repository at this point in the history
libimage: tweak platform checks
  • Loading branch information
openshift-merge-robot committed Jun 8, 2022
2 parents 5afa086 + 60ec43e commit dbecabb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 10 additions & 0 deletions libimage/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
"runtime"
)

// PlatformPolicy controls the behavior of image-platform matching.
type PlatformPolicy int

const (
// Only debug log if an image does not match the expected platform.
PlatformPolicyDefault PlatformPolicy = iota
// Warn if an image does not match the expected platform.
PlatformPolicyWarn
)

func toPlatformString(architecture, os, variant string) string {
if variant == "" {
return fmt.Sprintf("%s/%s", os, architecture)
Expand Down
17 changes: 16 additions & 1 deletion libimage/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ type LookupImageOptions struct {
// Lookup an image matching the specified variant.
Variant string

// Controls the behavior when checking the platform of an image.
PlatformPolicy PlatformPolicy

// If set, do not look for items/instances in the manifest list that
// match the current platform but return the manifest list as is.
// only check for manifest list, return ErrNotAManifestList if not found.
Expand Down Expand Up @@ -383,6 +386,13 @@ func (r *Runtime) lookupImageInLocalStorage(name, candidate string, options *Loo
// the store is and which driver (options) are used.
logrus.Debugf("Found image %q as %q in local containers storage (%s)", name, candidate, ref.StringWithinTransport())

// Do not perform any further platform checks if the image was
// requested by ID. In that case, we must assume that the user/tool
// know what they're doing.
if strings.HasPrefix(image.ID(), candidate) {
return image, nil
}

// Ignore the (fatal) error since the image may be corrupted, which
// will bubble up at other places. During lookup, we just return it as
// is.
Expand All @@ -393,7 +403,12 @@ func (r *Runtime) lookupImageInLocalStorage(name, candidate string, options *Loo
// platform and the located image does not match.
return nil, nil
}
logrus.Warnf("%v", matchError)
switch options.PlatformPolicy {
case PlatformPolicyDefault:
logrus.Debugf("%v", matchError)
case PlatformPolicyWarn:
logrus.Warnf("%v", matchError)
}
}

return image, nil
Expand Down

0 comments on commit dbecabb

Please sign in to comment.