From 84cabde357a7b35bce100fea66657b3b520b81ce Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 27 Jun 2024 17:29:26 +0200 Subject: [PATCH] daemon/graphdriver: deprecate GetDriver(), and remove its use The exported function was only used in tests, and identical in use when using New with a name provided. Deprecate it, and remove the uses of it in our (integration-)tests. Signed-off-by: Sebastiaan van Stijn --- daemon/graphdriver/driver.go | 2 +- daemon/graphdriver/graphtest/graphtest_unix.go | 7 ++++++- daemon/graphdriver/vfs/vfs_test.go | 2 +- layer/layer_test.go | 2 +- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/daemon/graphdriver/driver.go b/daemon/graphdriver/driver.go index 13cb135b16..67b8270fe7 100644 --- a/daemon/graphdriver/driver.go +++ b/daemon/graphdriver/driver.go @@ -158,7 +158,7 @@ func Register(name string, initFunc InitFunc) error { // GetDriver initializes and returns the registered driver. // -// It is exported for use in (integration-)tests, but should be considered internal. +// Deprecated: this function was exported for (integration-)tests, but no longer used, and will be removed in the next release. func GetDriver(name string, config Options) (Driver, error) { return getDriver(name, config) } diff --git a/daemon/graphdriver/graphtest/graphtest_unix.go b/daemon/graphdriver/graphtest/graphtest_unix.go index bf3b61bf9a..ef389fc583 100644 --- a/daemon/graphdriver/graphtest/graphtest_unix.go +++ b/daemon/graphdriver/graphtest/graphtest_unix.go @@ -30,11 +30,16 @@ type Driver struct { } func newDriver(t testing.TB, name string, options []string) *Driver { + if name == "" { + // Prevent graphdriver.New() from auto-detecting / picking a storage driver. + t.Fatal("newDriver requires a name for the storage driver to use") + } + root, err := os.MkdirTemp("", "docker-graphtest-") assert.NilError(t, err) assert.NilError(t, os.MkdirAll(root, 0o755)) - d, err := graphdriver.GetDriver(name, graphdriver.Options{DriverOptions: options, Root: root}) + d, err := graphdriver.New(name, graphdriver.Options{DriverOptions: options, Root: root}) if err != nil { t.Logf("graphdriver: %v\n", err) if graphdriver.IsDriverNotSupported(err) { diff --git a/daemon/graphdriver/vfs/vfs_test.go b/daemon/graphdriver/vfs/vfs_test.go index 9dc24e4d8e..c01d8c8009 100644 --- a/daemon/graphdriver/vfs/vfs_test.go +++ b/daemon/graphdriver/vfs/vfs_test.go @@ -92,7 +92,7 @@ func TestXattrUnsupportedByBackingFS(t *testing.T) { t.Run(tt.name, func(t *testing.T) { subdir := filepath.Join(rootdir, tt.name) assert.NilError(t, os.Mkdir(subdir, 0o755)) - d, err := graphdriver.GetDriver("vfs", graphdriver.Options{ + d, err := graphdriver.New("vfs", graphdriver.Options{ DriverOptions: tt.opts, Root: subdir, }) diff --git a/layer/layer_test.go b/layer/layer_test.go index d15d61ac98..6464b48183 100644 --- a/layer/layer_test.go +++ b/layer/layer_test.go @@ -26,7 +26,7 @@ func init() { } func newVFSGraphDriver(td string) (graphdriver.Driver, error) { - return graphdriver.GetDriver("vfs", graphdriver.Options{ + return graphdriver.New("vfs", graphdriver.Options{ Root: td, IDMap: idtools.IdentityMapping{ UIDMaps: []idtools.IDMap{{