8000 [release/2.1] Update transfer service supported platforms logic by k8s-infra-cherrypick-robot · Pull Request #11999 · containerd/containerd · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[release/2.1] Update transfer service supported platforms logic #11999

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

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
7 changes: 4 additions & 3 deletions core/transfer/local/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (

ocispec "github.com/opencontainers/image-spec/specs-go/v1"

"github.com/containerd/errdefs"
"github.com/containerd/log"

"github.com/containerd/containerd/v2/core/content"
"github.com/containerd/containerd/v2/core/images"
"github.com/containerd/containerd/v2/core/transfer"
"github.com/containerd/containerd/v2/core/unpack"
"github.com/containerd/errdefs"
"github.com/containerd/log"
)

func (ts *localTransferService) importStream(ctx context.Context, i transfer.ImageImporter, is transfer.ImageStorer, tops *transfer.Config) error {
Expand Down Expand Up @@ -95,7 +96,7 @@ func (ts *localTransferService) importStream(ctx context.Context, i transfer.Ima
if len(unpacks) > 0 {
uopts := []unpack.UnpackerOpt{}
for _, u := range unpacks {
matched, mu := getSupportedPlatform(u, ts.config.UnpackPlatforms)
matched, mu := getSupportedPlatform(ctx, u, ts.config.UnpackPlatforms)
if matched {
uopts = append(uopts, unpack.WithUnpackPlatform(mu))
}
Expand Down
30 changes: 24 additions & 6 deletions core/transfer/local/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/containerd/errdefs"
"github.com/containerd/log"
"github.com/containerd/platforms"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"

"github.com/containerd/containerd/v2/core/content"
Expand Down Expand Up @@ -194,12 +195,17 @@ func (ts *localTransferService) pull(ctx context.Context, ir transfer.ImageFetch
enableRemoteSnapshotAnnotations := false
// Only unpack if requested unpackconfig matches default/supported unpackconfigs
for _, u := range unpacks {
matched, mu := getSupportedPlatform(u, ts.config.UnpackPlatforms)
matched, mu := getSupportedPlatform(ctx, u, ts.config.UnpackPlatforms)
if matched {
if v, ok := mu.SnapshotterExports["enable_remote_snapshot_annotations"]; ok && v == "true" {
enableRemoteSnapshotAnnotations = true
}
uopts = append(uopts, unpack.WithUnpackPlatform(mu))
} else {
log.G(ctx).WithFields(log.Fields{
"platform": platforms.FormatAll(u.Platform),
"snapshotter": u.Snapshotter,
}).Warn("Unpack configuration not supported, skipping")
}
}

Expand Down Expand Up @@ -288,8 +294,7 @@ func fetchHandler(ingester content.Ingester, fetcher remotes.Fetcher, pt *Progre

// getSupportedPlatform returns a matched platform comparing input UnpackConfiguration to the supported platform/snapshotter combinations
// If input platform didn't specify snapshotter, default will be used if there is a match on platform.
func getSupportedPlatform(uc transfer.UnpackConfiguration, supportedPlatforms []unpack.Platform) (bool, unpack.Platform) {
var u unpack.Platform
func getSupportedPlatform(ctx context.Context, uc transfer.UnpackConfiguration, supportedPlatforms []unpack.Platform) (matched bool, u unpack.Platform) {
for _, sp := range supportedPlatforms {
// If both platform and snapshotter match, return the supportPlatform
// If platform matched and SnapshotterKey is empty, we assume client didn't pass SnapshotterKey
Expand All @@ -298,10 +303,23 @@ func getSupportedPlatform(uc transfer.UnpackConfiguration, supportedPlatforms []
// Assume sp.SnapshotterKey is not empty
if uc.Snapshotter == sp.SnapshotterKey {
return true, sp
} else if uc.Snapshotter == "" && sp.SnapshotterKey == defaults.DefaultSnapshotter {
return true, sp
} else if uc.Snapshotter == "" {
if sp.SnapshotterKey == defaults.DefaultSnapshotter {
// Return as best match immediately
return true, sp
} else if !matched {
// Match but prefer default if present to prevent configuration
// changes from altering default behavior
matched = true
u = sp
}
}
} else if uc.Snapshotter == sp.SnapshotterKey {
log.G(ctx).WithFields(log.Fields{
"platform": platforms.FormatAll(uc.Platform),
"snapshotter": uc.Snapshotter,
}).Info("Found unpack with matching snapshotter but platform does not match")
}
}
return false, u
return
}
6 changes: 4 additions & 2 deletions core/transfer/local/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
package local

import (
"context"
"testing"

"github.com/containerd/platforms"

"github.com/containerd/containerd/v2/core/transfer"
"github.com/containerd/containerd/v2/core/unpack"
"github.com/containerd/containerd/v2/defaults"
"github.com/containerd/platforms"
)

func TestGetSupportedPlatform(t *testing.T) {
Expand Down Expand Up @@ -121,7 +123,7 @@ func TestGetSupportedPlatform(t *testing.T) {
},
} {
t.Run(testCase.Name, func(t *testing.T) {
m, sp := getSupportedPlatform(testCase.UnpackConfig, testCase.SupportedPlatforms)
m, sp := getSupportedPlatform(context.TODO(), testCase.UnpackConfig, testCase.SupportedPlatforms)

// Match result should match expected
if m != testCase.Match {
Expand Down
0