Browse code

api/types: move MountPoint to api/types/container

This moves the `MountPoint` type to the container package, and
deprecates the old location.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2024/06/26 02:48:09
Showing 11 changed files
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"io"
5 5
 	"os"
6 6
 	"time"
7
+
8
+	"github.com/docker/docker/api/types/mount"
7 9
 )
8 10
 
9 11
 // PruneReport contains the response for Engine API:
... ...
@@ -42,3 +44,47 @@ type StatsResponseReader struct {
42 42
 	Body   io.ReadCloser `json:"body"`
43 43
 	OSType string        `json:"ostype"`
44 44
 }
45
+
46
+// MountPoint represents a mount point configuration inside the container.
47
+// This is used for reporting the mountpoints in use by a container.
48
+type MountPoint struct {
49
+	// Type is the type of mount, see `Type<foo>` definitions in
50
+	// github.com/docker/docker/api/types/mount.Type
51
+	Type mount.Type `json:",omitempty"`
52
+
53
+	// Name is the name reference to the underlying data defined by `Source`
54
+	// e.g., the volume name.
55
+	Name string `json:",omitempty"`
56
+
57
+	// Source is the source location of the mount.
58
+	//
59
+	// For volumes, this contains the storage location of the volume (within
60
+	// `/var/lib/docker/volumes/`). For bind-mounts, and `npipe`, this contains
61
+	// the source (host) part of the bind-mount. For `tmpfs` mount points, this
62
+	// field is empty.
63
+	Source string
64
+
65
+	// Destination is the path relative to the container root (`/`) where the
66
+	// Source is mounted inside the container.
67
+	Destination string
68
+
69
+	// Driver is the volume driver used to create the volume (if it is a volume).
70
+	Driver string `json:",omitempty"`
71
+
72
+	// Mode is a comma separated list of options supplied by the user when
73
+	// creating the bind/volume mount.
74
+	//
75
+	// The default is platform-specific (`"z"` on Linux, empty on Windows).
76
+	Mode string
77
+
78
+	// RW indicates whether the mount is mounted writable (read-write).
79
+	RW bool
80
+
81
+	// Propagation describes how mounts are propagated from the host into the
82
+	// mount point, and vice-versa. Refer to the Linux kernel documentation
83
+	// for details:
84
+	// https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
85
+	//
86
+	// This field is not used on Windows.
87
+	Propagation mount.Propagation
88
+}
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"github.com/docker/docker/api/types/container"
7 7
 	"github.com/docker/docker/api/types/filters"
8 8
 	"github.com/docker/docker/api/types/image"
9
-	"github.com/docker/docker/api/types/mount"
10 9
 	"github.com/docker/docker/api/types/swarm"
11 10
 	"github.com/docker/docker/api/types/volume"
12 11
 )
... ...
@@ -155,7 +154,7 @@ type Container struct {
155 155
 		Annotations map[string]string `json:",omitempty"`
156 156
 	}
157 157
 	NetworkSettings *container.NetworkSettingsSummary
158
-	Mounts          []MountPoint
158
+	Mounts          []container.MountPoint
159 159
 }
160 160
 
161 161
 // Ping contains response of Engine API:
... ...
@@ -251,55 +250,11 @@ type ContainerJSONBase struct {
251 251
 // ContainerJSON is newly used struct along with MountPoint
252 252
 type ContainerJSON struct {
253 253
 	*ContainerJSONBase
254
-	Mounts          []MountPoint
254
+	Mounts          []container.MountPoint
255 255
 	Config          *container.Config
256 256
 	NetworkSettings *container.NetworkSettings
257 257
 }
258 258
 
259
-// MountPoint represents a mount point configuration inside the container.
260
-// This is used for reporting the mountpoints in use by a container.
261
-type MountPoint struct {
262
-	// Type is the type of mount, see `Type<foo>` definitions in
263
-	// github.com/docker/docker/api/types/mount.Type
264
-	Type mount.Type `json:",omitempty"`
265
-
266
-	// Name is the name reference to the underlying data defined by `Source`
267
-	// e.g., the volume name.
268
-	Name string `json:",omitempty"`
269
-
270
-	// Source is the source location of the mount.
271
-	//
272
-	// For volumes, this contains the storage location of the volume (within
273
-	// `/var/lib/docker/volumes/`). For bind-mounts, and `npipe`, this contains
274
-	// the source (host) part of the bind-mount. For `tmpfs` mount points, this
275
-	// field is empty.
276
-	Source string
277
-
278
-	// Destination is the path relative to the container root (`/`) where the
279
-	// Source is mounted inside the container.
280
-	Destination string
281
-
282
-	// Driver is the volume driver used to create the volume (if it is a volume).
283
-	Driver string `json:",omitempty"`
284
-
285
-	// Mode is a comma separated list of options supplied by the user when
286
-	// creating the bind/volume mount.
287
-	//
288
-	// The default is platform-specific (`"z"` on Linux, empty on Windows).
289
-	Mode string
290
-
291
-	// RW indicates whether the mount is mounted writable (read-write).
292
-	RW bool
293
-
294
-	// Propagation describes how mounts are propagated from the host into the
295
-	// mount point, and vice-versa. Refer to the Linux kernel documentation
296
-	// for details:
297
-	// https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
298
-	//
299
-	// This field is not used on Windows.
300
-	Propagation mount.Propagation
301
-}
302
-
303 259
 // DiskUsageObject represents an object type used for disk usage query filtering.
304 260
 type DiskUsageObject string
305 261
 
... ...
@@ -249,3 +249,9 @@ type Health = container.Health
249 249
 //
250 250
 // Deprecated: use [container.HealthcheckResult].
251 251
 type HealthcheckResult = container.HealthcheckResult
252
+
253
+// MountPoint represents a mount point configuration inside the container.
254
+// This is used for reporting the mountpoints in use by a container.
255
+//
256
+// Deprecated: use [container.MountPoint].
257
+type MountPoint = container.MountPoint
... ...
@@ -10,7 +10,6 @@ import (
10 10
 
11 11
 	"github.com/containerd/continuity/fs"
12 12
 	"github.com/containerd/log"
13
-	"github.com/docker/docker/api/types"
14 13
 	containertypes "github.com/docker/docker/api/types/container"
15 14
 	"github.com/docker/docker/api/types/events"
16 15
 	mounttypes "github.com/docker/docker/api/types/mount"
... ...
@@ -432,10 +431,10 @@ func (container *Container) TmpfsMounts() ([]Mount, error) {
432 432
 }
433 433
 
434 434
 // GetMountPoints gives a platform specific transformation to types.MountPoint. Callers must hold a Container lock.
435
-func (container *Container) GetMountPoints() []types.MountPoint {
436
-	mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
435
+func (container *Container) GetMountPoints() []containertypes.MountPoint {
436
+	mountPoints := make([]containertypes.MountPoint, 0, len(container.MountPoints))
437 437
 	for _, m := range container.MountPoints {
438
-		mountPoints = append(mountPoints, types.MountPoint{
438
+		mountPoints = append(mountPoints, containertypes.MountPoint{
439 439
 			Type:        m.Type,
440 440
 			Name:        m.Name,
441 441
 			Source:      m.Path(),
... ...
@@ -6,7 +6,6 @@ import (
6 6
 	"os"
7 7
 	"path/filepath"
8 8
 
9
-	"github.com/docker/docker/api/types"
10 9
 	containertypes "github.com/docker/docker/api/types/container"
11 10
 	"github.com/docker/docker/api/types/events"
12 11
 	swarmtypes "github.com/docker/docker/api/types/swarm"
... ...
@@ -188,10 +187,10 @@ func (container *Container) BuildHostnameFile() error {
188 188
 }
189 189
 
190 190
 // GetMountPoints gives a platform specific transformation to types.MountPoint. Callers must hold a Container lock.
191
-func (container *Container) GetMountPoints() []types.MountPoint {
192
-	mountPoints := make([]types.MountPoint, 0, len(container.MountPoints))
191
+func (container *Container) GetMountPoints() []containertypes.MountPoint {
192
+	mountPoints := make([]containertypes.MountPoint, 0, len(container.MountPoints))
193 193
 	for _, m := range container.MountPoints {
194
-		mountPoints = append(mountPoints, types.MountPoint{
194
+		mountPoints = append(mountPoints, containertypes.MountPoint{
195 195
 			Type:        m.Type,
196 196
 			Name:        m.Name,
197 197
 			Source:      m.Path(),
... ...
@@ -463,7 +463,7 @@ func includeContainerInList(container *container.Snapshot, filter *listContext)
463 463
 	}
464 464
 
465 465
 	if filter.filters.Contains("volume") {
466
-		volumesByName := make(map[string]types.MountPoint)
466
+		volumesByName := make(map[string]containertypes.MountPoint)
467 467
 		for _, m := range container.Mounts {
468 468
 			if m.Name != "" {
469 469
 				volumesByName[m.Name] = m
... ...
@@ -471,7 +471,7 @@ func includeContainerInList(container *container.Snapshot, filter *listContext)
471 471
 				volumesByName[m.Source] = m
472 472
 			}
473 473
 		}
474
-		volumesByDestination := make(map[string]types.MountPoint)
474
+		volumesByDestination := make(map[string]containertypes.MountPoint)
475 475
 		for _, m := range container.Mounts {
476 476
 			if m.Destination != "" {
477 477
 				volumesByDestination[m.Destination] = m
... ...
@@ -16,7 +16,6 @@ import (
16 16
 	"testing"
17 17
 	"time"
18 18
 
19
-	"github.com/docker/docker/api/types"
20 19
 	"github.com/docker/docker/api/types/container"
21 20
 	"github.com/docker/docker/api/types/mount"
22 21
 	"github.com/docker/docker/api/types/network"
... ...
@@ -1807,7 +1806,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
1807 1807
 
1808 1808
 	type testCase struct {
1809 1809
 		spec     mount.Mount
1810
-		expected types.MountPoint
1810
+		expected container.MountPoint
1811 1811
 	}
1812 1812
 
1813 1813
 	var selinuxSharedLabel string
... ...
@@ -1820,23 +1819,23 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
1820 1820
 		// Validation of the actual `Mount` struct is done in another test is not needed here
1821 1821
 		{
1822 1822
 			spec:     mount.Mount{Type: "volume", Target: destPath},
1823
-			expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1823
+			expected: container.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1824 1824
 		},
1825 1825
 		{
1826 1826
 			spec:     mount.Mount{Type: "volume", Target: destPath + slash},
1827
-			expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1827
+			expected: container.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1828 1828
 		},
1829 1829
 		{
1830 1830
 			spec:     mount.Mount{Type: "volume", Target: destPath, Source: "test1"},
1831
-			expected: types.MountPoint{Type: "volume", Name: "test1", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1831
+			expected: container.MountPoint{Type: "volume", Name: "test1", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1832 1832
 		},
1833 1833
 		{
1834 1834
 			spec:     mount.Mount{Type: "volume", Target: destPath, ReadOnly: true, Source: "test2"},
1835
-			expected: types.MountPoint{Type: "volume", Name: "test2", RW: false, Destination: destPath, Mode: selinuxSharedLabel},
1835
+			expected: container.MountPoint{Type: "volume", Name: "test2", RW: false, Destination: destPath, Mode: selinuxSharedLabel},
1836 1836
 		},
1837 1837
 		{
1838 1838
 			spec:     mount.Mount{Type: "volume", Target: destPath, Source: "test3", VolumeOptions: &mount.VolumeOptions{DriverConfig: &mount.Driver{Name: volume.DefaultDriverName}}},
1839
-			expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", Name: "test3", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1839
+			expected: container.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", Name: "test3", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1840 1840
 		},
1841 1841
 	}
1842 1842
 
... ...
@@ -1852,7 +1851,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
1852 1852
 					Source: tmpDir1,
1853 1853
 					Target: destPath,
1854 1854
 				},
1855
-				expected: types.MountPoint{
1855
+				expected: container.MountPoint{
1856 1856
 					Type:        "bind",
1857 1857
 					RW:          true,
1858 1858
 					Destination: destPath,
... ...
@@ -1861,7 +1860,7 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
1861 1861
 			},
1862 1862
 			{
1863 1863
 				spec:     mount.Mount{Type: "bind", Source: tmpDir1, Target: destPath, ReadOnly: true},
1864
-				expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir1},
1864
+				expected: container.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir1},
1865 1865
 			},
1866 1866
 		}...)
1867 1867
 
... ...
@@ -1875,15 +1874,15 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
1875 1875
 				cases = append(cases, []testCase{
1876 1876
 					{
1877 1877
 						spec:     mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath},
1878
-						expected: types.MountPoint{Type: "bind", RW: true, Destination: destPath, Source: tmpDir3},
1878
+						expected: container.MountPoint{Type: "bind", RW: true, Destination: destPath, Source: tmpDir3},
1879 1879
 					},
1880 1880
 					{
1881 1881
 						spec:     mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true},
1882
-						expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3},
1882
+						expected: container.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3},
1883 1883
 					},
1884 1884
 					{
1885 1885
 						spec:     mount.Mount{Type: "bind", Source: tmpDir3, Target: destPath, ReadOnly: true, BindOptions: &mount.BindOptions{Propagation: "shared"}},
1886
-						expected: types.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3, Propagation: "shared"},
1886
+						expected: container.MountPoint{Type: "bind", RW: false, Destination: destPath, Source: tmpDir3, Propagation: "shared"},
1887 1887
 					},
1888 1888
 				}...)
1889 1889
 			}
... ...
@@ -1894,19 +1893,19 @@ func (s *DockerAPISuite) TestContainersAPICreateMountsCreate(c *testing.T) {
1894 1894
 		cases = append(cases, []testCase{
1895 1895
 			{
1896 1896
 				spec:     mount.Mount{Type: "volume", Target: destPath, VolumeOptions: &mount.VolumeOptions{NoCopy: true}},
1897
-				expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1897
+				expected: container.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1898 1898
 			},
1899 1899
 			{
1900 1900
 				spec:     mount.Mount{Type: "volume", Target: destPath + slash, VolumeOptions: &mount.VolumeOptions{NoCopy: true}},
1901
-				expected: types.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1901
+				expected: container.MountPoint{Driver: volume.DefaultDriverName, Type: "volume", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1902 1902
 			},
1903 1903
 			{
1904 1904
 				spec:     mount.Mount{Type: "volume", Target: destPath, Source: "test4", VolumeOptions: &mount.VolumeOptions{NoCopy: true}},
1905
-				expected: types.MountPoint{Type: "volume", Name: "test4", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1905
+				expected: container.MountPoint{Type: "volume", Name: "test4", RW: true, Destination: destPath, Mode: selinuxSharedLabel},
1906 1906
 			},
1907 1907
 			{
1908 1908
 				spec:     mount.Mount{Type: "volume", Target: destPath, Source: "test5", ReadOnly: true, VolumeOptions: &mount.VolumeOptions{NoCopy: true}},
1909
-				expected: types.MountPoint{Type: "volume", Name: "test5", RW: false, Destination: destPath, Mode: selinuxSharedLabel},
1909
+				expected: container.MountPoint{Type: "volume", Name: "test5", RW: false, Destination: destPath, Mode: selinuxSharedLabel},
1910 1910
 			},
1911 1911
 		}...)
1912 1912
 	}
... ...
@@ -14,7 +14,7 @@ import (
14 14
 	"testing"
15 15
 	"time"
16 16
 
17
-	"github.com/docker/docker/api/types"
17
+	"github.com/docker/docker/api/types/container"
18 18
 	volumetypes "github.com/docker/docker/api/types/volume"
19 19
 	"github.com/docker/docker/integration-cli/cli"
20 20
 	"github.com/docker/docker/integration-cli/daemon"
... ...
@@ -494,7 +494,7 @@ func (s *DockerExternalVolumeSuite) TestExternalVolumeDriverWithDaemonRestart(c
494 494
 	s.d.Restart(c)
495 495
 
496 496
 	cli.DockerCmd(c, "run", "--name=test", "-v", "abc1:/foo", "busybox", "true")
497
-	var mounts []types.MountPoint
497
+	var mounts []container.MountPoint
498 498
 	inspectFieldAndUnmarshall(c, "test", "Mounts", &mounts)
499 499
 	assert.Equal(c, len(mounts), 1)
500 500
 	assert.Equal(c, mounts[0].Driver, volumePluginName)
... ...
@@ -194,7 +194,7 @@ func (s *DockerCLIInspectSuite) TestInspectBindMountPoint(c *testing.T) {
194 194
 
195 195
 	vol := inspectFieldJSON(c, "test", "Mounts")
196 196
 
197
-	var mp []types.MountPoint
197
+	var mp []container.MountPoint
198 198
 	err := json.Unmarshal([]byte(vol), &mp)
199 199
 	assert.NilError(c, err)
200 200
 
... ...
@@ -218,7 +218,7 @@ func (s *DockerCLIInspectSuite) TestInspectNamedMountPoint(c *testing.T) {
218 218
 
219 219
 	vol := inspectFieldJSON(c, "test", "Mounts")
220 220
 
221
-	var mp []types.MountPoint
221
+	var mp []container.MountPoint
222 222
 	err := json.Unmarshal([]byte(vol), &mp)
223 223
 	assert.NilError(c, err)
224 224
 
... ...
@@ -9,7 +9,7 @@ import (
9 9
 	"strings"
10 10
 	"testing"
11 11
 
12
-	"github.com/docker/docker/api/types"
12
+	"github.com/docker/docker/api/types/container"
13 13
 	"github.com/docker/docker/api/types/mount"
14 14
 	"github.com/docker/docker/api/types/swarm"
15 15
 	"github.com/docker/docker/integration-cli/checker"
... ...
@@ -57,7 +57,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountVolume(c *testing.T) {
57 57
 	out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
58 58
 	assert.NilError(c, err, out)
59 59
 
60
-	var mounts []types.MountPoint
60
+	var mounts []container.MountPoint
61 61
 	assert.Assert(c, json.Unmarshal([]byte(out), &mounts) == nil)
62 62
 	assert.Equal(c, len(mounts), 1)
63 63
 
... ...
@@ -407,7 +407,7 @@ func (s *DockerSwarmSuite) TestServiceCreateMountTmpfs(c *testing.T) {
407 407
 	out, err = s.nodeCmd(c, task.NodeID, "inspect", "--format", "{{json .Mounts}}", task.Status.ContainerStatus.ContainerID)
408 408
 	assert.NilError(c, err, out)
409 409
 
410
-	var mounts []types.MountPoint
410
+	var mounts []container.MountPoint
411 411
 	assert.Assert(c, json.Unmarshal([]byte(out), &mounts) == nil)
412 412
 	assert.Equal(c, len(mounts), 1)
413 413
 
... ...
@@ -15,6 +15,7 @@ import (
15 15
 	"time"
16 16
 
17 17
 	"github.com/docker/docker/api/types"
18
+	"github.com/docker/docker/api/types/container"
18 19
 	"github.com/docker/docker/client"
19 20
 	"github.com/docker/docker/integration-cli/cli"
20 21
 	"github.com/docker/docker/integration-cli/daemon"
... ...
@@ -131,18 +132,18 @@ func inspectMountSourceField(name, destination string) (string, error) {
131 131
 var errMountNotFound = errors.New("mount point not found")
132 132
 
133 133
 // Deprecated: use cli.Docker
134
-func inspectMountPoint(name, destination string) (types.MountPoint, error) {
134
+func inspectMountPoint(name, destination string) (container.MountPoint, error) {
135 135
 	out, err := inspectFilter(name, "json .Mounts")
136 136
 	if err != nil {
137
-		return types.MountPoint{}, err
137
+		return container.MountPoint{}, err
138 138
 	}
139 139
 
140
-	var mp []types.MountPoint
140
+	var mp []container.MountPoint
141 141
 	if err := json.Unmarshal([]byte(out), &mp); err != nil {
142
-		return types.MountPoint{}, err
142
+		return container.MountPoint{}, err
143 143
 	}
144 144
 
145
-	var m *types.MountPoint
145
+	var m *container.MountPoint
146 146
 	for _, c := range mp {
147 147
 		if c.Destination == destination {
148 148
 			m = &c
... ...
@@ -151,7 +152,7 @@ func inspectMountPoint(name, destination string) (types.MountPoint, error) {
151 151
 	}
152 152
 
153 153
 	if m == nil {
154
-		return types.MountPoint{}, errMountNotFound
154
+		return container.MountPoint{}, errMountNotFound
155 155
 	}
156 156
 
157 157
 	return *m, nil