github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-volume.bats (about) 1 #!/usr/bin/env bats 2 # 3 # Copyright (c) 2018 Intel Corporation 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 TEST_INITRD="${TEST_INITRD:-no}" 11 12 setup() { 13 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 14 15 get_pod_config_dir 16 17 tmp_file=$(mktemp -d /tmp/data.XXXX) 18 pod_yaml=$(mktemp --tmpdir pod_config.XXXXXX.yaml) 19 msg="Hello from Kubernetes" 20 echo $msg > $tmp_file/index.html 21 pod_name="pv-pod" 22 # Define temporary file at yaml 23 sed -e "s|tmp_data|${tmp_file}|g" ${pod_config_dir}/pv-volume.yaml > "$pod_yaml" 24 } 25 26 @test "Create Persistent Volume" { 27 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 28 29 volume_name="pv-volume" 30 volume_claim="pv-claim" 31 32 # Create the persistent volume 33 kubectl create -f "$pod_yaml" 34 35 # Check the persistent volume is Available 36 cmd="kubectl get pv $volume_name | grep Available" 37 waitForProcess "$wait_time" "$sleep_time" "$cmd" 38 39 # Create the persistent volume claim 40 kubectl create -f "${pod_config_dir}/volume-claim.yaml" 41 42 # Check the persistent volume claim is Bound. 43 cmd="kubectl get pvc $volume_claim | grep Bound" 44 waitForProcess "$wait_time" "$sleep_time" "$cmd" 45 46 # Create pod 47 kubectl create -f "${pod_config_dir}/pv-pod.yaml" 48 49 # Check pod creation 50 kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" 51 52 cmd="cat /mnt/index.html" 53 kubectl exec $pod_name -- sh -c "$cmd" | grep "$msg" 54 } 55 56 teardown() { 57 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 58 59 # Debugging information 60 kubectl describe "pod/$pod_name" 61 62 kubectl delete pod "$pod_name" 63 kubectl delete pvc "$volume_claim" 64 kubectl delete pv "$volume_name" 65 rm -f "$pod_yaml" 66 rm -rf "$tmp_file" 67 }