github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/kubernetes/k8s-empty-dirs.bats (about) 1 #!/usr/bin/env bats 2 # 3 # Copyright (c) 2019 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 11 assert_equal() { 12 local expected=$1 13 local actual=$2 14 if [[ "$expected" != "$actual" ]]; then 15 echo "expected: $expected, got: $actual" 16 return 1 17 fi 18 } 19 20 setup() { 21 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 22 pod_name="sharevol-kata" 23 get_pod_config_dir 24 pod_logs_file="" 25 } 26 27 @test "Empty dir volumes" { 28 # Create the pod 29 kubectl create -f "${pod_config_dir}/pod-empty-dir.yaml" 30 31 # Check pod creation 32 kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" 33 34 # Check volume mounts 35 cmd="mount | grep cache" 36 kubectl exec $pod_name -- sh -c "$cmd" | grep "/tmp/cache type tmpfs" 37 } 38 39 @test "Empty dir volume when FSGroup is specified with non-root container" { 40 # This is a reproducer of k8s e2e "[sig-storage] EmptyDir volumes when FSGroup is specified [LinuxOnly] [NodeFeature:FSGroup] new files should be created with FSGroup ownership when container is non-root" test 41 pod_file="${pod_config_dir}/pod-empty-dir-fsgroup.yaml" 42 agnhost_name=$(get_test_version "container_images.agnhost.name") 43 agnhost_version=$(get_test_version "container_images.agnhost.version") 44 image="${agnhost_name}:${agnhost_version}" 45 46 # Try to avoid timeout by prefetching the image. 47 crictl_pull "$image" 48 sed -e "s#\${agnhost_image}#${image}#" "$pod_file" |\ 49 kubectl create -f - 50 cmd="kubectl get pods ${pod_name} | grep Completed" 51 waitForProcess "${wait_time}" "${sleep_time}" "${cmd}" 52 53 pod_logs_file="$(mktemp)" 54 for container in mounttest-container mounttest-container-2; do 55 kubectl logs "$pod_name" "$container" > "$pod_logs_file" 56 # Check owner UID of file 57 uid=$(cat $pod_logs_file | grep 'owner UID of' | sed 's/.*:\s//') 58 assert_equal "1001" "$uid" 59 # Check owner GID of file 60 gid=$(cat $pod_logs_file | grep 'owner GID of' | sed 's/.*:\s//') 61 assert_equal "123" "$gid" 62 done 63 } 64 65 teardown() { 66 # Debugging information 67 kubectl describe "pod/$pod_name" 68 69 kubectl delete pod "$pod_name" 70 71 [ ! -f "$pod_logs_file" ] || rm -f "$pod_logs_file" 72 }