github.com/percona/percona-xtradb-cluster-operator@v1.14.0/e2e-tests/default-cr/run (about) 1 #!/bin/bash 2 3 set -o errexit 4 5 test_dir=$(realpath $(dirname $0)) 6 deploy_dir=$(realpath $(dirname $0)/../../deploy) 7 . ${test_dir}/../functions 8 9 set_debug 10 11 function stop_cluster() { 12 local cluster_name=$1 13 local max_wait_time=${2:-120} 14 15 local passed_time=0 16 local sleep_time=1 17 kubectl_bin patch pxc ${cluster_name} --type json -p='[{"op":"add","path":"/spec/pause","value":true}]' 18 set +x 19 echo -n 'Waiting for cluster stop' 20 until [[ $(kubectl_bin get pxc ${cluster_name} -o jsonpath='{.status.ready}') -le 0 ]]; do 21 echo -n . 22 let passed_time="${passed_time}+${sleep_time}" 23 sleep ${sleep_time} 24 if [[ ${passed_time} -gt ${max_wait_time} ]]; then 25 echo "We've been waiting for cluster stop for too long. Exiting..." 26 exit 1 27 fi 28 done 29 echo 30 set -x 31 } 32 33 function start_cluster() { 34 local cluster_name=$1 35 36 kubectl_bin patch pxc ${cluster_name} --type json -p='[{"op":"add","path":"/spec/pause","value":false}]' 37 wait_cluster_consistency \ 38 ${cluster_name} \ 39 $(kubectl_bin get pxc/${cluster_name} -o jsonpath={.spec.pxc.size}) \ 40 $(kubectl_bin get pxc/${cluster_name} -o jsonpath={.spec.$(get_proxy_engine ${cluster_name}).size}) 41 } 42 43 function main() { 44 create_infra "${namespace}" 45 46 cluster="$(yq eval '.metadata.name' ${deploy_dir}/cr.yaml)" 47 48 kubectl_bin apply -f ${deploy_dir}/secrets.yaml 49 kubectl_bin apply -f ${conf_dir}/client.yml 50 kubectl_bin apply -f ${conf_dir}/secrets.yml 51 kubectl_bin apply -f ${deploy_dir}/cr.yaml 52 53 pxc_size=$(kubectl_bin get pxc/${cluster} -o jsonpath={.spec.pxc.size}) 54 proxy_size=$(kubectl_bin get pxc/${cluster} -o jsonpath={.spec.$(get_proxy_engine ${cluster}).size}) 55 56 wait_for_running "$(get_proxy ${cluster})" ${proxy_size} 57 wait_for_running "${cluster}-pxc" ${pxc_size} 58 59 desc 'check if service and statefulset created with expected config' 60 compare_kubectl statefulset/${cluster}-pxc 61 compare_kubectl statefulset/$(get_proxy ${cluster}) 62 compare_kubectl service/${cluster}-pxc 63 compare_kubectl service/${cluster}-pxc-unready 64 compare_kubectl service/$(get_proxy ${cluster}) 65 compare_kubectl service/$(get_proxy ${cluster})-replicas 66 67 desc 'install PMM Server' 68 deploy_pmm_server 69 sleep 120 70 ADMIN_PASSWORD=$(kubectl_bin exec monitoring-0 -- bash -c "printenv | grep ADMIN_PASSWORD | cut -d '=' -f2") 71 MONITORING_ENDPOINT=$(get_service_endpoint monitoring-service) 72 API_KEY=$(curl --insecure -X POST -H "Content-Type: application/json" -d '{"name":"operator", "role": "Admin"}' "https://admin:$ADMIN_PASSWORD@$MONITORING_ENDPOINT/graph/api/auth/keys" | jq .key) 73 74 kubectl_bin patch secret ${cluster}-secrets --type merge --patch '{"stringData": {"pmmserverkey": '$API_KEY'}}' 75 76 sleep 20 77 desc "enable pmm" 78 kubectl_bin patch pxc/${cluster} --type=merge --patch '{ 79 "spec": {"pmm":{"enabled":true}} 80 }' 81 sleep 120 82 # since pxc cluster won't work without pmm server running consistency check would be enough 83 wait_cluster_consistency ${cluster} ${pxc_size} ${proxy_size} 84 85 desc "disable pmm" 86 kubectl_bin patch pxc/${cluster} --type=merge --patch '{ 87 "spec": {"pmm":{"enabled":false}} 88 }' 89 sleep 120 90 helm uninstall monitoring 91 wait_cluster_consistency ${cluster} ${pxc_size} ${proxy_size} 92 93 desc 'write data directly, read from all' 94 run_mysql \ 95 "CREATE DATABASE IF NOT EXISTS myApp; use myApp; CREATE TABLE IF NOT EXISTS myApp (id int PRIMARY KEY);" \ 96 "-h ${cluster}-pxc-2.${cluster}-pxc -uroot -proot_password" 97 run_mysql \ 98 'INSERT myApp.myApp (id) VALUES (100501)' \ 99 "-h ${cluster}-pxc-2.${cluster}-pxc -uroot -proot_password" 100 sleep 20 101 102 for i in $(seq 0 $((pxc_size - 1))); do 103 compare_mysql_cmd "select-2" "SELECT * from myApp.myApp;" "-h ${cluster}-pxc-${i}.${cluster}-pxc -uroot -proot_password" 104 done 105 desc "stop cluster" 106 stop_cluster ${cluster} 107 desc "start cluster" 108 start_cluster ${cluster} 109 wait_cluster_consistency ${cluster} ${pxc_size} ${proxy_size} 110 111 desc "compare data" 112 for i in $(seq 0 $((pxc_size - 1))); do 113 compare_mysql_cmd "select-2" "SELECT * from myApp.myApp;" "-h ${cluster}-pxc-${i}.${cluster}-pxc -uroot -proot_password" 114 done 115 116 kubectl_bin delete -f ${deploy_dir}/cr.yaml 117 desc "run cr-minimal" 118 cluster="$(yq eval '.metadata.name' ${deploy_dir}/cr-minimal.yaml)" 119 kubectl_bin apply -f ${deploy_dir}/cr-minimal.yaml 120 121 pxc_size=$(kubectl_bin get pxc/${cluster} -o jsonpath={.spec.pxc.size}) 122 proxy_size=$(kubectl_bin get pxc/${cluster} -o jsonpath={.spec.$(get_proxy_engine ${cluster}).size}) 123 124 wait_for_running "$(get_proxy ${cluster})" ${proxy_size} 125 wait_for_running "${cluster}-pxc" ${pxc_size} 126 127 desc 'check if service and statefulset created with expected config' 128 compare_kubectl statefulset/${cluster}-pxc 129 compare_kubectl statefulset/$(get_proxy ${cluster}) 130 compare_kubectl service/${cluster}-pxc 131 compare_kubectl service/${cluster}-pxc-unready 132 compare_kubectl service/$(get_proxy ${cluster}) 133 compare_kubectl service/$(get_proxy ${cluster})-replicas 134 135 destroy $namespace 136 desc "test passed" 137 } 138 139 main