Skip to content

Commit

Permalink
systemcontext: make selection of ZstdImages configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Aditya R <arajan@redhat.com>
  • Loading branch information
flouthoc committed Jan 13, 2023
1 parent 0a892a4 commit 25f81e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 10 additions & 10 deletions manifest/oci_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (index *OCI1Index) UpdateInstances(updates []ListUpdate) error {
return nil
}

func instanceBetterMatchesPlatforms(manifests []imgspecv1.Descriptor, platformCheck bool, wantedPlatform imgspecv1.Platform) digest.Digest {
func instanceBetterMatchesPlatforms(ctx *types.SystemContext, manifests []imgspecv1.Descriptor, platformCheck bool, wantedPlatform imgspecv1.Platform) digest.Digest {
var matchedDigest digest.Digest
matchedDigest = ""
for _, d := range manifests {
Expand All @@ -97,13 +97,13 @@ func instanceBetterMatchesPlatforms(manifests []imgspecv1.Descriptor, platformCh
if matchedDigest == "" {
matchedDigest = d.Digest
}
// Always give priority to zstd if more than one image
// exists for the same platform.
// TODO: In future this check will be configurable and
// will be relayed via `ctx`.
if _, ok := d.Annotations[OCI1InstanceAnnotationCompressionZSTD]; ok {
matchedDigest = d.Digest
return matchedDigest
if ctx.GivePriorityToZstdImages != types.OptionalBoolFalse {
// Always give priority to zstd if more than one image
// exists for the same platform.
if _, ok := d.Annotations[OCI1InstanceAnnotationCompressionZSTD]; ok {
matchedDigest = d.Digest
return matchedDigest
}
}
}
}
Expand All @@ -119,13 +119,13 @@ func (index *OCI1Index) ChooseInstance(ctx *types.SystemContext) (digest.Digest,
}
var matchedDigest digest.Digest
for _, wantedPlatform := range wantedPlatforms {
matchedDigest = instanceBetterMatchesPlatforms(index.Manifests, true, wantedPlatform)
matchedDigest = instanceBetterMatchesPlatforms(ctx, index.Manifests, true, wantedPlatform)
if matchedDigest != "" {
return matchedDigest, nil
}
}

matchedDigest = instanceBetterMatchesPlatforms(index.Manifests, false, imgspecv1.Platform{})
matchedDigest = instanceBetterMatchesPlatforms(ctx, index.Manifests, false, imgspecv1.Platform{})
if matchedDigest != "" {
return matchedDigest, nil
}
Expand Down
3 changes: 3 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,9 @@ type SystemContext struct {
CompressionFormat *compression.Algorithm
// CompressionLevel specifies what compression level is used
CompressionLevel *int
// Give priority to pulling zstd images if multiple images are present unless explicitly
// configured false.
GivePriorityToZstdImages OptionalBool
}

// ProgressEvent is the type of events a progress reader can produce
Expand Down

0 comments on commit 25f81e7

Please sign in to comment.