github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/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  	pod_name="sharevol-kata"
    22  	get_pod_config_dir
    23  	pod_logs_file=""
    24  }
    25  
    26  @test "Empty dir volumes" {
    27  	# Create the pod
    28  	kubectl create -f "${pod_config_dir}/pod-empty-dir.yaml"
    29  
    30  	# Check pod creation
    31  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
    32  
    33  	# Check volume mounts
    34  	cmd="mount | grep cache"
    35  	kubectl exec $pod_name -- sh -c "$cmd" | grep "/tmp/cache type tmpfs"
    36  
    37  	# Check it can write up to the volume limit (50M)
    38  	cmd="dd if=/dev/zero of=/tmp/cache/file1 bs=1M count=50; echo $?"
    39  	kubectl exec $pod_name -- sh -c "$cmd" | tail -1 | grep 0
    40  }
    41  
    42  @test "Empty dir volume when FSGroup is specified with non-root container" {
    43  	# 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
    44  	pod_file="${pod_config_dir}/pod-empty-dir-fsgroup.yaml"
    45  	agnhost_name=$(get_test_version "container_images.agnhost.name")
    46  	agnhost_version=$(get_test_version "container_images.agnhost.version")
    47  	image="${agnhost_name}:${agnhost_version}"
    48  
    49  	# Try to avoid timeout by prefetching the image.
    50  	crictl_pull "$image"
    51  	sed -e "s#\${agnhost_image}#${image}#" "$pod_file" |\
    52  		kubectl create -f -
    53  	cmd="kubectl get pods ${pod_name} | grep Completed"
    54  	waitForProcess "${wait_time}" "${sleep_time}" "${cmd}"
    55  
    56  	pod_logs_file="$(mktemp)"
    57  	for container in mounttest-container mounttest-container-2; do
    58  		kubectl logs "$pod_name" "$container" > "$pod_logs_file"
    59  		# Check owner UID of file
    60  		uid=$(cat $pod_logs_file | grep 'owner UID of' | sed 's/.*:\s//')
    61  		assert_equal "1001" "$uid"
    62  		# Check owner GID of file
    63  		gid=$(cat $pod_logs_file | grep 'owner GID of' | sed 's/.*:\s//')
    64  		assert_equal "123" "$gid"
    65  	done
    66  }
    67  
    68  teardown() {
    69  	# Debugging information
    70  	kubectl describe "pod/$pod_name"
    71  
    72  	kubectl delete pod "$pod_name"
    73  
    74  	[ ! -f "$pod_logs_file" ] || rm -f "$pod_logs_file"
    75  }