From 8aa2551ce0f5e786f1edfcf2c4383e452ca12044 Mon Sep 17 00:00:00 2001 From: James Jenkins Date: Wed, 5 Apr 2023 11:59:54 -0400 Subject: [PATCH] Move DefaultSnapshotter constants Move the DefaultSnapshotter constants to the defaults package. Fixes issue #8226. Signed-off-by: James Jenkins --- client/client.go | 4 ++-- cmd/ctr/commands/images/mount.go | 3 ++- cmd/ctr/commands/images/usage.go | 3 ++- .../defaults_snapshotter_linux.go | 2 +- .../defaults_snapshotter_unix.go | 2 +- .../defaults_snapshotter_windows.go | 2 +- integration/client/client.go | 3 +-- integration/client/client_test.go | 2 +- integration/client/image_test.go | 13 +++++++------ integration/client/snapshot_test.go | 5 +++-- integration/image_pull_timeout_test.go | 5 +++-- pkg/cri/config/config_unix.go | 4 ++-- pkg/cri/config/config_windows.go | 4 ++-- pkg/transfer/local/pull.go | 4 ++-- pkg/transfer/local/pull_test.go | 6 +++--- plugins/transfer/plugin.go | 4 ++-- 16 files changed, 35 insertions(+), 31 deletions(-) rename client/snapshotter_default_linux.go => defaults/defaults_snapshotter_linux.go (97%) rename client/snapshotter_default_unix.go => defaults/defaults_snapshotter_unix.go (98%) rename client/snapshotter_default_windows.go => defaults/defaults_snapshotter_windows.go (97%) diff --git a/client/client.go b/client/client.go index 036e6e5ac..6c4794935 100644 --- a/client/client.go +++ b/client/client.go @@ -626,7 +626,7 @@ func (c *Client) ContentStore() content.Store { func (c *Client) SnapshotService(snapshotterName string) snapshots.Snapshotter { snapshotterName, err := c.resolveSnapshotterName(context.Background(), snapshotterName) if err != nil { - snapshotterName = DefaultSnapshotter + snapshotterName = defaults.DefaultSnapshotter } if c.snapshotters != nil { return c.snapshotters[snapshotterName] @@ -801,7 +801,7 @@ func (c *Client) resolveSnapshotterName(ctx context.Context, name string) (strin if label != "" { name = label } else { - name = DefaultSnapshotter + name = defaults.DefaultSnapshotter } } diff --git a/cmd/ctr/commands/images/mount.go b/cmd/ctr/commands/images/mount.go index fdd728481..2b5690218 100644 --- a/cmd/ctr/commands/images/mount.go +++ b/cmd/ctr/commands/images/mount.go @@ -22,6 +22,7 @@ import ( containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/cmd/ctr/commands" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/leases" "github.com/containerd/containerd/v2/mount" @@ -69,7 +70,7 @@ When you are done, use the unmount command. snapshotter := context.String("snapshotter") if snapshotter == "" { - snapshotter = containerd.DefaultSnapshotter + snapshotter = defaults.DefaultSnapshotter } ctx, done, err := client.WithLease(ctx, diff --git a/cmd/ctr/commands/images/usage.go b/cmd/ctr/commands/images/usage.go index 0bd7e8ff6..07ecc9cfb 100644 --- a/cmd/ctr/commands/images/usage.go +++ b/cmd/ctr/commands/images/usage.go @@ -23,6 +23,7 @@ import ( containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/cmd/ctr/commands" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/pkg/progress" "github.com/opencontainers/image-spec/identity" @@ -48,7 +49,7 @@ var usageCommand = cli.Command{ snapshotter := context.String("snapshotter") if snapshotter == "" { - snapshotter = containerd.DefaultSnapshotter + snapshotter = defaults.DefaultSnapshotter } img, err := client.ImageService().Get(ctx, ref) diff --git a/client/snapshotter_default_linux.go b/defaults/defaults_snapshotter_linux.go similarity index 97% rename from client/snapshotter_default_linux.go rename to defaults/defaults_snapshotter_linux.go index 5252dc70d..ade194717 100644 --- a/client/snapshotter_default_linux.go +++ b/defaults/defaults_snapshotter_linux.go @@ -14,7 +14,7 @@ limitations under the License. */ -package client +package defaults const ( // DefaultSnapshotter will set the default snapshotter for the platform. diff --git a/client/snapshotter_default_unix.go b/defaults/defaults_snapshotter_unix.go similarity index 98% rename from client/snapshotter_default_unix.go rename to defaults/defaults_snapshotter_unix.go index c50f09f7d..fc8b081ff 100644 --- a/client/snapshotter_default_unix.go +++ b/defaults/defaults_snapshotter_unix.go @@ -16,7 +16,7 @@ limitations under the License. */ -package client +package defaults const ( // DefaultSnapshotter will set the default snapshotter for the platform. diff --git a/client/snapshotter_default_windows.go b/defaults/defaults_snapshotter_windows.go similarity index 97% rename from client/snapshotter_default_windows.go rename to defaults/defaults_snapshotter_windows.go index 260b0fe96..37e5f7574 100644 --- a/client/snapshotter_default_windows.go +++ b/defaults/defaults_snapshotter_windows.go @@ -14,7 +14,7 @@ limitations under the License. */ -package client +package defaults const ( // DefaultSnapshotter will set the default snapshotter for the platform. diff --git a/integration/client/client.go b/integration/client/client.go index f3760deda..d62488379 100644 --- a/integration/client/client.go +++ b/integration/client/client.go @@ -23,7 +23,6 @@ import ( "os" "testing" - containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/namespaces" "github.com/containerd/log/logtest" @@ -37,7 +36,7 @@ const ( var ( address string ctrdStdioFilePath string - testSnapshotter = containerd.DefaultSnapshotter + testSnapshotter = defaults.DefaultSnapshotter ctrd = &daemon{} ) diff --git a/integration/client/client_test.go b/integration/client/client_test.go index 06eed9654..e02137c70 100644 --- a/integration/client/client_test.go +++ b/integration/client/client_test.go @@ -129,7 +129,7 @@ func TestMain(m *testing.M) { "snapshotter": os.Getenv("TEST_SNAPSHOTTER"), }).Info("running tests against containerd") - snapshotter := DefaultSnapshotter + snapshotter := defaults.DefaultSnapshotter if ss := os.Getenv("TEST_SNAPSHOTTER"); ss != "" { snapshotter = ss } diff --git a/integration/client/image_test.go b/integration/client/image_test.go index ccdfa06a9..ab75f2e31 100644 --- a/integration/client/image_test.go +++ b/integration/client/image_test.go @@ -24,6 +24,7 @@ import ( "testing" . "github.com/containerd/containerd/v2/client" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/images" imagelist "github.com/containerd/containerd/v2/integration/images" @@ -57,7 +58,7 @@ func TestImageIsUnpacked(t *testing.T) { } // Check that image is not unpacked - unpacked, err := image.IsUnpacked(ctx, DefaultSnapshotter) + unpacked, err := image.IsUnpacked(ctx, defaults.DefaultSnapshotter) if err != nil { t.Fatal(err) } @@ -66,11 +67,11 @@ func TestImageIsUnpacked(t *testing.T) { } // Check that image is unpacked - err = image.Unpack(ctx, DefaultSnapshotter) + err = image.Unpack(ctx, defaults.DefaultSnapshotter) if err != nil { t.Fatal(err) } - unpacked, err = image.IsUnpacked(ctx, DefaultSnapshotter) + unpacked, err = image.IsUnpacked(ctx, defaults.DefaultSnapshotter) if err != nil { t.Fatal(err) } @@ -218,7 +219,7 @@ func TestImageUsage(t *testing.T) { t.Fatalf("Expected actual usage to equal manifest reported usage of %d: got %d", s3, s) } - err = image.Unpack(ctx, DefaultSnapshotter) + err = image.Unpack(ctx, defaults.DefaultSnapshotter) if err != nil { t.Fatal(err) } @@ -256,12 +257,12 @@ func TestImageSupportedBySnapshotter_Error(t *testing.T) { _, err = client.Pull(ctx, unsupportedImage, WithSchema1Conversion, WithPlatform(platforms.DefaultString()), - WithPullSnapshotter(DefaultSnapshotter), + WithPullSnapshotter(defaults.DefaultSnapshotter), WithPullUnpack, WithUnpackOpts([]UnpackOpt{WithSnapshotterPlatformCheck()}), ) if err == nil { - t.Fatalf("expected unpacking %s for snapshotter %s to fail", unsupportedImage, DefaultSnapshotter) + t.Fatalf("expected unpacking %s for snapshotter %s to fail", unsupportedImage, defaults.DefaultSnapshotter) } } diff --git a/integration/client/snapshot_test.go b/integration/client/snapshot_test.go index 343f9de6e..02457b06d 100644 --- a/integration/client/snapshot_test.go +++ b/integration/client/snapshot_test.go @@ -21,6 +21,7 @@ import ( "testing" . "github.com/containerd/containerd/v2/client" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/snapshots" "github.com/containerd/containerd/v2/snapshots/testsuite" ) @@ -31,7 +32,7 @@ func newSnapshotter(ctx context.Context, root string) (snapshots.Snapshotter, fu return nil, nil, err } - sn := client.SnapshotService(DefaultSnapshotter) + sn := client.SnapshotService(defaults.DefaultSnapshotter) return sn, func() error { // no need to close remote snapshotter @@ -44,5 +45,5 @@ func TestSnapshotterClient(t *testing.T) { t.Skip() } - testsuite.SnapshotterSuite(t, DefaultSnapshotter, newSnapshotter) + testsuite.SnapshotterSuite(t, defaults.DefaultSnapshotter, newSnapshotter) } diff --git a/integration/image_pull_timeout_test.go b/integration/image_pull_timeout_test.go index 31315d501..a1a40447e 100644 --- a/integration/image_pull_timeout_test.go +++ b/integration/image_pull_timeout_test.go @@ -40,6 +40,7 @@ import ( containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/content" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/leases" "github.com/containerd/containerd/v2/namespaces" criconfig "github.com/containerd/containerd/v2/pkg/cri/config" @@ -476,7 +477,7 @@ func initLocalCRIImageService(client *containerd.Client, tmpDir string, registry containerdRootDir := filepath.Join(tmpDir, "root") cfg := criconfig.ImageConfig{ - Snapshotter: containerd.DefaultSnapshotter, + Snapshotter: defaults.DefaultSnapshotter, Registry: registryCfg, ImagePullProgressTimeout: defaultImagePullProgressTimeout.String(), StatsCollectPeriod: 10, @@ -484,7 +485,7 @@ func initLocalCRIImageService(client *containerd.Client, tmpDir string, registry return images.NewService(cfg, &images.CRIImageServiceOptions{ ImageFSPaths: map[string]string{ - containerd.DefaultSnapshotter: containerdRootDir, + defaults.DefaultSnapshotter: containerdRootDir, }, RuntimePlatforms: map[string]images.ImagePlatform{}, Content: client.ContentStore(), diff --git a/pkg/cri/config/config_unix.go b/pkg/cri/config/config_unix.go index 269b0db77..65d5fa53c 100644 --- a/pkg/cri/config/config_unix.go +++ b/pkg/cri/config/config_unix.go @@ -19,14 +19,14 @@ package config import ( - containerd "github.com/containerd/containerd/v2/client" + "github.com/containerd/containerd/v2/defaults" "github.com/pelletier/go-toml/v2" "k8s.io/kubelet/pkg/cri/streaming" ) func DefaultImageConfig() ImageConfig { return ImageConfig{ - Snapshotter: containerd.DefaultSnapshotter, + Snapshotter: defaults.DefaultSnapshotter, DisableSnapshotAnnotations: true, MaxConcurrentDownloads: 3, ImageDecryption: ImageDecryption{ diff --git a/pkg/cri/config/config_windows.go b/pkg/cri/config/config_windows.go index f571a9405..9c2eeac15 100644 --- a/pkg/cri/config/config_windows.go +++ b/pkg/cri/config/config_windows.go @@ -20,13 +20,13 @@ import ( "os" "path/filepath" - containerd "github.com/containerd/containerd/v2/client" + "github.com/containerd/containerd/v2/defaults" "k8s.io/kubelet/pkg/cri/streaming" ) func DefaultImageConfig() ImageConfig { return ImageConfig{ - Snapshotter: containerd.DefaultSnapshotter, + Snapshotter: defaults.DefaultSnapshotter, StatsCollectPeriod: 10, MaxConcurrentDownloads: 3, ImageDecryption: ImageDecryption{ diff --git a/pkg/transfer/local/pull.go b/pkg/transfer/local/pull.go index b80cb73d3..d116dedc7 100644 --- a/pkg/transfer/local/pull.go +++ b/pkg/transfer/local/pull.go @@ -20,8 +20,8 @@ import ( "context" "fmt" - containerd "github.com/containerd/containerd/v2/client" "github.com/containerd/containerd/v2/content" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/images" "github.com/containerd/containerd/v2/pkg/transfer" @@ -286,7 +286,7 @@ 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 == containerd.DefaultSnapshotter { + } else if uc.Snapshotter == "" && sp.SnapshotterKey == defaults.DefaultSnapshotter { return true, sp } } diff --git a/pkg/transfer/local/pull_test.go b/pkg/transfer/local/pull_test.go index 5410ae26c..908d030ab 100644 --- a/pkg/transfer/local/pull_test.go +++ b/pkg/transfer/local/pull_test.go @@ -19,7 +19,7 @@ package local import ( "testing" - containerd "github.com/containerd/containerd/v2/client" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/pkg/transfer" "github.com/containerd/containerd/v2/pkg/unpack" "github.com/containerd/containerd/v2/platforms" @@ -45,7 +45,7 @@ func TestGetSupportedPlatform(t *testing.T) { }, { Platform: platforms.DefaultStrict(), - SnapshotterKey: containerd.DefaultSnapshotter, + SnapshotterKey: defaults.DefaultSnapshotter, }, } @@ -116,7 +116,7 @@ func TestGetSupportedPlatform(t *testing.T) { Match: true, ExpectedPlatform: transfer.UnpackConfiguration{ Platform: platforms.DefaultSpec(), - Snapshotter: containerd.DefaultSnapshotter, + Snapshotter: defaults.DefaultSnapshotter, }, }, } { diff --git a/plugins/transfer/plugin.go b/plugins/transfer/plugin.go index 865698246..fd0aedfa0 100644 --- a/plugins/transfer/plugin.go +++ b/plugins/transfer/plugin.go @@ -19,7 +19,7 @@ package transfer import ( "fmt" - containerd "github.com/containerd/containerd/v2/client" + "github.com/containerd/containerd/v2/defaults" "github.com/containerd/containerd/v2/diff" "github.com/containerd/containerd/v2/errdefs" "github.com/containerd/containerd/v2/leases" @@ -172,7 +172,7 @@ func defaultConfig() *transferConfig { UnpackConfiguration: []unpackConfiguration{ { Platform: platforms.Format(platforms.DefaultSpec()), - Snapshotter: containerd.DefaultSnapshotter, + Snapshotter: defaults.DefaultSnapshotter, }, }, }