github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-job.bats (about) 1 #!/usr/bin/env bats 2 # 3 # Copyright (c) 2019 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 get_pod_config_dir 13 } 14 15 @test "Run a job to completion" { 16 job_name="job-pi-test" 17 18 # Create job 19 kubectl apply -f "${pod_config_dir}/job.yaml" 20 21 # Verify job 22 kubectl describe jobs/"$job_name" | grep "SuccessfulCreate" 23 24 # List pods that belong to the job 25 pod_name=$(kubectl get pods --selector=job-name=$job_name --output=jsonpath='{.items[*].metadata.name}') 26 27 # Verify that the job is completed 28 cmd="kubectl get pods -o jsonpath='{.items[*].status.phase}' | grep Succeeded" 29 waitForProcess "$wait_time" "$sleep_time" "$cmd" 30 31 # Verify the output of the pod 32 pi_number="3.14" 33 kubectl logs "$pod_name" | grep "$pi_number" 34 } 35 36 teardown() { 37 kubectl delete pod "$pod_name" 38 # Verify that pod is not running 39 run kubectl get pods 40 echo "$output" 41 [[ "$output" =~ "No resources found" ]] 42 43 44 kubectl delete jobs/"$job_name" 45 # Verify that the job is not running 46 run kubectl get jobs 47 echo "$output" 48 [[ "$output" =~ "No resources found" ]] 49 }