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

Commit

Permalink
Add integration test for volume copy up.
Browse files Browse the repository at this point in the history
Signed-off-by: Lantao Liu <lantaol@google.com>
  • Loading branch information
Random-Liu committed Jan 11, 2018
1 parent d744499 commit 07a562e
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 1 deletion.
17 changes: 17 additions & 0 deletions integration/images/volume-copy-up/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM busybox
RUN sh -c "mkdir /test_dir; echo test_content > /test_dir/test_file"
VOLUME "/test_dir"
27 changes: 27 additions & 0 deletions integration/images/volume-copy-up/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2018 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

all: build

PROJ=gcr.io/k8s-cri-containerd
VERSION=1.0
IMAGE=$(PROJ)/volume-copy-up:$(VERSION)

build:
docker build -t $(IMAGE) .

push:
gcloud docker -- push $(IMAGE)

.PHONY: build push
90 changes: 90 additions & 0 deletions integration/volume_copy_up_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
Copyright 2018 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package integration

import (
"fmt"
"os/exec"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
)

func TestVolumeCopyUp(t *testing.T) {
const (
testImage = "gcr.io/k8s-cri-containerd/volume-copy-up:1.0"
execTimeout = time.Minute
)

t.Logf("Create a sandbox")
sbConfig := PodSandboxConfig("sandbox", "volume-copy-up")
sb, err := runtimeService.RunPodSandbox(sbConfig)
require.NoError(t, err)
defer func() {
assert.NoError(t, runtimeService.StopPodSandbox(sb))
assert.NoError(t, runtimeService.RemovePodSandbox(sb))
}()

t.Logf("Pull test image")
_, err = imageService.PullImage(&runtime.ImageSpec{Image: testImage}, nil)
require.NoError(t, err)

t.Logf("Create a container with volume-copy-up test image")
cnConfig := ContainerConfig(
"container",
testImage,
WithCommand("tail", "-f", "/dev/null"),
)
cn, err := runtimeService.CreateContainer(sb, cnConfig, sbConfig)
require.NoError(t, err)

t.Logf("Start the container")
require.NoError(t, runtimeService.StartContainer(cn))

// gcr.io/k8s-cri-containerd/volume-copy-up:1.0 contains a test_dir
// volume, which contains a test_file with content "test_content".
t.Logf("Check whether volume contains the test file")
stdout, stderr, err := runtimeService.ExecSync(cn, []string{
"cat",
"/test_dir/test_file",
}, execTimeout)
require.NoError(t, err)
assert.Empty(t, stderr)
assert.Equal(t, "test_content\n", string(stdout))

t.Logf("Check host path of the volume")
hostCmd := fmt.Sprintf("ls %s/containers/%s/volumes/*/test_file | xargs cat", criContainerdRoot, cn)
output, err := exec.Command("sh", "-c", hostCmd).CombinedOutput()
require.NoError(t, err)
assert.Equal(t, "test_content\n", string(output))

t.Logf("Update volume from inside the container")
_, _, err = runtimeService.ExecSync(cn, []string{
"sh",
"-c",
"echo new_content > /test_dir/test_file",
}, execTimeout)
require.NoError(t, err)

t.Logf("Check whether host path of the volume is updated")
output, err = exec.Command("sh", "-c", hostCmd).CombinedOutput()
require.NoError(t, err)
assert.Equal(t, "new_content\n", string(output))
}
1 change: 0 additions & 1 deletion pkg/server/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ func (c *criContainerdService) CreateContainer(ctx context.Context, r *runtime.C
}()

// Create container volumes mounts.
// TODO(random-liu): Add cri-containerd integration test for image volume.
volumeMounts := c.generateVolumeMounts(containerRootDir, config.GetMounts(), &image.ImageSpec.Config)

// Generate container runtime spec.
Expand Down

0 comments on commit 07a562e

Please sign in to comment.