Skip to content

Commit

Permalink
fix: set mountpoint RW and Propagation in internal mount label
Browse files Browse the repository at this point in the history
Signed-off-by: baijia <baijia.wr@antgroup.com>
  • Loading branch information
baijia committed Apr 25, 2024
1 parent f25ce7e commit 4ef3190
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 7 additions & 1 deletion cmd/nerdctl/container_inspect_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"testing"

"github.com/containerd/nerdctl/v2/pkg/inspecttypes/dockercompat"
"github.com/containerd/nerdctl/v2/pkg/labels"
"github.com/containerd/nerdctl/v2/pkg/testutil"
"github.com/docker/go-connections/nat"
"gotest.tools/v3/assert"
Expand Down Expand Up @@ -147,13 +148,18 @@ func TestContainerInspectContainsLabel(t *testing.T) {
base := testutil.NewBase(t)
defer base.Cmd("rm", "-f", testContainer).Run()

base.Cmd("run", "-d", "--name", testContainer, "--label", "foo=foo", "--label", "bar=bar", testutil.NginxAlpineImage).AssertOK()
base.Cmd("run", "-d", "--name", testContainer, "--label", "foo=foo", "--label", "bar=bar", "--mount", "type=bind,src=/tmp,dst=/app,readonly=false,bind-propagation=rshared", testutil.NginxAlpineImage).AssertOK()
base.EnsureContainerStarted(testContainer)
inspect := base.InspectContainer(testContainer)
lbs := inspect.Config.Labels

assert.Equal(base.T, "foo", lbs["foo"])
assert.Equal(base.T, "bar", lbs["bar"])

// internal labels
labelMount := lbs[labels.Mounts]
expectedLabelMount := "[{\"Type\":\"bind\",\"Source\":\"/tmp\",\"Destination\":\"/app\",\"Mode\":\"rshared,rbind\",\"RW\":true,\"Propagation\":\"rshared\"}]"
assert.Equal(base.T, expectedLabelMount, labelMount)
}

func TestContainerInspectState(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ func dockercompatMounts(mountPoints []*mountutil.Processed) []dockercompat.Mount
Driver: "",
Mode: mp.Mode,
}
result[i].RW, result[i].Propagation = dockercompat.ParseMountProperties(strings.Split(mp.Mode, ","))

// it's an anonymous volume
if mp.AnonymousVolume != "" {
Expand Down
11 changes: 2 additions & 9 deletions pkg/inspecttypes/dockercompat/dockercompat.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
"path/filepath"
"runtime"
"strconv"
"strings"
"time"

"github.com/containerd/containerd"
Expand Down Expand Up @@ -485,18 +484,12 @@ func parseMounts(nerdctlMounts string) ([]MountPoint, error) {
return nil, err
}

for i := range mounts {
rw, propagation := parseMountProperties(mounts[i].Mode)
mounts[i].RW = rw
mounts[i].Propagation = propagation
}

return mounts, nil
}

func parseMountProperties(option string) (rw bool, propagation string) {
func ParseMountProperties(option []string) (rw bool, propagation string) {
rw = true
for _, opt := range strings.Split(option, ",") {
for _, opt := range option {
switch opt {
case "ro", "rro":
rw = false
Expand Down

0 comments on commit 4ef3190

Please sign in to comment.