github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-memory.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="memory-test"
    13  	get_pod_config_dir
    14  }
    15  
    16  setup_yaml() {
    17  	sed \
    18  		-e "s/\${memory_size}/${memory_limit_size}/" \
    19  		-e "s/\${memory_allocated}/${allocated_size}/" \
    20  		-e "s|\${stress_image}|${stress_image}|" \
    21  		-e "s/\${stress_image_pull_policy}/${stress_image_pull_policy}/" \
    22  		"${pod_config_dir}/pod-memory-limit.yaml"
    23  }
    24  
    25  
    26  @test "Exceeding memory constraints" {
    27  	memory_limit_size="50Mi"
    28  	allocated_size="250M"
    29  	# Create test .yaml
    30  	setup_yaml > "${pod_config_dir}/test_exceed_memory.yaml"
    31  
    32  	# Create the pod exceeding memory constraints
    33  	run kubectl create -f "${pod_config_dir}/test_exceed_memory.yaml"
    34  	[ "$status" -ne 0 ]
    35  
    36  	rm -f "${pod_config_dir}/test_exceed_memory.yaml"
    37  }
    38  
    39  @test "Running within memory constraints" {
    40  	memory_limit_size="600Mi"
    41  	allocated_size="150M"
    42  	# Create test .yaml
    43  	setup_yaml > "${pod_config_dir}/test_within_memory.yaml"
    44  
    45  	# Create the pod within memory constraints
    46  	kubectl create -f "${pod_config_dir}/test_within_memory.yaml"
    47  
    48  	# Check pod creation
    49  	kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name"
    50  
    51  	rm -f "${pod_config_dir}/test_within_memory.yaml"
    52  	kubectl delete pod "$pod_name"
    53  }
    54  
    55  teardown() {
    56  	# Debugging information
    57  	kubectl describe "pod/$pod_name" || true
    58  }