github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/integration/kubernetes/k8s-port-forward.bats (about) 1 #!/usr/bin/env bats 2 # 3 # Copyright (c) 2019 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 7 load "${BATS_TEST_DIRNAME}/../../.ci/lib.sh" 8 load "${BATS_TEST_DIRNAME}/tests_common.sh" 9 source "/etc/os-release" || source "/usr/lib/os-release" 10 11 issue="https://github.com/kata-containers/runtime/issues/1834" 12 13 setup() { 14 skip "test not working see: ${issue}" 15 export KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}" 16 get_pod_config_dir 17 } 18 19 @test "Port forwarding" { 20 skip "test not working see: ${issue}" 21 deployment_name="redis-master" 22 23 # Create deployment 24 kubectl apply -f "${pod_config_dir}/redis-master-deployment.yaml" 25 26 # Check deployment 27 kubectl wait --for=condition=Available --timeout=$timeout deployment/"$deployment_name" 28 kubectl expose deployment/"$deployment_name" 29 30 # Get pod name 31 pod_name=$(kubectl get pods --output=jsonpath={.items..metadata.name}) 32 kubectl wait --for=condition=Ready --timeout=$timeout pod "$pod_name" 33 34 # View replicaset 35 kubectl get rs 36 37 # Create service 38 kubectl apply -f "${pod_config_dir}/redis-master-service.yaml" 39 40 # Check service 41 kubectl get svc | grep redis 42 43 # Check redis service 44 port_redis=$(kubectl get pods $pod_name --template='{{(index (index .spec.containers 0).ports 0).containerPort}}{{"\n"}}') 45 46 # Verify that redis is running in the pod and listening on port 47 port=6379 48 [ "$port_redis" -eq "$port" ] 49 50 # Forward a local port to a port on the pod 51 (2&>1 kubectl port-forward "$pod_name" 7000:"$port"> /dev/null) & 52 53 # Run redis-cli 54 retries="10" 55 ok="0" 56 57 for _ in $(seq 1 "$retries"); do 58 if sudo -E redis-cli -p 7000 ping | grep -q "PONG" ; then 59 ok="1" 60 break; 61 fi 62 sleep 1 63 done 64 65 [ "$ok" -eq "1" ] 66 } 67 68 teardown() { 69 skip "test not working see: ${issue}" 70 kubectl delete -f "${pod_config_dir}/redis-master-deployment.yaml" 71 kubectl delete -f "${pod_config_dir}/redis-master-service.yaml" 72 }