Skip to content

Commit e6e206b

Browse files
cap1984nmarukovichegegunestplavcicgithub-actions[bot]
authored
K8SPSMDB-885 - E2E tests - start mongod major upgrade from the lowest version (#1194)
* K8SPSMDB-794 release 1.14.0 * added missed tests * Update deploy/cr.yaml Co-authored-by: Ege Güneş <[email protected]> * update init image * update default mongo version * Add backup type into restore example for backupSource (#1170) * K8SPSMDB-769 update rs-shard-migration (#1172) * update rs-shard-migration * Update e2e-tests/rs-shard-migration/run Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * K8SPSMDB-873: Change HOME dir for mongosh (#1171) * K8SPSMDB-853: fix `version_test` unit-test (#1169) https://jira.percona.com/browse/K8SPSMDB-853 * Change HOME dir for mongosh. * K8SPSMDB-873 Force interpreter to incorporate variable in CLI call Bash tries to execute HOME=/tmp as a regular binary thus we need to trick it a bit. * Update build/ps-entry.sh Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: Andrii Dema <[email protected]> Co-authored-by: Ivan Pylypenko <[email protected]> Co-authored-by: Viacheslav Sarzhan <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * fix vault deployment for OpenShift (#1174) * fix vault deployment for openshift * Remove the unknown field * Adapt vault installation for Openshift --------- Co-authored-by: Ivan Pylypenko <[email protected]> * Fix for version-service semver channel name (#1182) * Fix for version-service semver channel name * Increase timeout a bit for openshift * Update some obsolete code * Fixing compare files for openshift (#1183) * Fixing compare files for openshift * Add some verification checks * Enhance debug processing section (#1186) * Use separate namespace for getting mongod version (#1184) * Use separete namespace for getting mongod version * Enabling debug processing and test files * K8SPSMDB-794 - Fix diff in demand-backup-eks-credentials test (#1187) * Update e2e-tests/functions Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * K8SPSMDB-878 - Fix EKS tests (#1188) * K8SPSMDB-878 - Fix upgrade-consistency test to check cluster readyness * K8SPSMDB-794 - Fix runtimeclass for EKS 1.24 * K8SPSMDB-713: Retry PBM describe-restore on failure (#1189) * K8SPSMDB-853: fix `version_test` unit-test (#1169) https://jira.percona.com/browse/K8SPSMDB-853 * Retry pbm describe-restore if necessary. --------- Co-authored-by: Andrii Dema <[email protected]> * K8SPSMDB-881 Force error exit on restore error (#1190) * Force error exit on restore error we should not wait any longer if the restore error happened * K8SPSMDB-881 Exit on backup error as well * fix cross-site-sharded (#1192) * K8SPSMDB-885 Always start from the lowest mongod version * K8SPSMDB-885 Make sure backup image is provided by version-service A dismal bug lead to a false conclusions regarding pbm functionality. It was caused by depending on static main-backup image instead the one from IMAGE_BACKUP. Also additional check for FCV inside mongo has been added * Update e2e-tests/mongod-major-upgrade-sharded/run Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update e2e-tests/mongod-major-upgrade/run Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update e2e-tests/mongod-major-upgrade-sharded/run Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update e2e-tests/mongod-major-upgrade/run Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * K8SPSMDB-885 Refactoring a bit Making sure only dynamic vs generation happen Enhance FCV value getting * K8SPSMDB-885 Add lines missing after resoving merge conflict * Fix mongod-major-upgrade test * Fix mongod-major-upgrade-sharded test --------- Co-authored-by: Natalia Marukovich <[email protected]> Co-authored-by: Natalia Marukovich <[email protected]> Co-authored-by: Ege Güneş <[email protected]> Co-authored-by: Tomislav Plavcic <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Inel Pandzic <[email protected]> Co-authored-by: Andrii Dema <[email protected]> Co-authored-by: Viacheslav Sarzhan <[email protected]> Co-authored-by: Tomislav Plavcic <[email protected]>
1 parent 60a7fca commit e6e206b

File tree

15 files changed

+105
-157
lines changed

15 files changed

+105
-157
lines changed

e2e-tests/functions

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,13 +1203,7 @@ check_crd_for_deletion() {
12031203
function get_mongod_ver_from_image() {
12041204
local image=${1}
12051205

1206-
local pod_name=${RANDOM}
1207-
kubectl_bin -n default run ${pod_name} --image=${image} --restart=Never --command -- sleep infinity >/dev/null
1208-
kubectl_bin -n default wait --for=condition=Ready pod/${pod_name} >/dev/null
1209-
1210-
local version_info=$(kubectl_bin -n default exec ${pod_name} -- mongod --version)
1211-
kubectl_bin -n default delete pod/${pod_name} --grace-period=0 --force >/dev/null
1212-
version_info=$(echo ${version_info} | head -n2 | $sed -r 's/^.*db version v(([0-9]+\.){2}[0-9]+-[0-9]+).*$/\1/g')
1206+
version_info=$(run_simple_cli_inside_image ${image} 'mongod --version' | $sed -r 's/^.*db version v(([0-9]+\.){2}[0-9]+-[0-9]+).*$/\1/g')
12131207

12141208
if [[ ! ${version_info} =~ ^([0-9]+\.){2}[0-9]+-[0-9]+$ ]]; then
12151209
printf "No mongod version obtained from %s. Exiting" ${image}
@@ -1218,6 +1212,52 @@ function get_mongod_ver_from_image() {
12181212
echo ${version_info}
12191213
}
12201214

1215+
function get_pbm_version() {
1216+
local image=${1}
1217+
1218+
local version_info=$(run_simple_cli_inside_image ${image} 'pbm-agent version' | $sed -r 's/^Version:\ (([0-9]+\.){2}[0-9]+)\ .*/\1/g')
1219+
1220+
if [[ ! ${version_info} =~ ^([0-9]+\.){2}[0-9]+$ ]]; then
1221+
printf "No pbm version obtained from %s. Exiting" ${image}
1222+
exit 1
1223+
fi
1224+
echo ${version_info}
1225+
}
1226+
1227+
function run_simple_cli_inside_image() {
1228+
local image=${1}
1229+
local cli=${2}
1230+
1231+
local pod_name=${RANDOM}
1232+
kubectl_bin -n default run ${pod_name} --image=${image} --restart=Never --command -- sleep infinity >/dev/null
1233+
kubectl_bin -n default wait --for=condition=Ready pod/${pod_name} >/dev/null
1234+
local output=$(kubectl_bin -n default exec ${pod_name} -- ${cli})
1235+
kubectl_bin -n default delete pod/${pod_name} --grace-period=0 --force >/dev/null
1236+
echo ${output}
1237+
}
1238+
1239+
function generate_vs_json() {
1240+
local template_path=${1}
1241+
local target_path=${2}
1242+
1243+
local version_service_source=$(jq '.versions[0].operator="'${OPERATOR_VERSION}'"' ${template_path})
1244+
1245+
for image_mongod in ${IMAGE_MONGOD_CHAIN[@]}; do
1246+
current_mongod_version=$(get_mongod_ver_from_image ${image_mongod})
1247+
1248+
version_service_source=$(echo ${version_service_source} \
1249+
| jq '.versions[0].matrix.mongod += {"'${current_mongod_version}'": {"image_path":"'${image_mongod}'","status":"recommended"}}')
1250+
done
1251+
1252+
version_service_source=$(echo ${version_service_source} \
1253+
| jq '.versions[0].matrix.backup += {"'$(get_pbm_version ${IMAGE_BACKUP})'": {"image_path":"'${IMAGE_BACKUP}'","status":"recommended"}}')
1254+
1255+
version_service_source=$(echo ${version_service_source} \
1256+
| jq '.versions[0].matrix.operator += {"'${OPERATOR_VERSION}'": {"image_path":"'${IMAGE}'","status":"recommended"}}')
1257+
1258+
echo ${version_service_source} | jq '.' >${target_path}
1259+
}
1260+
12211261
check_passwords_leak() {
12221262
secrets=$(kubectl_bin get secrets -o json | jq -r '.items[].data | to_entries | .[] | select(.key | (contains("_PASSWORD"))) | .value')
12231263
echo secrets=$secrets
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
switched to db myApp
2-
{ "_id" : , "x" : 100500 }
2+
{ "_id" : , "x" : 100501 }
33
{ "_id" : , "x" : 100502 }
44
bye
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
switched to db myApp
2-
{ "_id" : , "x" : 100500 }
2+
{ "_id" : , "x" : 100501 }
3+
{ "_id" : , "x" : 100502 }
34
{ "_id" : , "x" : 100503 }
45
bye
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
switched to db myApp
2-
{ "_id" : , "x" : 100500 }
2+
{ "_id" : , "x" : 100501 }
33
bye

e2e-tests/mongod-major-upgrade-sharded/conf/backup-minio.yml

Lines changed: 0 additions & 9 deletions
This file was deleted.

e2e-tests/mongod-major-upgrade-sharded/conf/operator.main.psmdb-operator.json

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,8 @@
1515
}
1616
},
1717
"backup": {
18-
"2.0.3": {
19-
"image_path": "perconalab/percona-server-mongodb-operator:main-backup",
20-
"image_hash": "01388bcc310de0190cad0c4cfbe8cf8edc07c5c7ea057edec137e8f58931696b",
21-
"status": "recommended",
22-
"critical": false
23-
}
2418
},
2519
"operator": {
26-
"1.14.0": {
27-
"image_path": "perconalab/percona-server-mongodb-operator:main",
28-
"image_hash": "e9ed11994cef3f7ab33e126484d5d5991cccc00b54d066183d1c7abe8e29b802",
29-
"status": "recommended",
30-
"critical": false
31-
}
3220
}
3321
}
3422
}

e2e-tests/mongod-major-upgrade-sharded/conf/restore.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

e2e-tests/mongod-major-upgrade-sharded/run

Lines changed: 25 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,6 @@ test_dir=$(realpath $(dirname $0))
77
. ${test_dir}/../functions
88
set_debug
99

10-
function generate_vs_json() {
11-
local template_path=${1}
12-
local target_path=${2}
13-
14-
local version_service_source=$(jq '.versions[0].operator="'${OPERATOR_VERSION}'"' ${template_path})
15-
16-
for image_mongod in ${IMAGE_MONGOD_CHAIN[@]}; do
17-
current_mongod_version=$(get_mongod_ver_from_image ${image_mongod})
18-
19-
version_service_source=$(echo ${version_service_source} \
20-
| jq '.versions[0].matrix.mongod += {"'${current_mongod_version}'": {"image_path":"'${image_mongod}'","status":"recommended"}}')
21-
done
22-
echo ${version_service_source} | jq '.' >${target_path}
23-
}
24-
2510
function main() {
2611
rbac="rbac"
2712
if [ -n "$OPERATOR_NS" ]; then
@@ -49,27 +34,16 @@ function main() {
4934
version_matrix=$(jq '.[] | .[] |.matrix.mongod' ${tmp_dir}/operator.${OPERATOR_VERSION}.psmdb-operator.json)
5035

5136
current_mongod_version=$(get_mongod_ver_from_image ${IMAGE_MONGOD})
52-
version_matrix=$(echo ${version_matrix} | jq '. += {"'${current_mongod_version}'":{"image_path":"'${IMAGE_MONGOD}'"}}')
37+
version_matrix=$(echo ${version_matrix} | jq '. += {"'${current_mongod_version}'":{"image_path":"'${IMAGE_MONGOD}'","status": "recommended"}}')
5338

5439
version_matrix=$(echo ${version_matrix} | jq 'to_entries
5540
| sort_by( .key | split("[[:punct:]]";"g") | map(tonumber) )
5641
| map({(.key): .value}) ')
5742

58-
current_version_index=$(echo ${version_matrix} | jq 'map(keys[] == "'${current_mongod_version}'") | index(true)')
59-
60-
if [[ $((current_version_index + 1)) == $(echo ${version_matrix} | jq length) ]]; then
61-
desc 'IMAGE_MONGOD '${IMAGE_MONGOD}' has '${current_mongod_version}' is the last in upgrade chain. Exiting...'
62-
destroy ${namespace}
63-
exit 0
64-
fi
65-
66-
version_matrix=$(echo ${version_matrix} | jq '.['$((current_version_index + 1))':]')
67-
68-
versions_to_verify=$(echo ${version_matrix} | jq -r '.[] | keys | .[] | split(".") | .[:2] | join(".")' | uniq | grep -v ${current_mongod_version:0:3})
69-
43+
versions_to_verify=$(echo ${version_matrix} | jq -r '.[] | keys | .[] | split(".") | .[:2] | join(".")' | uniq | tail -n +2)
7044
cluster="some-name"
71-
desc 'Starting the cluster with IMAGE_MONGOD '${IMAGE_MONGOD}''
72-
45+
desc 'Starting the cluster with IMAGE_MONGOD '$(echo ${version_matrix} | jq '.[0] | keys | .[0]')''
46+
export IMAGE_MONGOD=$(echo ${version_matrix} | jq -r 'to_entries | .[0].value | .[].image_path')
7347
apply_cluster "${test_dir}/conf/${cluster}.yml"
7448

7549
desc 'check if all 3 Pods started'
@@ -84,35 +58,51 @@ function main() {
8458
"userAdmin:userAdmin123456@${cluster}-mongos.${namespace}"
8559
sleep 2
8660
run_mongos \
87-
'use myApp\n db.test.insert({ x: 100500 })' \
61+
'use myApp\n db.test.insert({ x: 100501 })' \
8862
"myApp:myPass@${cluster}-mongos.${namespace}"
8963
compare_mongos_cmd "find" "myApp:myPass@${cluster}-mongos.${namespace}"
9064

9165
desc 'Starting to follow mongod upgrade images chain'
92-
9366
target_generation=2
9467
for version in ${versions_to_verify[@]}; do
68+
desc "Testing upgrade to version: ${version}"
9569
kubectl_bin patch psmdb/${cluster%%-rs0} \
9670
--type=json \
9771
-p='[
9872
{"op":"replace","path":"/spec/upgradeOptions/apply","value": "'${version}'-recommended"},
99-
{"op":"replace","path":"/spec/upgradeOptions/setFCV","value": true}
10073
]'
10174

102-
sleep 60 # waiting for update loop to fire
75+
sleep 70 # waiting for update loop to fire
10376
wait_for_running "${cluster}-cfg" 3
10477
wait_for_running "${cluster}-rs0" 3
10578
wait_for_running "${cluster}-mongos" 3
10679
wait_cluster_consistency "${cluster}"
10780

10881
compare_generation ${target_generation} "statefulset" "${cluster}-cfg"
10982
compare_generation ${target_generation} "statefulset" "${cluster}-rs0"
110-
compare_generation 2 "statefulset" "${cluster}-mongos" # generation is 2 because mongos gets deleted on restore
83+
compare_generation ${target_generation} "statefulset" "${cluster}-mongos"
84+
85+
kubectl_bin patch psmdb/${cluster%%-rs0} \
86+
--type=json \
87+
-p='[
88+
{"op":"replace","path":"/spec/upgradeOptions/setFCV","value": true}
89+
]'
90+
sleep 10
91+
wait_cluster_consistency "${cluster}"
92+
93+
currentFCV=$(run_mongos 'JSON.stringify(db.adminCommand({getParameter:1,featureCompatibilityVersion:1}))' "clusterAdmin:clusterAdmin123456@${cluster}-cfg.${namespace}" \
94+
| grep -E '^\{.*\}$' | jq -r '.featureCompatibilityVersion.version')
95+
96+
if [[ ${currentFCV} != ${version} ]]; then
97+
echo "FCV at the moment is ${currentFCV} and is not set to ${version} as it should. Exiting..."
98+
exit 1
99+
fi
111100

112101
run_mongos \
113102
'use myApp\n db.test.insert({ x: 10050'${target_generation}' })' \
114103
"myApp:myPass@${cluster}-mongos.${namespace}"
115104
compare_mongos_cmd "find" "myApp:myPass@${cluster}-mongos.${namespace}" "-${target_generation}"
105+
116106
target_generation=$((target_generation + 1))
117107
done
118108

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
switched to db myApp
2-
{ "_id" : , "x" : 100500 }
2+
{ "_id" : , "x" : 100501 }
33
{ "_id" : , "x" : 100502 }
44
bye
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
switched to db myApp
2-
{ "_id" : , "x" : 100500 }
2+
{ "_id" : , "x" : 100501 }
3+
{ "_id" : , "x" : 100502 }
34
{ "_id" : , "x" : 100503 }
45
bye

0 commit comments

Comments
 (0)