Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Ensure the mount point is propagated #230

Merged
merged 1 commit into from
Sep 19, 2017

Conversation

miaoyq
Copy link
Member

@miaoyq miaoyq commented Sep 8, 2017

mount with rshared, the host path should be shared.
mount with rslave, the host pash should be shared or slave.

Based on #246

Signed-off-by: Yanqiang Miao miao.yanqiang@zte.com.cn

/cc @Random-Liu

@miaoyq
Copy link
Member Author

miaoyq commented Sep 11, 2017

The CI failed because we have not used the real path.
Maybe we should add this in kubelet side.
@Random-Liu What do you think for this?

@miaoyq miaoyq force-pushed the ensure-mount-shared-slave branch 3 times, most recently from 0c13442 to d391d7b Compare September 12, 2017 08:51
@Random-Liu
Copy link
Member

Random-Liu commented Sep 13, 2017

@miaoyq Will review this PR after Thursday. BTW, would you mind me mention ZTE is contributing to cri-containerd in the moby summit LA? I want to thank you guys for your contribution. :)

@miaoyq
Copy link
Member Author

miaoyq commented Sep 13, 2017

Of course not, i really appreciate that. : )

@miaoyq
Copy link
Member Author

miaoyq commented Sep 14, 2017

I've manually made unit test locally, and it works, but the travis-ci always failed.
@Random-Liu Does the travis-ci run as non root user?

miaoyq pushed a commit to miaoyq/cri-containerd that referenced this pull request Sep 15, 2017
Related to containerd#230

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
@miaoyq miaoyq mentioned this pull request Sep 15, 2017
@miaoyq
Copy link
Member Author

miaoyq commented Sep 15, 2017

@Random-Liu The travis-ci run unit test as non root user, but mount operation need root user.

I have create a pr for this, see #246, PTAL, Thanks :)

@Random-Liu Random-Liu added this to the v1.0.0-alpha.0 milestone Sep 15, 2017
@@ -48,8 +50,57 @@ func checkMount(t *testing.T, mounts []runtimespec.Mount, src, dest, typ string,
assert.True(t, found, "mount from %q to %q not found", src, dest)
}

func getCreateContainerTestData() (*runtime.ContainerConfig, *runtime.PodSandboxConfig,
*imagespec.ImageConfig, func(*testing.T, string, uint32, *runtimespec.Spec)) {
func createHostPath(t *testing.T, mounts []*runtime.Mount) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we should test this in unit test.
We have replaced or os with FakeOS. This test won't work.
If we really want to test, we should leverage the FakeOS to test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add our own integration test framework, we could add this kind of test there.

@Random-Liu Random-Liu self-assigned this Sep 16, 2017
optsSplit := strings.Split(optionalOpts, " ")
for _, opt := range optsSplit {
if strings.HasPrefix(opt, "shared:") {
sharedMount = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nil directly.

sharedMount = true
break
} else if strings.HasPrefix(opt, "master:") {
slaveMount = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nil directly.

slaveMount = true
break
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return error here.


func getSourceMount(source string) (string, string, error) {
// Ensure any symlinks are resolved.
sourcePath, err := filepath.EvalSymlinks(source)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to resolve symlink. We've done that in addOCIBindMounts.

return "", "", err
}

mountinfos, err := mount.GetMounts()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add GetMounts to os package, so that you could use fake os in unit test, and please add unit test based on that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's better. 👍

optsSplit := strings.Split(optionalOpts, " ")
for _, opt := range optsSplit {
if strings.HasPrefix(opt, "shared:") {
sharedMount = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nil here.

break
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return error.

return nil
}

func getSourceMount(source string) (string, string, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably move this to helper.

@miaoyq
Copy link
Member Author

miaoyq commented Sep 16, 2017

@Random-Liu Thank you for review, I'm addressing the comments.

@miaoyq
Copy link
Member Author

miaoyq commented Sep 17, 2017

@Random-Liu Have addressed, PTAL, Thanks!

@@ -384,3 +385,35 @@ func isInCRIMounts(dst string, mounts []*runtime.Mount) bool {
}
return false
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add TODO to replace with mount.Lookup() in containerd.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And please replace with mount.Loopup() after #257 is merged.

}
}

return fmt.Errorf("path %s is mounted on %s but it is not a shared mount", path, sourceMount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use %q for string.

return nil
}
}
return fmt.Errorf("path %s is mounted on %s but it is not a shared or slave mount", path, sourceMount)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto.

imagespec "github.com/opencontainers/image-spec/specs-go/v1"
runtimespec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/generate"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"

testing2 "github.com/kubernetes-incubator/cri-containerd/pkg/os/testing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ostesting "github.com/kubernetes-incubator/cri-containerd/pkg/os/testing"

},
fakeGetMountsFn: nil,
optionsCheck: []string{"rbind", "rprivate"},
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add error test case, which host path propagation is not properly set, we should expect an error from addOCIBindMounts.

@miaoyq
Copy link
Member Author

miaoyq commented Sep 19, 2017

@Random-Liu Thanks for review, Have addressed.

Copy link
Member

@Random-Liu Random-Liu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with one nit. Good to go after address the nit.

}

for desc, test := range map[string]struct {
criMount *runtime.Mount
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add expectErr bool.

We could:

  1. assert error, if expectErr==true.
  2. assert no error and check options, if expectErr==false.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will change according to your instructions, thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

mount with `rshared`, the host path should be shared.
mount with `rslave`, the host pash should be shared or slave.

Signed-off-by: Yanqiang Miao <miao.yanqiang@zte.com.cn>
@Random-Liu
Copy link
Member

LGTM

@Random-Liu
Copy link
Member

The test failure feels like a flake, filed #259 for it.

Will retrigger the test.

@Random-Liu Random-Liu merged commit 4371312 into containerd:master Sep 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants