github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-attach-handlers.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 nginx_version=$(get_test_version "docker_images.nginx.version") 13 nginx_image="nginx:$nginx_version" 14 15 pod_name="handlers" 16 17 get_pod_config_dir 18 } 19 20 @test "Running with postStart and preStop handlers" { 21 # Create yaml 22 sed -e "s/\${nginx_version}/${nginx_image}/" \ 23 "${pod_config_dir}/lifecycle-events.yaml" > "${pod_config_dir}/test-lifecycle-events.yaml" 24 25 # Create the pod with postStart and preStop handlers 26 kubectl create -f "${pod_config_dir}/test-lifecycle-events.yaml" 27 28 # Check pod creation 29 kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name 30 31 # Check postStart message 32 display_message="cat /usr/share/message" 33 check_postStart=$(kubectl exec $pod_name -- sh -c "$display_message" | grep "Hello from the postStart handler") 34 } 35 36 teardown(){ 37 # Debugging information 38 kubectl describe "pod/$pod_name" 39 40 rm -f "${pod_config_dir}/test-lifecycle-events.yaml" 41 kubectl delete pod "$pod_name" 42 }