Browse code

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 <github@gone.nl>

Sebastiaan van Stijn authored on 2024/06/28 00:29:26
Showing 4 changed files
... ...
@@ -158,7 +158,7 @@ func Register(name string, initFunc InitFunc) error {
158 158
 
159 159
 // GetDriver initializes and returns the registered driver.
160 160
 //
161
-// It is exported for use in (integration-)tests, but should be considered internal.
161
+// Deprecated: this function was exported for (integration-)tests, but no longer used, and will be removed in the next release.
162 162
 func GetDriver(name string, config Options) (Driver, error) {
163 163
 	return getDriver(name, config)
164 164
 }
... ...
@@ -30,11 +30,16 @@ type Driver struct {
30 30
 }
31 31
 
32 32
 func newDriver(t testing.TB, name string, options []string) *Driver {
33
+	if name == "" {
34
+		// Prevent graphdriver.New() from auto-detecting / picking a storage driver.
35
+		t.Fatal("newDriver requires a name for the storage driver to use")
36
+	}
37
+
33 38
 	root, err := os.MkdirTemp("", "docker-graphtest-")
34 39
 	assert.NilError(t, err)
35 40
 
36 41
 	assert.NilError(t, os.MkdirAll(root, 0o755))
37
-	d, err := graphdriver.GetDriver(name, graphdriver.Options{DriverOptions: options, Root: root})
42
+	d, err := graphdriver.New(name, graphdriver.Options{DriverOptions: options, Root: root})
38 43
 	if err != nil {
39 44
 		t.Logf("graphdriver: %v\n", err)
40 45
 		if graphdriver.IsDriverNotSupported(err) {
... ...
@@ -92,7 +92,7 @@ func TestXattrUnsupportedByBackingFS(t *testing.T) {
92 92
 		t.Run(tt.name, func(t *testing.T) {
93 93
 			subdir := filepath.Join(rootdir, tt.name)
94 94
 			assert.NilError(t, os.Mkdir(subdir, 0o755))
95
-			d, err := graphdriver.GetDriver("vfs", graphdriver.Options{
95
+			d, err := graphdriver.New("vfs", graphdriver.Options{
96 96
 				DriverOptions: tt.opts,
97 97
 				Root:          subdir,
98 98
 			})
... ...
@@ -26,7 +26,7 @@ func init() {
26 26
 }
27 27
 
28 28
 func newVFSGraphDriver(td string) (graphdriver.Driver, error) {
29
-	return graphdriver.GetDriver("vfs", graphdriver.Options{
29
+	return graphdriver.New("vfs", graphdriver.Options{
30 30
 		Root: td,
31 31
 		IDMap: idtools.IdentityMapping{
32 32
 			UIDMaps: []idtools.IDMap{{