github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-projected-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  
    11  setup() {
    12  	[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}"
    13  
    14  	get_pod_config_dir
    15  }
    16  
    17  @test "Projected volume" {
    18  	[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}"
    19  
    20  	password="1f2d1e2e67df"
    21  	username="admin"
    22  	pod_name="test-projected-volume"
    23  
    24  	TMP_FILE=$(mktemp username.XXXX)
    25  	SECOND_TMP_FILE=$(mktemp password.XXXX)
    26  
    27  	# Create files containing the username and password
    28  	echo "$username" > $TMP_FILE
    29  	echo "$password" > $SECOND_TMP_FILE
    30  
    31  	# Package these files into secrets
    32  	kubectl create secret generic user --from-file=$TMP_FILE
    33  	kubectl create secret generic pass --from-file=$SECOND_TMP_FILE
    34  
    35  	# Create pod
    36  	kubectl create -f "${pod_config_dir}/pod-projected-volume.yaml"
    37  
    38  	# Check pod creation
    39  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
    40  
    41  	# Check that the projected sources exists
    42  	cmd="ls /projected-volume | grep username"
    43  	kubectl exec $pod_name -- sh -c "$cmd"
    44  	sec_cmd="ls /projected-volume | grep password"
    45  	kubectl exec $pod_name -- sh -c "$sec_cmd"
    46  
    47  	# Check content of the projected sources
    48  	check_cmd="cat /projected-volume/username*"
    49  	kubectl exec $pod_name -- sh -c "$check_cmd" | grep "$username"
    50  	sec_check_cmd="cat /projected-volume/password*"
    51  	kubectl exec $pod_name -- sh -c "$sec_check_cmd" | grep "$password"
    52  }
    53  
    54  teardown() {
    55  	[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}"
    56  
    57  	# Debugging information
    58  	kubectl describe "pod/$pod_name"
    59  
    60  	rm -f $TMP_FILE $SECOND_TMP_FILE
    61  	kubectl delete pod "$pod_name"
    62  	kubectl delete secret pass user
    63  }