github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/integration/kubernetes/k8s-replication.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 nginx_version=$(get_test_version "docker_images.nginx.version") 13 nginx_image="nginx:$nginx_version" 14 15 get_pod_config_dir 16 } 17 18 @test "Replication controller" { 19 replication_name="replicationtest" 20 21 # Create yaml 22 sed -e "s/\${nginx_version}/${nginx_image}/" \ 23 "${pod_config_dir}/replication-controller.yaml" > "${pod_config_dir}/test-replication-controller.yaml" 24 25 # Create replication controller 26 kubectl create -f "${pod_config_dir}/test-replication-controller.yaml" 27 28 # Check replication controller 29 local cmd="kubectl describe replicationcontrollers/$replication_name | grep replication-controller" 30 waitForProcess "$wait_time" "$sleep_time" "$cmd" 31 32 number_of_replicas=$(kubectl get replicationcontrollers/"$replication_name" \ 33 --output=jsonpath='{.spec.replicas}') 34 [ "${number_of_replicas}" -gt 0 ] 35 36 # The replicas pods can be in running, waiting, succeeded or failed 37 # status. We need them all on running state before proceed. 38 cmd="kubectl describe rc/\"${replication_name}\"" 39 cmd+="| grep \"Pods Status\" | grep \"${number_of_replicas} Running\"" 40 waitForProcess "$wait_time" "$sleep_time" "$cmd" 41 42 # Check number of pods created for the 43 # replication controller is equal to the 44 # number of replicas that we defined 45 launched_pods=($(kubectl get pods --selector=app=nginx-rc-test \ 46 --output=jsonpath={.items..metadata.name})) 47 [ "${#launched_pods[@]}" -eq "$number_of_replicas" ] 48 49 # Check pod creation 50 for pod_name in ${launched_pods[@]}; do 51 cmd="kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name" 52 waitForProcess "$wait_time" "$sleep_time" "$cmd" 53 done 54 } 55 56 teardown() { 57 # Debugging information 58 kubectl describe replicationcontrollers/"$replication_name" 59 60 rm -f "${pod_config_dir}/test-replication-controller.yaml" 61 kubectl delete rc "$replication_name" 62 }