github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/kubernetes/k8s-expose-ip.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 # Test that IP addresses/connections of PODS are routed/exposed correctly 9 # via a loadbalancer service. 10 # 11 # This test is temporarily turned off on ARM CI. 12 # See detailed info in PR#2157(https://github.com/kata-containers/tests/pull/2157) 13 14 load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh" 15 load "${BATS_TEST_DIRNAME}/tests_common.sh" 16 17 setup() { 18 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 19 deployment="hello-world" 20 service="my-service" 21 agnhost_name=$(get_test_version "container_images.agnhost.name") 22 agnhost_version=$(get_test_version "container_images.agnhost.version") 23 24 get_pod_config_dir 25 } 26 27 @test "Expose IP Address" { 28 29 # Create deployment 30 sed -e "s#\${agnhost_image}#${agnhost_name}:${agnhost_version}#" \ 31 "${pod_config_dir}/deployment-expose-ip.yaml" |\ 32 kubectl create -f - 33 34 # Check deployment creation 35 cmd="kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}" 36 waitForProcess "$wait_time" "$sleep_time" "$cmd" 37 38 # Check pods are running 39 cmd="kubectl get pods -o jsonpath='{.items[*].status.phase}' | grep Running" 40 waitForProcess "$wait_time" "$sleep_time" "$cmd" 41 42 # Expose deployment 43 kubectl expose deployment/${deployment} --type=LoadBalancer --name=${service} 44 45 # There appears to be no easy way to formally wait for a loadbalancer service 46 # to become 'ready' - there is no service.status.condition field to wait on. 47 48 # Now obtain the local IP:port pair of the loadbalancer service and ensure 49 # we can curl from it, and get the expected result 50 svcip=$(kubectl get service ${service} -o=json | jq '.spec.clusterIP' | sed 's/"//g') 51 svcport=$(kubectl get service ${service} -o=json | jq '.spec.ports[].port') 52 # And check we can curl the expected response from that IP address 53 echo_msg="hello,world" 54 cmd="curl http://$svcip:$svcport/echo?msg=${echo_msg} | grep \"$echo_msg\"" 55 56 waitForProcess "$wait_time" "$sleep_time" "$cmd" 57 58 # NOTE - we do not test the 'public IP' address of the node balancer here as 59 # that may not be set up, as it may require an IP/DNS allocation and local 60 # routing and firewall rules to access. 61 } 62 63 teardown() { 64 kubectl delete services ${service} 65 kubectl delete deployment ${deployment} 66 }