From d3c051318f1576ecadf04657b328792ef6513a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Gronowski?= Date: Fri, 12 Apr 2024 11:46:25 +0200 Subject: [PATCH] daemon/cluster/executor: Add volume `Subpath` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Paweł Gronowski --- daemon/cluster/convert/container.go | 10 +++--- daemon/cluster/convert/service_test.go | 31 +++++++++++++++++++ .../cluster/executor/container/container.go | 3 +- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/daemon/cluster/convert/container.go b/daemon/cluster/convert/container.go index 77001774fe..b6b610e10e 100644 --- a/daemon/cluster/convert/container.go +++ b/daemon/cluster/convert/container.go @@ -120,8 +120,9 @@ func containerSpecFromGRPC(c *swarmapi.ContainerSpec) *types.ContainerSpec { if m.VolumeOptions != nil { mount.VolumeOptions = &mounttypes.VolumeOptions{ - NoCopy: m.VolumeOptions.NoCopy, - Labels: m.VolumeOptions.Labels, + NoCopy: m.VolumeOptions.NoCopy, + Labels: m.VolumeOptions.Labels, + Subpath: m.VolumeOptions.Subpath, } if m.VolumeOptions.DriverConfig != nil { mount.VolumeOptions.DriverConfig = &mounttypes.Driver{ @@ -406,8 +407,9 @@ func containerToGRPC(c *types.ContainerSpec) (*swarmapi.ContainerSpec, error) { if m.VolumeOptions != nil { mount.VolumeOptions = &swarmapi.Mount_VolumeOptions{ - NoCopy: m.VolumeOptions.NoCopy, - Labels: m.VolumeOptions.Labels, + NoCopy: m.VolumeOptions.NoCopy, + Labels: m.VolumeOptions.Labels, + Subpath: m.VolumeOptions.Subpath, } if m.VolumeOptions.DriverConfig != nil { mount.VolumeOptions.DriverConfig = &swarmapi.Driver{ diff --git a/daemon/cluster/convert/service_test.go b/daemon/cluster/convert/service_test.go index 12907f3115..6f058829ee 100644 --- a/daemon/cluster/convert/service_test.go +++ b/daemon/cluster/convert/service_test.go @@ -4,11 +4,13 @@ import ( "testing" containertypes "github.com/docker/docker/api/types/container" + "github.com/docker/docker/api/types/mount" swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm/runtime" google_protobuf3 "github.com/gogo/protobuf/types" swarmapi "github.com/moby/swarmkit/v2/api" "gotest.tools/v3/assert" + is "gotest.tools/v3/assert/cmp" ) func TestServiceConvertFromGRPCRuntimeContainer(t *testing.T) { @@ -611,3 +613,32 @@ func TestServiceConvertToGRPCConfigs(t *testing.T) { }) } } + +func TestServiceConvertToGRPCVolumeSubpath(t *testing.T) { + s := swarmtypes.ServiceSpec{ + TaskTemplate: swarmtypes.TaskSpec{ + ContainerSpec: &swarmtypes.ContainerSpec{ + Mounts: []mount.Mount{ + { + Source: "/foo/bar", + Target: "/baz", + Type: mount.TypeVolume, + ReadOnly: false, + VolumeOptions: &mount.VolumeOptions{ + Subpath: "sub", + }, + }, + }, + }, + }, + } + + g, err := ServiceSpecToGRPC(s) + assert.NilError(t, err) + + v, ok := g.Task.Runtime.(*swarmapi.TaskSpec_Container) + assert.Assert(t, ok) + + assert.Check(t, is.Len(v.Container.Mounts, 1)) + assert.Check(t, is.Equal(v.Container.Mounts[0].VolumeOptions.Subpath, "sub")) +} diff --git a/daemon/cluster/executor/container/container.go b/daemon/cluster/executor/container/container.go index 8aeb9d379c..0257030e5e 100644 --- a/daemon/cluster/executor/container/container.go +++ b/daemon/cluster/executor/container/container.go @@ -338,7 +338,8 @@ func convertMount(m api.Mount) enginemount.Mount { if m.VolumeOptions != nil { mount.VolumeOptions = &enginemount.VolumeOptions{ - NoCopy: m.VolumeOptions.NoCopy, + NoCopy: m.VolumeOptions.NoCopy, + Subpath: m.VolumeOptions.Subpath, } if m.VolumeOptions.Labels != nil { mount.VolumeOptions.Labels = make(map[string]string, len(m.VolumeOptions.Labels))