github.com/percona/percona-xtradb-cluster-operator@v1.14.0/e2e-tests/haproxy/run (about) 1 #!/bin/bash 2 3 set -o errexit 4 5 test_default_replicas_service() { 6 kpatch_delete_field pxc $1 "/spec/haproxy/exposeReplicas" && sleep 1 7 compare_kubectl "service/$1-haproxy-replicas" 8 } 9 10 test_disable_replicas_service() { 11 kpatch_set_field pxc $1 "/spec/haproxy/exposeReplicas" {} && sleep 1 12 kpatch_set_field pxc $1 "/spec/haproxy/exposeReplicas/enabled" false && sleep 1 13 wait_for_delete "svc/$1-haproxy-replicas" 14 (kubectl_bin get svc "$1-haproxy-replicas" || :) 2>&1 | grep -e "not found$" >/dev/null 15 } 16 17 test_enable_replicas_service() { 18 kpatch_set_field pxc $1 "/spec/haproxy/exposeReplicas/enabled" true && sleep 1 19 compare_kubectl "service/$1-haproxy-replicas" 20 } 21 22 test_dir=$(realpath $(dirname $0)) 23 . ${test_dir}/../functions 24 25 set_debug 26 27 fail_pod() { 28 local pod=$1 29 30 yq eval ' 31 .metadata.name = "chaos-pod-failure" | 32 del(.spec.selector.pods.test-namespace) | 33 .spec.selector.pods.'$namespace'[0] = "'$pod'"' $conf_dir/chaos-pod-failure.yml \ 34 | kubectl apply -f - 35 36 sleep 20 37 38 } 39 40 check_haproxy_writer() { 41 for i in $(seq 0 2); do 42 local haproxy_pod_ip=$(kubectl_bin get pods $cluster-haproxy-$i -o jsonpath='{.status.podIP}') 43 run_mysql "SHOW VARIABLES LIKE 'server_id'" "-h $haproxy_pod_ip -uroot -proot_password" >"/$tmp_dir/server_id_$i.sql" 44 done 45 for i in $(seq 0 1); do 46 diff -u "/$tmp_dir/server_id_$i.sql" "/$tmp_dir/server_id_$((i + 1)).sql" 47 done 48 } 49 50 main() { 51 create_infra $namespace 52 deploy_chaos_mesh $namespace 53 54 if version_gt "1.24"; then 55 apply_config "$test_dir/conf/container-rc.yaml" 56 elif version_gt "1.19" && [ $EKS -ne 1 ]; then 57 apply_config "$test_dir/conf/container-rc.yaml" 58 else 59 apply_config "$test_dir/conf/docker-rc.yaml" 60 fi 61 62 desc 'create first PXC cluster with HAProxy' 63 cluster="haproxy" 64 spinup_pxc "$cluster" "$test_dir/conf/$cluster.yml" 3 10 65 66 desc 'checking all haproxy pods point to the same writer' 67 wait_for_running "$cluster-pxc" 3 68 wait_cluster_consistency "$cluster" 3 3 69 check_haproxy_writer 70 71 desc 'check for passwords leak' 72 check_passwords_leak 73 74 desc 'delete active writer and checking all haproxy pods still point to the same writer' 75 desc 'fail pxc-pod-0 pod for 60s' 76 fail_pod $cluster-pxc-0 77 kubectl_bin get pods 78 check_haproxy_writer 79 wait_for_running "$cluster-pxc" 3 80 81 desc 'check advanced options are enabled in haproxy statefulset' 82 compare_kubectl pdb/$cluster-haproxy 83 compare_kubectl statefulset/$cluster-haproxy 84 85 desc 'default haproxy-replicas service' 86 test_default_replicas_service $cluster 87 88 desc 'disable haproxy-replicas service' 89 test_disable_replicas_service $cluster 90 91 desc 'enable haproxy-replicas service' 92 test_enable_replicas_service $cluster 93 94 wait_for_running "$cluster-haproxy" 3 95 96 kubectl_bin exec haproxy-haproxy-0 -c haproxy -it -- bash -c 'echo "show info" | socat stdio unix-connect:/etc/haproxy/pxc/haproxy.sock' \ 97 | grep "Maxconn:" >"$tmp_dir"/haproxy_maxconn.txt 98 diff --strip-trailing-cr "$tmp_dir"/haproxy_maxconn.txt "$test_dir"/compare/haproxy_maxconn.txt 99 100 apply_config "$test_dir/conf/config-secret-haproxy.yaml" 101 wait_cluster_consistency "$cluster" 3 3 102 compare_kubectl statefulset/$cluster-haproxy "-secret" 103 kubectl_bin exec haproxy-haproxy-0 -c haproxy -it -- bash -c 'echo "show info" | socat stdio unix-connect:/etc/haproxy/pxc/haproxy.sock' \ 104 | grep "Maxconn:" >"$tmp_dir"/haproxy_maxconn.txt 105 diff --strip-trailing-cr "$tmp_dir"/haproxy_maxconn.txt "$test_dir"/compare/haproxy_maxconn-secret.txt 106 107 desc 'clean up' 108 destroy_chaos_mesh 109 destroy $namespace 110 desc "test passed" 111 } 112 113 main