This repository was archived by the owner on Jun 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+ #
3+ # Copyright (c) 2022 Ant Group
4+ #
5+ # SPDX-License-Identifier: Apache-2.0
6+ #
7+
8+ load " ${BATS_TEST_DIRNAME} /../../.ci/lib.sh"
9+ load " ${BATS_TEST_DIRNAME} /tests_common.sh"
10+
11+ setup () {
12+ [ " ${KATA_HYPERVISOR} " == " firecracker" ] && skip " test not working see: ${fc_limitations} "
13+ pod_name=" test-file-volume"
14+ container_name=" busybox-file-volume-container"
15+ tmp_file=$( mktemp /tmp/file-volume-test-foo.XXXXX)
16+ mount_path=" /tmp/foo.txt"
17+ file_body=" test"
18+ get_pod_config_dir
19+ }
20+
21+ @test " Test readonly volume for pods" {
22+ [ " ${KATA_HYPERVISOR} " == " firecracker" ] && skip " test not working see: ${fc_limitations} "
23+ # Write test body to temp file
24+ echo " $file_body " > $tmp_file
25+
26+ # Create test yaml
27+ sed -e " s|HOST_FILE|$tmp_file |" ${pod_config_dir} /pod-file-volume.yaml > ${pod_config_dir} /test-pod-file-volume.yaml
28+ sed -i " s|MOUNT_PATH|$mount_path |" ${pod_config_dir} /test-pod-file-volume.yaml
29+
30+ # Create pod
31+ kubectl create -f " ${pod_config_dir} /test-pod-file-volume.yaml"
32+
33+ # Check pod creation
34+ kubectl wait --for=condition=Ready --timeout=$timeout pod " $pod_name "
35+
36+ # Validate file volume body inside the pod
37+ file_in_container=$( kubectl exec $pod_name -- cat $mount_path )
38+ [ " $file_body " == " $file_in_container " ]
39+ }
40+
41+ teardown () {
42+ [ " ${KATA_HYPERVISOR} " == " firecracker" ] && skip " test not working see: ${fc_limitations} "
43+ rm -f $tmp_file
44+ rm -f ${pod_config_dir} /test-pod-file-volume.yaml.yaml
45+ kubectl delete pod " $pod_name "
46+ }
Original file line number Diff line number Diff line change 3232 " k8s-env.bats" \
3333 " k8s-exec.bats" \
3434 " k8s-expose-ip.bats" \
35+ " k8s-file-volume.bats" \
3536 " k8s-inotify.bats" \
3637 " k8s-job.bats" \
3738 " k8s-kill-all-process-in-container.bats" \
7273 " k8s-env.bats" \
7374 " k8s-exec.bats" \
7475 " k8s-expose-ip.bats" \
76+ " k8s-file-volume.bats" \
7577 " k8s-inotify.bats" \
7678 " k8s-job.bats" \
7779 " k8s-limit-range.bats" \
Original file line number Diff line number Diff line change 1+ #
2+ # Copyright (c) 2022 Ant Group
3+ #
4+ # SPDX-License-Identifier: Apache-2.0
5+ #
6+ apiVersion : v1
7+ kind : Pod
8+ metadata :
9+ name : test-file-volume
10+ spec :
11+ terminationGracePeriodSeconds : 0
12+ runtimeClassName : kata
13+ restartPolicy : Never
14+ volumes :
15+ - name : shared-file
16+ hostPath :
17+ path : HOST_FILE
18+ type : File
19+ containers :
20+ - name : busybox-file-volume-container
21+ image : busybox
22+ volumeMounts :
23+ - name : shared-file
24+ mountPath : MOUNT_PATH
25+ command : ["/bin/sh"]
26+ args : ["-c", "tail -f /dev/null"]
You can’t perform that action at this time.
0 commit comments