github.com/percona/percona-xtradb-cluster-operator@v1.14.0/e2e-tests/cross-site/run (about) 1 #!/bin/bash 2 3 set -o errexit 4 5 test_dir=$(realpath $(dirname $0)) 6 . ${test_dir}/../functions 7 8 set_debug 9 10 if [[ $IMAGE_PXC =~ 5\.7 ]]; then 11 echo "Skipping cross-site test because 5.7 doesn't support it!" 12 exit 0 13 fi 14 15 main() { 16 local source_cluster="cross-site-source" 17 local replica_cluster="cross-site-replica" 18 desc "Create source cluster" 19 20 create_infra ${namespace} 21 start_minio 22 apply_secrets 23 spinup_pxc "$source_cluster" "$test_dir/conf/$source_cluster.yml" 24 sleep 60 25 desc "get main cluster services endpoints" 26 source_endpoint0=$(get_service_ip ${source_cluster}-pxc-0) 27 source_endpoint1=$(get_service_ip ${source_cluster}-pxc-1) 28 source_endpoint2=$(get_service_ip ${source_cluster}-pxc-2) 29 30 source_primary=$(run_mysql 'SELECT @@hostname hostname;' "-h ${source_cluster}-haproxy -p33062 -uroot -proot_password") 31 source_primary_endpoint=$(get_service_ip ${source_primary}) 32 desc "patch source cluster with replicationChannels settings" 33 kubectl_bin patch pxc $source_cluster --type=merge --patch '{"spec": {"pxc":{"replicationChannels": [{"name":"source_to_replica", "isSource": true}]}}}' 34 desc "patch main cluster secrets with replication user" 35 kubectl_bin patch secret my-cluster-secrets -p '{"data":{"replication": "'$(echo -n new_password | base64)'"}}' 36 sleep 15 37 wait_cluster_consistency "$source_cluster" 3 2 38 39 desc 'write data to source cluster' 40 run_mysql \ 41 'CREATE DATABASE IF NOT EXISTS myApp; use myApp; CREATE TABLE IF NOT EXISTS testSourceReplica (id int PRIMARY KEY);' \ 42 "-h $source_primary_endpoint -uroot -proot_password" 43 run_mysql \ 44 'INSERT myApp.testSourceReplica (id) VALUES (100700)' \ 45 "-h $source_primary_endpoint -uroot -proot_password" 46 47 kubectl_bin get secrets cross-site-source-ssl-internal -o yaml | yq 'del(.metadata)' - | yq '.metadata={"name": "cross-site-replica-ssl-internal"}' - >${tmp_dir}/replica-ssl-internal.yaml 48 49 desc "take backup of source cluster" 50 run_backup "$source_cluster" "backup-minio-source" 51 52 desc "create replica cluster" 53 54 create_namespace $replica_namespace 0 55 deploy_operator 56 kubectl_bin apply -f ${tmp_dir}/replica-ssl-internal.yaml 57 apply_secrets 58 spinup_pxc "$replica_cluster" "$test_dir/conf/$replica_cluster.yml" 59 sleep 60 60 61 desc "restore backup from source cluster" 62 destination=$(kubectl_bin get -n "${namespace}" pxc-backup backup-minio-source -o jsonpath='{.status.destination}') 63 cat "${test_dir}/conf/restore-backup-minio.yml" \ 64 | $sed -e "s~#cluster~${replica_cluster}~" \ 65 | $sed -e "s~#destination~${destination}~" \ 66 | $sed -e "s~minio-service.#namespace~minio-service.${namespace}~" \ 67 | kubectl_bin apply -f - 68 wait_cluster_consistency "$replica_cluster" 3 2 69 70 desc "get replica cluster services endpoints" 71 replica_endpoint0=$(get_service_ip ${replica_cluster}-pxc-0) 72 replica_endpoint1=$(get_service_ip ${replica_cluster}-pxc-1) 73 replica_endpoint2=$(get_service_ip ${replica_cluster}-pxc-2) 74 replica_primary=$(run_mysql 'SELECT @@hostname hostname;' "-h ${replica_cluster}-haproxy -p33062 -uroot -proot_password") 75 replica_primary_endpoint=$(get_service_ip ${replica_primary}) 76 77 run_mysql \ 78 'DELETE FROM myApp.myApp WHERE id=100500' \ 79 "-h $replica_primary_endpoint -uroot -proot_password" 80 81 desc "patch replica cluster with replicationChannels settings" 82 kubectl_bin patch pxc $replica_cluster --type=merge --patch '{"spec": {"pxc": {"replicationChannels":[{"name": "source_to_replica", "isSource": false, "configuration": {"ssl": true, "sslSkipVerify": true, "ca": "/etc/mysql/ssl-internal/ca.crt"}, "sourcesList": [{"host": "'${source_endpoint0}'", "port": 3306, "weight": 100},{"host": "'${source_endpoint1}'", "port": 3306, "weight": 100},{"host": "'${source_endpoint2}'", "port": 3306, "weight": 100}]}]}}}' 83 sleep 40 84 85 desc "patch replica cluster secrets with replication user" 86 kubectl_bin patch secret my-cluster-secrets -p '{"data":{"replication": "'$(echo -n new_password | base64)'"}}' 87 sleep 15 88 wait_cluster_consistency "$replica_cluster" 3 2 89 90 desc "Check replication works between source -> replica" 91 compare_mysql_cmd "select-2" "SELECT * from myApp.testSourceReplica;" "-h $replica_endpoint0 -uroot -proot_password" 92 compare_mysql_cmd "select-2" "SELECT * from myApp.testSourceReplica;" "-h $replica_endpoint1 -uroot -proot_password" 93 compare_mysql_cmd "select-2" "SELECT * from myApp.testSourceReplica;" "-h $replica_endpoint2 -uroot -proot_password" 94 95 run_backup "$replica_cluster" "backup-minio-replica" 96 97 desc "Switch clusters over" 98 kubectl_bin config set-context $(kubectl_bin config current-context) --namespace="$namespace" 99 100 desc "rebuild source cluster" 101 destination=$(kubectl_bin get -n "${replica_namespace}" pxc-backup backup-minio-replica -o jsonpath='{.status.destination}') 102 cat "${test_dir}/conf/restore-backup-minio.yml" \ 103 | $sed -e "s~#cluster~${source_cluster}~" \ 104 | $sed -e "s~#destination~${destination}~" \ 105 | $sed -e "s~minio-service.#namespace~minio-service.${namespace}~" \ 106 | kubectl_bin apply -f - 107 wait_cluster_consistency "$source_cluster" 3 2 108 109 run_mysql \ 110 'DELETE FROM myApp.myApp WHERE id=100500' \ 111 "-h $source_primary_endpoint -uroot -proot_password" 112 113 run_mysql \ 114 'DELETE FROM myApp.testSourceReplica WHERE id=100700' \ 115 "-h $source_primary_endpoint -uroot -proot_password" 116 117 desc "configure old replica as source" 118 kubectl patch pxc ${replica_cluster} -n ${replica_namespace} --type=json -p="[{'op': 'remove', 'path': '/spec/pxc/replicationChannels/0'}]" 119 kubectl_bin patch pxc ${replica_cluster} \ 120 -n ${replica_namespace} \ 121 --type=merge \ 122 --patch '{"spec": {"pxc": {"replicationChannels":[{"name": "replica_to_source", "isSource": true}]}}}' 123 124 desc "configure old source as replica" 125 kubectl patch pxc ${source_cluster} -n ${namespace} --type=json -p="[{'op': 'remove', 'path': '/spec/pxc/replicationChannels/0'}]" 126 kubectl_bin patch pxc ${source_cluster} \ 127 -n ${namespace} \ 128 --type=merge \ 129 --patch '{"spec": {"pxc": {"replicationChannels":[{"name": "replica_to_source", "isSource": false, "configuration": {"ssl": true, "sslSkipVerify": true, "ca": "/etc/mysql/ssl-internal/ca.crt"}, "sourcesList": [{"host": "'${replica_endpoint0}'", "port": 3306, "weight": 100},{"host": "'${replica_endpoint1}'", "port": 3306, "weight": 100},{"host": "'${replica_endpoint2}'", "port": 3306, "weight": 100}]}]}}}' 130 131 kubectl_bin config set-context $(kubectl_bin config current-context) --namespace="$replica_namespace" 132 desc "Write data to replica cluster" 133 run_mysql \ 134 'CREATE DATABASE IF NOT EXISTS myApp; use myApp; CREATE TABLE IF NOT EXISTS testReplicaSource (id int PRIMARY KEY);' \ 135 "-h $replica_primary_endpoint -uroot -proot_password" 136 run_mysql \ 137 'INSERT myApp.testReplicaSource (id) VALUES (100800)' \ 138 "-h $replica_primary_endpoint -uroot -proot_password" 139 140 sleep 15 141 142 desc "Check replication works between replica -> source" 143 kubectl_bin config set-context $(kubectl_bin config current-context) --namespace="$namespace" 144 compare_mysql_cmd "select-3" "SELECT * from myApp.testReplicaSource;" "-h $source_endpoint0 -uroot -proot_password" 145 compare_mysql_cmd "select-3" "SELECT * from myApp.testReplicaSource;" "-h $source_endpoint1 -uroot -proot_password" 146 compare_mysql_cmd "select-3" "SELECT * from myApp.testReplicaSource;" "-h $source_endpoint2 -uroot -proot_password" 147 148 destroy $namespace "true" 149 destroy $replica_namespace "true" 150 desc "test passed" 151 } 152 153 main