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

Add new container host path test. #320

Merged
merged 1 commit into from
Jun 7, 2018
Merged
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
38 changes: 24 additions & 14 deletions pkg/validate/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ var _ = framework.KubeDescribe("Container", func() {
})
})

Context("runtime should support adding volume and device [Conformance]", func() {
Context("runtime should support adding volume and device", func() {
var podID string
var podConfig *runtimeapi.PodSandboxConfig

Expand Down Expand Up @@ -165,26 +165,29 @@ var _ = framework.KubeDescribe("Container", func() {
Expect(len(output)).NotTo(BeZero(), "len(output) should not be zero.")
})

It("runtime should support starting container with volume when host path doesn't exist", func() {
// TODO: revisit this after https://github.com/kubernetes/kubernetes/issues/52318.
Skip("Skip the test since the behavior is not decided yet in CRI")
By("get a host path that doesn't exist")
It("runtime should support starting container with volume when host path is a symlink [Conformance]", func() {
By("create host path and flag file")
hostPath, _ := createHostPath(podID)
os.RemoveAll(hostPath) // make sure the host path doesn't exist

defer os.RemoveAll(hostPath) // clean up the TempDir

By("create container with volume")
containerID := createVolumeContainer(rc, ic, "container-with-volume-test-", podID, podConfig, hostPath)
By("create symlink")
symlinkPath := createSymlink(hostPath)
defer os.RemoveAll(symlinkPath) // clean up the symlink

By("test start container with volume")
By("create volume container with symlink host path")
containerID := createVolumeContainer(rc, ic, "container-with-symlink-host-path-test-", podID, podConfig, symlinkPath)

By("test start volume container with symlink host path")
testStartContainer(rc, containerID)

By("check whether 'hostPath' does exist or not in host")
Eventually(func() bool {
return pathExists(hostPath)
}, time.Minute, time.Second*4).Should(Equal(true))
By("check whether 'symlink' contains file or dir in container")
command := []string{"ls", "-A", symlinkPath}
output := execSyncContainer(rc, containerID, command)
Expect(len(output)).NotTo(BeZero(), "len(output) should not be zero.")
})

// TODO(random-liu): Decide whether to add host path not exist test when https://github.com/kubernetes/kubernetes/pull/61460
// is finalized.
})

Context("runtime should support log", func() {
Expand Down Expand Up @@ -390,6 +393,13 @@ func createHostPath(podID string) (string, string) {
return hostPath, flagFile
}

// createSymlink creates a symlink of path.
func createSymlink(path string) string {
symlinkPath := path + "-symlink"
framework.ExpectNoError(os.Symlink(path, symlinkPath), "failed to create symlink %q", symlinkPath)
return symlinkPath
}

// createVolumeContainer creates a container with volume and the prefix of containerName and fails if it gets error.
func createVolumeContainer(rc internalapi.RuntimeService, ic internalapi.ImageManagerService, prefix string, podID string, podConfig *runtimeapi.PodSandboxConfig, hostPath string) string {
By("create a container with volume and name")
Expand Down