github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/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 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 16 get_pod_config_dir 17 } 18 19 @test "Replication controller" { 20 replication_name="replicationtest" 21 number_of_replicas="1" 22 23 # Create yaml 24 sed -e "s/\${nginx_version}/${nginx_image}/" \ 25 "${pod_config_dir}/replication-controller.yaml" > "${pod_config_dir}/test-replication-controller.yaml" 26 27 # Create replication controller 28 kubectl create -f "${pod_config_dir}/test-replication-controller.yaml" 29 30 # Check replication controller 31 kubectl describe replicationcontrollers/"$replication_name" | grep "replication-controller" 32 33 # Check pod creation 34 pod_name=$(kubectl get pods --output=jsonpath={.items..metadata.name}) 35 cmd="kubectl wait --for=condition=Ready --timeout=$timeout pod $pod_name" 36 waitForProcess "$wait_time" "$sleep_time" "$cmd" 37 38 # Check number of pods created for the 39 # replication controller is equal to the 40 # number of replicas that we defined 41 launched_pods=$(echo $pod_name | wc -l) 42 43 [ "$launched_pods" -eq "$number_of_replicas" ] 44 } 45 46 teardown() { 47 rm -f "${pod_config_dir}/test-replication-controller.yaml" 48 kubectl delete pod "$pod_name" 49 kubectl delete rc "$replication_name" 50 }