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