github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-credentials-secrets.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 "Credentials using secrets" {
    18  	[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}"
    19  
    20  	secret_name="test-secret"
    21  	pod_name="secret-test-pod"
    22  	second_pod_name="secret-envars-test-pod"
    23  
    24  	# Create the secret
    25  	kubectl create -f "${pod_config_dir}/inject_secret.yaml"
    26  
    27  	# View information about the secret
    28  	kubectl get secret "${secret_name}" -o yaml | grep "type: Opaque"
    29  
    30  	# Create a pod that has access to the secret through a volume
    31  	kubectl create -f "${pod_config_dir}/pod-secret.yaml"
    32  
    33  	# Check pod creation
    34  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
    35  
    36  	# List the files
    37  	cmd="ls /tmp/secret-volume"
    38  	kubectl exec $pod_name -- sh -c "$cmd" | grep -w "password"
    39  	kubectl exec $pod_name -- sh -c "$cmd" | grep -w "username"
    40  
    41  	# Create a pod that has access to the secret data through environment variables
    42  	kubectl create -f "${pod_config_dir}/pod-secret-env.yaml"
    43  
    44  	# Check pod creation
    45  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$second_pod_name"
    46  
    47  	# Display environment variables
    48  	second_cmd="printenv"
    49  	kubectl exec $second_pod_name -- sh -c "$second_cmd" | grep -w "SECRET_USERNAME"
    50  	kubectl exec $second_pod_name -- sh -c "$second_cmd" | grep -w "SECRET_PASSWORD"
    51  }
    52  
    53  teardown() {
    54  	[ "${KATA_HYPERVISOR}" == "firecracker" ] && skip "test not working see: ${fc_limitations}"
    55  
    56  	# Debugging information
    57  	kubectl describe "pod/$pod_name"
    58  	kubectl describe "pod/$second_pod_name"
    59  
    60  	kubectl delete pod "$pod_name" "$second_pod_name"
    61  	kubectl delete secret "$secret_name"
    62  }