Skip to content

Commit 948bd66

Browse files
authored
Merge pull request #11999 from k8s-infra-cherrypick-robot/cherry-pick-11927-to-release/2.1
[release/2.1] Update transfer service supported platforms logic
2 parents a6a7a28 + 3c5ede8 commit 948bd66

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

core/transfer/local/import.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import (
2323

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

26+
"github.com/containerd/errdefs"
27+
"github.com/containerd/log"
28+
2629
"github.com/containerd/containerd/v2/core/content"
2730
"github.com/containerd/containerd/v2/core/images"
2831
"github.com/containerd/containerd/v2/core/transfer"
2932
"github.com/containerd/containerd/v2/core/unpack"
30-
"github.com/containerd/errdefs"
31-
"github.com/containerd/log"
3233
)
3334

3435
func (ts *localTransferService) importStream(ctx context.Context, i transfer.ImageImporter, is transfer.ImageStorer, tops *transfer.Config) error {
@@ -94,7 +95,7 @@ func (ts *localTransferService) importStream(ctx context.Context, i transfer.Ima
9495
if len(unpacks) > 0 {
9596
uopts := []unpack.UnpackerOpt{}
9697
for _, u := range unpacks {
97-
matched, mu := getSupportedPlatform(u, ts.config.UnpackPlatforms)
98+
matched, mu := getSupportedPlatform(ctx, u, ts.config.UnpackPlatforms)
9899
if matched {
99100
uopts = append(uopts, unpack.WithUnpackPlatform(mu))
100101
}

core/transfer/local/pull.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/containerd/errdefs"
2424
"github.com/containerd/log"
25+
"github.com/containerd/platforms"
2526
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2627

2728
"github.com/containerd/containerd/v2/core/content"
@@ -194,12 +195,17 @@ func (ts *localTransferService) pull(ctx context.Context, ir transfer.ImageFetch
194195
enableRemoteSnapshotAnnotations := false
195196
// Only unpack if requested unpackconfig matches default/supported unpackconfigs
196197
for _, u := range unpacks {
197-
matched, mu := getSupportedPlatform(u, ts.config.UnpackPlatforms)
198+
matched, mu := getSupportedPlatform(ctx, u, ts.config.UnpackPlatforms)
198199
if matched {
199200
if v, ok := mu.SnapshotterExports["enable_remote_snapshot_annotations"]; ok && v == "true" {
200201
enableRemoteSnapshotAnnotations = true
201202
}
202203
uopts = append(uopts, unpack.WithUnpackPlatform(mu))
204+
} else {
205+
log.G(ctx).WithFields(log.Fields{
206+
"platform": platforms.FormatAll(u.Platform),
207+
"snapshotter": u.Snapshotter,
208+
}).Warn("Unpack configuration not supported, skipping")
203209
}
204210
}
205211

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

289295
// getSupportedPlatform returns a matched platform comparing input UnpackConfiguration to the supported platform/snapshotter combinations
290296
// If input platform didn't specify snapshotter, default will be used if there is a match on platform.
291-
func getSupportedPlatform(uc transfer.UnpackConfiguration, supportedPlatforms []unpack.Platform) (bool, unpack.Platform) {
292-
var u unpack.Platform
297+
func getSupportedPlatform(ctx context.Context, uc transfer.UnpackConfiguration, supportedPlatforms []unpack.Platform) (matched bool, u unpack.Platform) {
293298
for _, sp := range supportedPlatforms {
294299
// If both platform and snapshotter match, return the supportPlatform
295300
// If platform matched and SnapshotterKey is empty, we assume client didn't pass SnapshotterKey
@@ -298,10 +303,23 @@ func getSupportedPlatform(uc transfer.UnpackConfiguration, supportedPlatforms []
298303
// Assume sp.SnapshotterKey is not empty
299304
if uc.Snapshotter == sp.SnapshotterKey {
300305
return true, sp
301-
} else if uc.Snapshotter == "" && sp.SnapshotterKey == defaults.DefaultSnapshotter {
302-
return true, sp
306+
} else if uc.Snapshotter == "" {
307+
if sp.SnapshotterKey == defaults.DefaultSnapshotter {
308+
// Return as best match immediately
309+
return true, sp
310+
} else if !matched {
311+
// Match but prefer default if present to prevent configuration
312+
// changes from altering default behavior
313+
matched = true
314+
u = sp
315+
}
303316
}
317+
} else if uc.Snapshotter == sp.SnapshotterKey {
318+
log.G(ctx).WithFields(log.Fields{
319+
"platform": platforms.FormatAll(uc.Platform),
320+
"snapshotter": uc.Snapshotter,
321+
}).Info("Found unpack with matching snapshotter but platform does not match")
304322
}
305323
}
306-
return false, u
324+
return
307325
}

core/transfer/local/pull_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
package local
1818

1919
import (
20+
"context"
2021
"testing"
2122

23+
"github.com/containerd/platforms"
24+
2225
"github.com/containerd/containerd/v2/core/transfer"
2326
"github.com/containerd/containerd/v2/core/unpack"
2427
"github.com/containerd/containerd/v2/defaults"
25-
"github.com/containerd/platforms"
2628
)
2729

2830
func TestGetSupportedPlatform(t *testing.T) {
@@ -121,7 +123,7 @@ func TestGetSupportedPlatform(t *testing.T) {
121123
},
122124
} {
123125
t.Run(testCase.Name, func(t *testing.T) {
124-
m, sp := getSupportedPlatform(testCase.UnpackConfig, testCase.SupportedPlatforms)
126+
m, sp := getSupportedPlatform(context.TODO(), testCase.UnpackConfig, testCase.SupportedPlatforms)
125127

126128
// Match result should match expected
127129
if m != testCase.Match {

0 commit comments

Comments
 (0)