github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-parallel.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  	get_pod_config_dir
    13  	job_name="jobtest"
    14  	names=( "test1" "test2" "test3" )
    15  }
    16  
    17  @test "Parallel jobs" {
    18  	# Create yaml files
    19  	for i in "${names[@]}"; do
    20  		sed "s/\$ITEM/$i/" ${pod_config_dir}/job-template.yaml > ${pod_config_dir}/job-$i.yaml
    21  	done
    22  
    23  	# Create the jobs
    24  	for i in "${names[@]}"; do
    25  		kubectl create -f "${pod_config_dir}/job-$i.yaml"
    26  	done
    27  
    28  	# Check the jobs
    29  	kubectl get jobs -l jobgroup=${job_name}
    30  
    31  	# Check the pods
    32  	kubectl wait --for=condition=Ready --timeout=$timeout pod -l jobgroup=${job_name}
    33  
    34  	# Check output of the jobs
    35  	for i in $(kubectl get pods -l jobgroup=${job_name} -o name); do
    36  		kubectl logs ${i}
    37  	done
    38  }
    39  
    40  teardown() {
    41  	# Delete jobs
    42  	kubectl delete jobs -l jobgroup=${job_name}
    43  
    44  	# Remove generated yaml files
    45  	for i in "${names[@]}"; do
    46  		rm -f ${pod_config_dir}/job-$i.yaml
    47  	done
    48  }