github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-pid-ns.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  	pod_name="busybox"
    13  	first_container_name="first-test-container"
    14  	second_container_name="second-test-container"
    15  
    16  	get_pod_config_dir
    17  }
    18  
    19  @test "Check PID namespaces" {
    20  	# Create the pod
    21  	kubectl create -f "${pod_config_dir}/busybox-pod.yaml"
    22  
    23  	# Check pod creation
    24  	kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name
    25  
    26  	# Check PID from first container
    27  	first_pid_container=$(kubectl exec $pod_name -c $first_container_name \
    28  		-- ps | grep "/pause")
    29  	# Verify that is not empty
    30  	check_first_pid=$(echo $first_pid_container | wc -l)
    31  	[ "$check_first_pid" == "1" ]
    32  
    33  	# Check PID from second container
    34  	second_pid_container=$(kubectl exec $pod_name -c $second_container_name \
    35  		-- ps | grep "/pause")
    36  	# Verify that is not empty
    37  	check_second_pid=$(echo $second_pid_container | wc -l)
    38  	[ "$check_second_pid" == "1" ]
    39  
    40  	[ "$first_pid_container" == "$second_pid_container" ]
    41  }
    42  
    43  teardown() {
    44  	# Debugging information
    45  	kubectl describe "pod/$pod_name"
    46  
    47  	kubectl delete pod "$pod_name"
    48  }