chore(helm): Test postgres version is < 15, then exit

Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com>
This commit is contained in:
rjshrjndrn 2024-08-07 22:07:15 +02:00
parent 845ce44ddd
commit 859915107b
2 changed files with 64 additions and 9 deletions

View file

@ -222,15 +222,16 @@ function or_helm_upgrade() {
fi
for chart in "${chart_names[@]}"; do
[[ -z $OR_VERSION ]] || HELM_OPTIONS="${HELM_OPTIONS} --set dbMigrationUpstreamBranch=${OR_VERSION}"
log info helm upgrade --install "$chart" ./"$chart" -n "$APP_NS" --wait -f ./vars.yaml --atomic --debug $HELM_OPTIONS 2>&1 | tee -a "${log_file}"
log info "Upgrading chart: $chart"
if ! helm upgrade --install "$chart" ./"$chart" -n "$APP_NS" --wait -f ./vars.yaml --atomic --debug $HELM_OPTIONS 2>&1 | tee -a "${log_file}"; then
log err "
Installation failed, run ${BWHITE}cat ${log_file}${RED} for more info
If logs aren't verbose, run ${BWHITE}openreplay --status${RED}
If pods are in failed state, run ${BWHITE}openreplay --logs <pod-name>${RED}
If pods are in a failed state, run ${BWHITE}openreplay --logs <pod-name>${RED}
"
kubectl logs -l or.workload/type=db-migrate
fi
done
set +o pipefail
@ -351,7 +352,8 @@ function upgrade() {
# 3. In upgrade you'll have to clone the repo
# 3. How to update package. Because openreplay -u will be done from old update script
# 4. Update from Version
exists git || log err "Git not found. Please install"
command -v git >/dev/null 2>&1 || log err "Git not found. Please install"
[[ -f ${OR_DIR}/vars.yaml ]] || log err "No configuration file ${BWHITE}${OR_DIR}/vars.yaml${RED}.
If you're updating from version older than ${BWHITE}v1.10.0${RED}, for example ${BWHITE}v1.9.0${RED}:
${BWHITE}RELEASE_UPGRADE=1 openreplay --deprecated-upgrade ~/openreplay_v1.9.0/scripts/helmcharts/vars.yaml${RED}.
@ -360,11 +362,10 @@ function upgrade() {
"
or_version=$(busybox awk '/fromVersion/{print $2}' <"${OR_DIR}/vars.yaml") || {
log err "${BWHITE}${OR_DIR}/vars.yaml${RED} not found.
Please do ${BWHITE}openreplay --deprecated-upgrade /path/to/vars.yaml${RED}
"
Please do ${BWHITE}openreplay --deprecated-upgrade /path/to/vars.yaml${RED}"
}
# Unless its upgrade release, always checkout same tag.
# Unless it's upgrade release, always checkout same tag.
[[ $RELEASE_UPGRADE -eq 1 ]] || OR_VERSION=${OR_VERSION:-$or_version}
time_now=$(date +%m-%d-%Y-%I%M%S)
@ -376,8 +377,8 @@ function upgrade() {
install_packages
[[ -d /openreplay ]] && sudo chown -R 1001:1001 /openreplay
# Merge prefrerences
cp $OR_DIR/vars.yaml old_vars.yaml
# Merge preferences
cp "$OR_DIR/vars.yaml" old_vars.yaml
or_new_version=$(awk '/fromVersion/{print $2}' <"vars.yaml")
yq '(load("old_vars.yaml") | .. | select(tag != "!!map" and tag != "!!seq")) as $i ireduce(.; setpath($i | path; $i))' vars.yaml >new_vars.yaml
mv new_vars.yaml vars.yaml
@ -389,7 +390,7 @@ function upgrade() {
sudo mv ./openreplay-cli /bin/openreplay
sudo chmod +x /bin/openreplay
sudo mv ./vars.yaml "$OR_DIR"
sudo cp -rf ../../../openreplay $OR_DIR/
sudo cp -rf ../../../openreplay "$OR_DIR/"
log info "Configuration file is saved in /var/lib/openreplay/vars.yaml"
log info "Run ${BWHITE}openreplay -h${GREEN} to see the cli information to manage OpenReplay."

View file

@ -133,6 +133,60 @@ spec:
mountPath: /opt/openreplay
- name: datadir
mountPath: /mnt/efs
- name: postgres-check
image: bitnami/postgresql
env:
- name: PGHOST
value: "{{ .Values.global.postgresql.postgresqlHost }}"
- name: PGPORT
value: "{{ .Values.global.postgresql.postgresqlPort }}"
- name: PGUSER
value: "{{ .Values.global.postgresql.postgresqlUsername }}"
- name: PGPASSWORD
{{- if .Values.global.postgresql.existingSecret }}
valueFrom:
secretKeyRef:
name: {{ .Values.global.postgresql.existingSecret }}
key: postgresql-postgres-password
{{- else }}
value: '{{ .Values.global.postgresql.postgresqlPassword }}'
{{- end}}
command:
- /bin/sh
- -c
args:
- |
exit_count=0
error_connection=1
while [ $exit_count -le 20 ];do
nc -zv $POSTGRESQL_HOST $POSTGRESQL_PORT -w 1
if [ $? -ne 0 ]; then
echo "[info] postgresql is not up; retrying in 5 seconds"
sleep 4
exit_count=$(($exit_count+1))
echo $exit_count
else
error_connection=0
break
fi
done
if [ $error_connection -eq 1 ]; then
echo "[error] postgresql is not running. Exiting."
exit 100
fi
pg_version=$(psql -c "SHOW server_version;" | grep -oP '\d\d+')
if [ $pg_version -le 14 ]; then
echo "[error] postgresql version is $pg_version which is <= 15. Exiting."
exit 101
fi
volumeMounts:
- name: shared
mountPath: /opt/openreplay
- name: datadir
mountPath: /mnt/efs
containers:
- name: postgres
env: