Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit f239e9f

Browse files
authored
Merge pull request #5357 from liubin/fix/5356-add-test-for-share-file
tests: add hostPath volume test for sharing files
2 parents 77e755f + 77f6908 commit f239e9f

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

integration/kubernetes/run_kubernetes_tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ else
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" \
@@ -72,6 +73,7 @@ else
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" \
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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"]

0 commit comments

Comments
 (0)