From 81409e9373b242da2e5ac770df412ab669bdc6ea Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Tue, 30 Jan 2024 14:02:02 -0800 Subject: [PATCH 1/2] Add a default differ that matches the snapshotter Signed-off-by: James Sturtevant --- defaults/defaults_snapshotter_windows.go | 1 + plugins/transfer/plugin.go | 10 ++----- plugins/transfer/plugin_defaults_other.go | 33 +++++++++++++++++++++ plugins/transfer/plugin_defaults_windows.go | 32 ++++++++++++++++++++ 4 files changed, 68 insertions(+), 8 deletions(-) create mode 100644 plugins/transfer/plugin_defaults_other.go create mode 100644 plugins/transfer/plugin_defaults_windows.go diff --git a/defaults/defaults_snapshotter_windows.go b/defaults/defaults_snapshotter_windows.go index 37e5f7574..fefe66774 100644 --- a/defaults/defaults_snapshotter_windows.go +++ b/defaults/defaults_snapshotter_windows.go @@ -21,4 +21,5 @@ const ( // This will be based on the client compilation target, so take that into // account when choosing this value. DefaultSnapshotter = "windows" + DefaultDiffer = "windows" ) diff --git a/plugins/transfer/plugin.go b/plugins/transfer/plugin.go index 5737b2936..49842b12a 100644 --- a/plugins/transfer/plugin.go +++ b/plugins/transfer/plugin.go @@ -22,7 +22,6 @@ import ( "github.com/containerd/containerd/v2/core/diff" "github.com/containerd/containerd/v2/core/leases" "github.com/containerd/containerd/v2/core/metadata" - "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/pkg/imageverifier" "github.com/containerd/containerd/v2/pkg/transfer/local" "github.com/containerd/containerd/v2/pkg/unpack" @@ -81,12 +80,7 @@ func init() { // If UnpackConfiguration is not defined, set the default. // If UnpackConfiguration is defined and empty, ignore. if config.UnpackConfiguration == nil { - config.UnpackConfiguration = []unpackConfiguration{ - { - Platform: platforms.Format(platforms.DefaultSpec()), - Snapshotter: defaults.DefaultSnapshotter, - }, - } + config.UnpackConfiguration = defaultUnpackConfig() } for _, uc := range config.UnpackConfiguration { p, err := platforms.Parse(uc.Platform) @@ -122,7 +116,7 @@ func init() { continue } if applier != nil { - log.G(ic.Context).Warnf("multiple differs match for platform, set `differ` option to choose, skipping %q", name) + log.G(ic.Context).Warnf("multiple differs match for platform, set `differ` option to choose, skipping %q", plugin.Registration.ID) continue } inst, err := plugin.Instance() diff --git a/plugins/transfer/plugin_defaults_other.go b/plugins/transfer/plugin_defaults_other.go new file mode 100644 index 000000000..23b948eeb --- /dev/null +++ b/plugins/transfer/plugin_defaults_other.go @@ -0,0 +1,33 @@ +//go:build !windows + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package transfer + +import ( + "github.com/containerd/containerd/v2/defaults" + "github.com/containerd/platforms" +) + +func defaultUnpackConfig() []unpackConfiguration { + return []unpackConfiguration{ + { + Platform: platforms.Format(platforms.DefaultSpec()), + Snapshotter: defaults.DefaultSnapshotter, + }, + } +} diff --git a/plugins/transfer/plugin_defaults_windows.go b/plugins/transfer/plugin_defaults_windows.go new file mode 100644 index 000000000..74946bb4b --- /dev/null +++ b/plugins/transfer/plugin_defaults_windows.go @@ -0,0 +1,32 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package transfer + +import ( + "github.com/containerd/containerd/v2/defaults" + "github.com/containerd/platforms" +) + +func defaultUnpackConfig() []unpackConfiguration { + return []unpackConfiguration{ + { + Platform: platforms.Format(platforms.DefaultSpec()), + Snapshotter: defaults.DefaultSnapshotter, + Differ: defaults.DefaultDiffer, + }, + } +} From f74e5ce7e66b92515f932a7d85c724f0c797850d Mon Sep 17 00:00:00 2001 From: James Sturtevant Date: Wed, 31 Jan 2024 09:44:01 -0800 Subject: [PATCH 2/2] Move differ default to its own file Signed-off-by: James Sturtevant --- defaults/defaults_differ_windows.go | 23 +++++++++++++++++++++++ defaults/defaults_snapshotter_windows.go | 1 - 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 defaults/defaults_differ_windows.go diff --git a/defaults/defaults_differ_windows.go b/defaults/defaults_differ_windows.go new file mode 100644 index 000000000..0762d259e --- /dev/null +++ b/defaults/defaults_differ_windows.go @@ -0,0 +1,23 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package defaults + +const ( + // DefaultDiffer will set the default differ for the platform. + // This differ should be compatible with the windows snapshotter. + DefaultDiffer = "windows" +) diff --git a/defaults/defaults_snapshotter_windows.go b/defaults/defaults_snapshotter_windows.go index fefe66774..37e5f7574 100644 --- a/defaults/defaults_snapshotter_windows.go +++ b/defaults/defaults_snapshotter_windows.go @@ -21,5 +21,4 @@ const ( // This will be based on the client compilation target, so take that into // account when choosing this value. DefaultSnapshotter = "windows" - DefaultDiffer = "windows" )