Skip to content

Commit f458804

Browse files
committed
e2e: fix previous tests
1 parent dd09eac commit f458804

11 files changed

Lines changed: 68 additions & 151 deletions

File tree

stackgres-k8s/e2e/spec/previous/1.13/spec/abstract/backup

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ check_backup_retention() {
229229
}
230230

231231
get_completed_managed_backup_count() {
232-
kubectl get sgbackup -n "$CLUSTER_NAMESPACE" -o custom-columns=PHASE:.status.process.status \
233-
| grep 'Completed' | wc -l
232+
kubectl get sgbackup -n "$CLUSTER_NAMESPACE" -o custom-columns=PHASE:.status.process.status,MANAGED:.spec.managedLifecycle \
233+
| tr -s ' ' | grep -xF 'Completed true' | wc -l
234234
}
235235

236236
enable_cluster_cron_schedule() {

stackgres-k8s/e2e/spec/previous/1.13/spec/abstract/dbops-major-version-upgrade

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ reset_cluster_internal() {
103103
fi
104104

105105
wait_pods_running "$CLUSTER_NAMESPACE" "$PODS_RUNNING"
106-
wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
106+
SWITCHOVER_TO_FIRST=true wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
107107

108108
if [ "$ONLY_PG_REPACK" != true ] && [ -n "$SOURCE_POSTGIS_VERSION" ] && [ "$SOURCE_POSTGIS_VERSION" = "$TARGET_POSTGIS_VERSION" ]
109109
then
@@ -254,4 +254,10 @@ check_major_version_upgrade_check() {
254254
check_mock_data_samehost "$CLUSTER_NAME"
255255
wait_until run_query -i 1 -q "SELECT 1;"
256256
check_mock_data_replication "$CLUSTER_NAME"
257+
if kubectl exec -ti -n "$CLUSTER_NAMESPACE" "$CLUSTER_NAME-0" -c patroni -- psql -q -w -h localhost -p 5432 -c 'SELECT 1'
258+
then
259+
fail "was possible to connect to the cluster without password"
260+
else
261+
success "was not possible to connect to the cluster without password"
262+
fi
257263
}

stackgres-k8s/e2e/spec/previous/1.13/spec/abstract/dbops-minor-version-upgrade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ reset_cluster() {
2323
--set-string cluster.postgres.version="$E2E_MINOR_SOURCE_POSTGRES_VERSION"
2424

2525
wait_pods_running "$CLUSTER_NAMESPACE" 3
26-
wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
26+
SWITCHOVER_TO_FIRST=true wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
2727

2828
set_restarted_pods
2929

stackgres-k8s/e2e/spec/previous/1.13/spec/abstract/dbops-pgbench

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,20 @@ check_pgbench() {
183183
fail "pgbench did not returned the statements script."
184184
fi
185185

186-
if kubectl get -n "$CLUSTER_NAMESPACE" sgdbops "$DBOPS_NAME" \
187-
--template '{{ .status.benchmark.pgbench.hdrHistogram }}' | grep -x '[0-9A-Za-z+/=]\+'
186+
kubectl get -n "$CLUSTER_NAMESPACE" pod -l "app=StackGresCluster,stackgres.io/cluster-name=$CLUSTER_NAME,stackgres.io/cluster=true" -o json \
187+
| jq -r '.items[0].spec.containers[0].image' | grep -q '^.*-build-6\.\(.*\)$'
188+
189+
if kubectl get -n "$CLUSTER_NAMESPACE" pod -l "app=StackGresCluster,stackgres.io/cluster-name=$CLUSTER_NAME,stackgres.io/cluster=true" -o json \
190+
| jq -r '.items[0].spec.containers[0].image' | sed 's/^.*-build-6\.\(.*\)$/\1/' \
191+
| test "$(cat)" -ge 35
188192
then
189-
success "pgbench returned the HdrHistogram."
190-
else
191-
fail "pgbench did not returned the HdrHistogram."
193+
if kubectl get -n "$CLUSTER_NAMESPACE" sgdbops "$DBOPS_NAME" \
194+
--template '{{ .status.benchmark.pgbench.hdrHistogram }}' | grep -x '[0-9A-Za-z+/=]\+'
195+
then
196+
success "pgbench returned the HdrHistogram."
197+
else
198+
fail "pgbench did not returned the HdrHistogram."
199+
fi
192200
fi
193201

194202
RESULT="$(run_query -i 0 -p 5432 -q "SELECT EXISTS(SELECT * FROM pg_database WHERE datname LIKE 'pgbench-%')")"

stackgres-k8s/e2e/spec/previous/1.13/spec/abstract/patroni

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/sh
2+
23
patroni_ports_check() {
34
if patroni_liveness_check
45
then
@@ -38,11 +39,11 @@ patroni_switchover(){
3839
}
3940

4041
patroni_direct_switchover_check(){
41-
patroni_curl -e "switchover" -p 8009 -XPOST -d '{"leader":"'"$CLUSTER_NAME-0"'"}' > /dev/null
42+
patroni_curl -e "switchover" -p 8009 -XPOST -d '{"leader":"'"$CLUSTER_NAME-0"'"}' > /dev/null
4243
}
4344

4445
patroni_liveness_check() {
45-
patroni_curl -e "cluster" > /dev/null
46+
patroni_curl -e "cluster" > /dev/null
4647
}
4748

4849
patroni_readiness_check() {
@@ -54,7 +55,7 @@ get_pod_ip(){
5455
}
5556

5657
patroni_curl(){
57-
PORT=8008
58+
PORT="${PATRONI_PORT:-8008}"
5859
POD_IP="$(get_pod_ip)"
5960
ENPOINT="cluster"
6061

stackgres-k8s/e2e/spec/previous/1.13/spec/abstract/prometheus-integration

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ e2e_exclusive_lock() {
66

77
e2e_test() {
88
run_test "Check that exporter queries are wokring" check_exporter_queries
9-
run_test "Check that exporter pod monitor was created" check_exporter_pod_monitor
10-
run_test "Check that envoy pod monitor was created" check_envoy_pod_monitor
9+
run_test "Check that collector was created" check_collector
10+
run_test "Check that collector pod monitor was created" check_collector_pod_monitor
1111
run_test "Check that grafana is embedded" check_grafana_embedded
1212
run_test "Check that grafana secret is used" check_grafana_secret
1313
}
@@ -61,14 +61,26 @@ check_exporter_queries() {
6161
done
6262
}
6363

64-
check_exporter_pod_monitor() {
65-
local SERVICE_MONITOR="$CLUSTER_NAMESPACE-$CLUSTER_NAME-stackgres-postgres-exporter"
64+
check_collector() {
65+
local SERVICE_MONITOR="stackgres-collector"
6666

67-
if wait_until kubectl get podmonitors.monitoring.coreos.com -n "$(prometheus_namespace)" "$SERVICE_MONITOR"
67+
if wait_until kubectl get deployment -n "$OPERATOR_NAMESPACE" "$SERVICE_MONITOR"
6868
then
69-
echo "Exporter pod monitor was created"
69+
echo "Collector deployment was created"
7070
else
71-
echo "Exporter pod monitor wasn't created"
71+
echo "Collector deployment wasn't created"
72+
return 1
73+
fi
74+
}
75+
76+
check_collector_pod_monitor() {
77+
local SERVICE_MONITOR="stackgres-collector"
78+
79+
if wait_until kubectl get podmonitors.monitoring.coreos.com -n "$OPERATOR_NAMESPACE" "$SERVICE_MONITOR"
80+
then
81+
echo "Collector pod monitor was created"
82+
else
83+
echo "Collector pod monitor wasn't created"
7284
return 1
7385
fi
7486

@@ -93,27 +105,6 @@ check_exporter_pod_monitor() {
93105
fi
94106
}
95107

96-
check_envoy_pod_monitor() {
97-
local SERVICE_MONITOR="$CLUSTER_NAMESPACE-$CLUSTER_NAME-stackgres-envoy"
98-
99-
if wait_until kubectl get podmonitors.monitoring.coreos.com -n "$(prometheus_namespace)" "$SERVICE_MONITOR"
100-
then
101-
echo "Envoy pod monitor was created"
102-
else
103-
echo "Envoy pod monitor wasn't created"
104-
return 1
105-
fi
106-
107-
if wait_until kubectl exec -i -n "$CLUSTER_NAMESPACE" curl -- \
108-
curl -f -s "http://$(prometheus_service).$(prometheus_namespace):9090/api/v1/query?query=envoy_cluster_upstream_cx_rx_bytes_total"
109-
then
110-
echo "Envoy metrics was found on prometheus"
111-
else
112-
echo "Envoy metrics wasn't found on prometheus"
113-
return 1
114-
fi
115-
}
116-
117108
check_grafana_embedded() {
118109
if wait_until kubectl exec -i -n "$CLUSTER_NAMESPACE" curl -- curl -s -k "https://stackgres-restapi.$OPERATOR_NAMESPACE/grafana" -o /dev/null --fail
119110
then

stackgres-k8s/e2e/spec/previous/1.14/spec/abstract/backup

Lines changed: 3 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -145,104 +145,6 @@ is_automatic_backup_cr_completed() {
145145
fi
146146
}
147147

148-
check_manual_backup() {
149-
local NODE="${1:-0}"
150-
local BACKUP_NAME
151-
BACKUP_NAME="$(get_sgbackup_name "${CLUSTER_NAME}-${NODE}-$(shuf -i 0-65535 -n 1)")"
152-
local BACKUP_2_NAME
153-
BACKUP_2_NAME="$(get_sgbackup_name "${CLUSTER_NAME}-${NODE}-$(shuf -i 0-65535 -n 1)-2")"
154-
local BACKUP_3_NAME
155-
BACKUP_3_NAME="$(get_sgbackup_name "${CLUSTER_NAME}-${NODE}-$(shuf -i 0-65535 -n 1)-3")"
156-
local ACTUAL_BACKUP_NAME
157-
158-
kubectl delete job -n "$CLUSTER_NAMESPACE" -l "stackgres.io/scheduled-backup=true" --ignore-not-found
159-
kubectl delete sgbackup -n "$CLUSTER_NAMESPACE" --all
160-
161-
create_backup "$BACKUP_NAME" false
162-
163-
if wait_until eval '[ "$(kubectl get sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_NAME" \
164-
-o name | wc -l)" -gt 0 ]'
165-
then
166-
echo "SUCCESS. The manual backup CR is running"
167-
else
168-
echo "FAIL. The manual backup CR is not running"
169-
return 1
170-
fi
171-
172-
wait_backup_is_completed "$BACKUP_NAME" "$NODE"
173-
174-
ACTUAL_BACKUP_NAME="$(kubectl get sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_NAME" \
175-
--template '{{ .status.internalName }} {{ .status.process.status }} {{ .status.backupInformation.sourcePod }}' \
176-
| grep " Completed ${CLUSTER_NAME}-${NODE}$" | tail -n 1 | cut -d ' ' -f 1)"
177-
178-
if [ -z "$ACTUAL_BACKUP_NAME" ]
179-
then
180-
echo "FAIL. Backup name not found"
181-
return 1
182-
fi
183-
184-
if [ "$(kubectl exec -n "$CLUSTER_NAMESPACE" "${CLUSTER_NAME}-${NODE}" -c patroni -- \
185-
exec-with-env backup -- wal-g backup-list 2>/dev/null | grep "^$ACTUAL_BACKUP_NAME " | wc -l)" -gt 0 ]
186-
then
187-
echo "SUCCESS. The full backup of created CR is available"
188-
else
189-
echo "FAIL. The full backup of created CR is not available"
190-
return 1
191-
fi
192-
193-
check_is_managed_lifecycle_value "$BACKUP_NAME" false
194-
195-
kubectl patch sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_NAME" --type json \
196-
--patch '[{"op":"replace","path":"/spec/managedLifecycle","value":true}]'
197-
198-
create_backup "$BACKUP_2_NAME" true
199-
200-
wait_until check_is_managed_lifecycle_value "$BACKUP_NAME" true
201-
202-
local DEFAULT_ANNOTATION
203-
DEFAULT_ANNOTATION="$(kubectl get sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_NAME" -o json | jq '.metadata.annotations["stackgres.io/operatorVersion"]')"
204-
205-
if [ -z "$DEFAULT_ANNOTATION" ] || [ "$DEFAULT_ANNOTATION" = "null" ]
206-
then
207-
echo "FAIL. Default annotations not created"
208-
return 1
209-
else
210-
echo "SUCCESS. Defaults annotations created"
211-
fi
212-
213-
create_backup "$BACKUP_3_NAME" true
214-
215-
if wait_until eval '! kubectl get sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_NAME" > /dev/null 2>&1'
216-
then
217-
echo "SUCCESS. The backup retention has been honored. Old backups deleted"
218-
else
219-
echo "FAIL. The backup retention has not been honored. Old backups not deleted"
220-
return 1
221-
fi
222-
223-
if wait_until eval '[ "$(get_completed_managed_backup_count)" = "2" ]'
224-
then
225-
echo "SUCCESS. The backup retention has been honored. Remaining backups are 2"
226-
else
227-
echo "FAIL. The backup retention has not been honored. Remaining backups are $(get_completed_managed_backup_count)"
228-
return 1
229-
fi
230-
231-
kubectl delete job -n "$CLUSTER_NAMESPACE" -l "stackgres.io/scheduled-backup=true" --ignore-not-found
232-
kubectl delete sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_2_NAME"
233-
kubectl delete sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_3_NAME"
234-
235-
if wait_until eval '[ "$(kubectl exec -n "$CLUSTER_NAMESPACE" "${CLUSTER_NAME}-${NODE}" -c patroni -- \
236-
exec-with-env backup -- wal-g backup-list 2>/dev/null | grep "^$ACTUAL_BACKUP_NAME " | wc -l)" -eq 0 ]'
237-
then
238-
echo "SUCCESS. The full backup of deleted CR has been removed"
239-
else
240-
echo "FAIL. The full backup of deleted CR has not been removed"
241-
return 1
242-
>>>>>>> main-1.14:stackgres-k8s/e2e/spec/previous/1.12/spec/abstract/backup
243-
fi
244-
}
245-
246148
wait_backup_is_completed() {
247149
local BACKUP_NAME="$1"
248150
local NODE="${2:-0}"
@@ -322,13 +224,13 @@ check_backup_retention() {
322224
then
323225
success "The backup retention has been honored. Remaining backups are 2"
324226
else
325-
fail "The backup retention has not been honored. Remaining backups are $(get_completed_backup_count)"
227+
fail "The backup retention has not been honored. Remaining backups are $(get_completed_managed_backup_count)"
326228
fi
327229
}
328230

329231
get_completed_managed_backup_count() {
330-
kubectl get sgbackup -n "$CLUSTER_NAMESPACE" -o custom-columns=PHASE:.status.process.status \
331-
| grep 'Completed' | wc -l
232+
kubectl get sgbackup -n "$CLUSTER_NAMESPACE" -o custom-columns=PHASE:.status.process.status,MANAGED:.spec.managedLifecycle \
233+
| tr -s ' ' | grep -xF 'Completed true' | wc -l
332234
}
333235

334236
enable_cluster_cron_schedule() {

stackgres-k8s/e2e/spec/previous/1.14/spec/abstract/dbops-major-version-upgrade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ reset_cluster_internal() {
103103
fi
104104

105105
wait_pods_running "$CLUSTER_NAMESPACE" "$PODS_RUNNING"
106-
wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
106+
SWITCHOVER_TO_FIRST=true wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
107107

108108
if [ "$ONLY_PG_REPACK" != true ] && [ -n "$SOURCE_POSTGIS_VERSION" ] && [ "$SOURCE_POSTGIS_VERSION" = "$TARGET_POSTGIS_VERSION" ]
109109
then

stackgres-k8s/e2e/spec/previous/1.14/spec/abstract/dbops-minor-version-upgrade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ reset_cluster() {
2323
--set-string cluster.postgres.version="$E2E_MINOR_SOURCE_POSTGRES_VERSION"
2424

2525
wait_pods_running "$CLUSTER_NAMESPACE" 3
26-
wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
26+
SWITCHOVER_TO_FIRST=true wait_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
2727

2828
set_restarted_pods
2929

stackgres-k8s/e2e/spec/previous/1.14/spec/abstract/dbops-pgbench

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,20 @@ check_pgbench() {
183183
fail "pgbench did not returned the statements script."
184184
fi
185185

186-
if kubectl get -n "$CLUSTER_NAMESPACE" sgdbops "$DBOPS_NAME" \
187-
--template '{{ .status.benchmark.pgbench.hdrHistogram }}' | grep -x '[0-9A-Za-z+/=]\+'
186+
kubectl get -n "$CLUSTER_NAMESPACE" pod -l "app=StackGresCluster,stackgres.io/cluster-name=$CLUSTER_NAME,stackgres.io/cluster=true" -o json \
187+
| jq -r '.items[0].spec.containers[0].image' | grep -q '^.*-build-6\.\(.*\)$'
188+
189+
if kubectl get -n "$CLUSTER_NAMESPACE" pod -l "app=StackGresCluster,stackgres.io/cluster-name=$CLUSTER_NAME,stackgres.io/cluster=true" -o json \
190+
| jq -r '.items[0].spec.containers[0].image' | sed 's/^.*-build-6\.\(.*\)$/\1/' \
191+
| test "$(cat)" -ge 35
188192
then
189-
success "pgbench returned the HdrHistogram."
190-
else
191-
fail "pgbench did not returned the HdrHistogram."
193+
if kubectl get -n "$CLUSTER_NAMESPACE" sgdbops "$DBOPS_NAME" \
194+
--template '{{ .status.benchmark.pgbench.hdrHistogram }}' | grep -x '[0-9A-Za-z+/=]\+'
195+
then
196+
success "pgbench returned the HdrHistogram."
197+
else
198+
fail "pgbench did not returned the HdrHistogram."
199+
fi
192200
fi
193201

194202
RESULT="$(run_query -i 0 -p 5432 -q "SELECT EXISTS(SELECT * FROM pg_database WHERE datname LIKE 'pgbench-%')")"

0 commit comments

Comments
 (0)