github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-oom.bats (about)

     1  #!/usr/bin/env bats
     2  #
     3  # Copyright (c) 2020 Ant Group
     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="pod-oom"
    13  	get_pod_config_dir
    14  }
    15  
    16  @test "Test OOM events for pods" {
    17  
    18  	# Create test .yaml
    19  	sed \
    20  		-e "s|\${stress_image}|${stress_image}|" \
    21  		-e "s/\${stress_image_pull_policy}/${stress_image_pull_policy}/" \
    22  		"${pod_config_dir}/pod-oom.yaml" > "${pod_config_dir}/test_pod_oom.yaml"
    23  
    24  	# Create pod
    25  	kubectl create -f "${pod_config_dir}/test_pod_oom.yaml"
    26  
    27  	# Check pod creation
    28  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
    29  
    30  	# Check if OOMKilled
    31  	cmd="kubectl get pods "$pod_name" -o yaml | yq r - 'status.containerStatuses[0].state.terminated.reason' | grep OOMKilled"
    32  
    33  	waitForProcess "$wait_time" "$sleep_time" "$cmd"
    34  
    35  	rm -f "${pod_config_dir}/test_pod_oom.yaml"
    36  }
    37  
    38  teardown() {
    39  	# Debugging information
    40  	kubectl describe "pod/$pod_name"
    41  	kubectl get "pod/$pod_name" -o yaml
    42  
    43  	kubectl delete pod "$pod_name"
    44  }