github.com/kata-containers/tests@v0.0.0-20240307153542-772105b56064/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 deployment="hello-world" 19 service="my-service" 20 agnhost_name=$(get_test_version "container_images.agnhost.name") 21 agnhost_version=$(get_test_version "container_images.agnhost.version") 22 23 get_pod_config_dir 24 } 25 26 @test "Expose IP Address" { 27 28 # Create deployment 29 sed -e "s#\${agnhost_image}#${agnhost_name}:${agnhost_version}#" \ 30 "${pod_config_dir}/deployment-expose-ip.yaml" |\ 31 kubectl create -f - 32 33 # Check deployment creation 34 cmd="kubectl wait --for=condition=Available --timeout=$timeout deployment/${deployment}" 35 waitForProcess "$wait_time" "$sleep_time" "$cmd" 36 37 # Check pods are running 38 cmd="kubectl get pods -o jsonpath='{.items[*].status.phase}' | grep Running" 39 waitForProcess "$wait_time" "$sleep_time" "$cmd" 40 41 # Expose deployment 42 kubectl expose deployment/${deployment} --type=LoadBalancer --name=${service} 43 44 # There appears to be no easy way to formally wait for a loadbalancer service 45 # to become 'ready' - there is no service.status.condition field to wait on. 46 47 # Now obtain the local IP:port pair of the loadbalancer service and ensure 48 # we can curl from it, and get the expected result 49 svcip=$(kubectl get service ${service} -o=json | jq '.spec.clusterIP' | sed 's/"//g') 50 svcport=$(kubectl get service ${service} -o=json | jq '.spec.ports[].port') 51 # And check we can curl the expected response from that IP address 52 echo_msg="hello,world" 53 cmd="curl http://$svcip:$svcport/echo?msg=${echo_msg} | grep \"$echo_msg\"" 54 55 waitForProcess "$wait_time" "$sleep_time" "$cmd" 56 57 # NOTE - we do not test the 'public IP' address of the node balancer here as 58 # that may not be set up, as it may require an IP/DNS allocation and local 59 # routing and firewall rules to access. 60 } 61 62 teardown() { 63 kubectl delete services ${service} 64 kubectl delete deployment ${deployment} 65 }