Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply volume options only to volumes #2201

Merged
merged 3 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions docker_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ func mapToDockerMounts(containerMounts ContainerMounts) []mount.Mount {
Source: m.Source.Source(),
ReadOnly: m.ReadOnly,
Target: m.Target.Target(),
VolumeOptions: &mount.VolumeOptions{
Labels: GenericLabels(),
},
}

switch typedMounter := m.Source.(type) {
Expand All @@ -117,6 +114,17 @@ func mapToDockerMounts(containerMounts ContainerMounts) []mount.Mount {
// The provided source type has no custom options
}

if mountType == mount.TypeVolume {
if containerMount.VolumeOptions == nil {
containerMount.VolumeOptions = &mount.VolumeOptions{
Labels: make(map[string]string),
}
}
for k, v := range GenericLabels() {
containerMount.VolumeOptions.Labels[k] = v
}
}

mounts = append(mounts, containerMount)
}

Expand Down
24 changes: 11 additions & 13 deletions mounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
Labels: GenericLabels(),
}

expectedLabels := GenericLabels()
expectedLabels["hello"] = "world"

t.Parallel()
tests := []struct {
name string
Expand Down Expand Up @@ -104,9 +107,7 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
Target: "/data",
VolumeOptions: &mount.VolumeOptions{
NoCopy: true,
Labels: map[string]string{
"hello": "world",
},
Labels: expectedLabels,
},
},
},
Expand All @@ -117,26 +118,24 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
mounts: ContainerMounts{{Source: GenericTmpfsMountSource{}, Target: "/data"}},
want: []mount.Mount{
{
Type: mount.TypeTmpfs,
Target: "/data",
VolumeOptions: volumeOptions,
Type: mount.TypeTmpfs,
Target: "/data",
},
},
},
{
name: "Single volume mount - read-only",
name: "Single tmpfs mount - read-only",
mounts: ContainerMounts{{Source: GenericTmpfsMountSource{}, Target: "/data", ReadOnly: true}},
want: []mount.Mount{
{
Type: mount.TypeTmpfs,
Target: "/data",
ReadOnly: true,
VolumeOptions: volumeOptions,
Type: mount.TypeTmpfs,
Target: "/data",
ReadOnly: true,
},
},
},
{
name: "Single volume mount - with options",
name: "Single tmpfs mount - with options",
mounts: ContainerMounts{
{
Source: DockerTmpfsMountSource{
Expand All @@ -156,7 +155,6 @@ func TestContainerMounts_PrepareMounts(t *testing.T) {
SizeBytes: 50 * 1024 * 1024,
Mode: 0o644,
},
VolumeOptions: volumeOptions,
},
},
},
Expand Down
Loading