github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/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 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 13 pod_name="memory-test" 14 get_pod_config_dir 15 } 16 17 @test "Exceeding memory constraints" { 18 memory_limit_size="50Mi" 19 allocated_size="250M" 20 # Create test .yaml 21 sed \ 22 -e "s/\${memory_size}/${memory_limit_size}/" \ 23 -e "s/\${memory_allocated}/${allocated_size}/" \ 24 "${pod_config_dir}/pod-memory-limit.yaml" > "${pod_config_dir}/test_exceed_memory.yaml" 25 26 # Create the pod exceeding memory constraints 27 run kubectl create -f "${pod_config_dir}/test_exceed_memory.yaml" 28 [ "$status" -ne 0 ] 29 30 rm -f "${pod_config_dir}/test_exceed_memory.yaml" 31 } 32 33 @test "Running within memory constraints" { 34 memory_limit_size="600Mi" 35 allocated_size="150M" 36 # Create test .yaml 37 sed \ 38 -e "s/\${memory_size}/${memory_limit_size}/" \ 39 -e "s/\${memory_allocated}/${allocated_size}/" \ 40 "${pod_config_dir}/pod-memory-limit.yaml" > "${pod_config_dir}/test_within_memory.yaml" 41 42 # Create the pod within memory constraints 43 kubectl create -f "${pod_config_dir}/test_within_memory.yaml" 44 45 # Check pod creation 46 kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" 47 48 rm -f "${pod_config_dir}/test_within_memory.yaml" 49 kubectl delete pod "$pod_name" 50 }