github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/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 issue="https://github.com/kata-containers/runtime/issues/1127" 12 fc_limitations="https://github.com/kata-containers/documentation/issues/351" 13 14 setup() { 15 [ "${TEST_INITRD}" == "yes" ] && skip "test not working see: ${issue}" 16 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 17 18 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 19 get_pod_config_dir 20 21 tmp_file=$(mktemp -d /tmp/data.XXXX) 22 pod_yaml=$(mktemp --tmpdir pod_config.XXXXXX.yaml) 23 msg="Hello from Kubernetes" 24 echo $msg > $tmp_file/index.html 25 pod_name="pv-pod" 26 # Define temporary file at yaml 27 sed -e "s|tmp_data|${tmp_file}|g" ${pod_config_dir}/pv-volume.yaml > "$pod_yaml" 28 } 29 30 @test "Create Persistent Volume" { 31 [ "${TEST_INITRD}" == "yes" ] && skip "test not working see: ${issue}" 32 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 33 34 volume_name="pv-volume" 35 volume_claim="pv-claim" 36 37 # Create the persistent volume 38 kubectl create -f "$pod_yaml" 39 40 # Check the persistent volume is Available 41 cmd="kubectl get pv $volume_name | grep Available" 42 waitForProcess "$wait_time" "$sleep_time" "$cmd" 43 44 # Create the persistent volume claim 45 kubectl create -f "${pod_config_dir}/volume-claim.yaml" 46 47 # Check the persistent volume claim is Bound. 48 cmd="kubectl get pvc $volume_claim | grep Bound" 49 waitForProcess "$wait_time" "$sleep_time" "$cmd" 50 51 # Create pod 52 kubectl create -f "${pod_config_dir}/pv-pod.yaml" 53 54 # Check pod creation 55 kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" 56 57 cmd="cat /mnt/index.html" 58 kubectl exec $pod_name -- sh -c "$cmd" | grep "$msg" 59 } 60 61 teardown() { 62 [ "${TEST_INITRD}" == "yes" ] && skip "test not working see: ${issue}" 63 [ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}" 64 65 # Debugging information 66 kubectl describe "pod/$pod_name" 67 68 kubectl delete pod "$pod_name" 69 kubectl delete pvc "$volume_claim" 70 kubectl delete pv "$volume_name" 71 rm -f "$pod_yaml" 72 rm -rf "$tmp_file" 73 }