chore(helm): Adding opereplay config map for
Installation agnostic version access. This is useful for db migration, especially when we install using argo, or other means precedence to the autogenereated prev version. Set migration is true if its argo deployment fix the forceMigration override
This commit is contained in:
parent
e7ddf5b6b6
commit
b4d00cfe04
4 changed files with 111 additions and 60 deletions
|
|
@ -5,9 +5,22 @@ cd $(dirname $0)
|
|||
|
||||
is_migrate=$1
|
||||
|
||||
# Check if the openreplay version is set.
|
||||
# This will take precedence over the .Values.fromVersion variable
|
||||
# Because its created by installation programatically.
|
||||
if [[ -n $OPENREPLAY_VERSION ]]; then
|
||||
is_migrate=true
|
||||
PREVIOUS_APP_VERSION=$OPENREPLAY_VERSION
|
||||
echo "$OPENREPLAY_VERSION set"
|
||||
fi
|
||||
|
||||
if [[ $FORCE_MIGRATION == "true" ]]; then
|
||||
is_migrate=true
|
||||
fi
|
||||
|
||||
# Converting alphaneumeric to number.
|
||||
PREVIOUS_APP_VERSION=`echo $PREVIOUS_APP_VERSION | cut -d "v" -f2`
|
||||
CHART_APP_VERSION=`echo $CHART_APP_VERSION | cut -d "v" -f2`
|
||||
PREVIOUS_APP_VERSION=$(echo $PREVIOUS_APP_VERSION | cut -d "v" -f2)
|
||||
CHART_APP_VERSION=$(echo $CHART_APP_VERSION | cut -d "v" -f2)
|
||||
|
||||
function migration() {
|
||||
ls -la /opt/openreplay/openreplay
|
||||
|
|
@ -36,72 +49,71 @@ function migration() {
|
|||
|
||||
# We need to remove version dots
|
||||
function normalise_version {
|
||||
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
|
||||
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
|
||||
}
|
||||
all_versions=(`ls -l db/init_dbs/$db | grep -E ^d | grep -v create | awk '{print $NF}'`)
|
||||
migration_versions=(`for ver in ${all_versions[*]}; do if [[ $(normalise_version $ver) > $(normalise_version "${PREVIOUS_APP_VERSION}") ]]; then echo $ver; fi; done | sort -V`)
|
||||
all_versions=($(ls -l db/init_dbs/$db | grep -E ^d | grep -v create | awk '{print $NF}'))
|
||||
migration_versions=($(for ver in ${all_versions[*]}; do if [[ $(normalise_version $ver) > $(normalise_version "${PREVIOUS_APP_VERSION}") ]]; then echo $ver; fi; done | sort -V))
|
||||
echo "Migration version: ${migration_versions[*]}"
|
||||
# Can't pass the space seperated array to ansible for migration. So joining them with ,
|
||||
joined_migration_versions=$(IFS=, ; echo "${migration_versions[*]}")
|
||||
|
||||
joined_migration_versions=$(
|
||||
IFS=,
|
||||
echo "${migration_versions[*]}"
|
||||
)
|
||||
|
||||
cd -
|
||||
|
||||
case "$1" in
|
||||
postgresql)
|
||||
/bin/bash postgresql.sh migrate $joined_migration_versions
|
||||
;;
|
||||
minio)
|
||||
/bin/bash minio.sh migrate $joined_migration_versions
|
||||
;;
|
||||
clickhouse)
|
||||
/bin/bash clickhouse.sh migrate $joined_migration_versions
|
||||
;;
|
||||
kafka)
|
||||
/bin/bash kafka.sh migrate $joined_migration_versions
|
||||
;;
|
||||
*)
|
||||
echo "Unknown operation for db migration; exiting."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function init(){
|
||||
case $1 in
|
||||
postgresql)
|
||||
/bin/bash postgresql.sh init
|
||||
;;
|
||||
minio)
|
||||
/bin/bash minio.sh migrate $migration_versions
|
||||
;;
|
||||
clickhouse)
|
||||
/bin/bash clickhouse.sh init
|
||||
;;
|
||||
kafka)
|
||||
/bin/bash kafka.sh init
|
||||
;;
|
||||
*)
|
||||
echo "Unknown operation for db init; exiting."
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
}
|
||||
|
||||
if [[ $FORCE_MIGRATION == "true" ]]; then
|
||||
is_migrate=true
|
||||
fi
|
||||
|
||||
# dbops.sh true(upgrade) clickhouse
|
||||
case "$is_migrate" in
|
||||
"false")
|
||||
init $2
|
||||
postgresql)
|
||||
/bin/bash postgresql.sh migrate $joined_migration_versions
|
||||
;;
|
||||
"true")
|
||||
migration $2
|
||||
minio)
|
||||
/bin/bash minio.sh migrate $joined_migration_versions
|
||||
;;
|
||||
clickhouse)
|
||||
/bin/bash clickhouse.sh migrate $joined_migration_versions
|
||||
;;
|
||||
kafka)
|
||||
/bin/bash kafka.sh migrate $joined_migration_versions
|
||||
;;
|
||||
*)
|
||||
echo "Unknown operation for db migration; exiting."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function init() {
|
||||
case $1 in
|
||||
postgresql)
|
||||
/bin/bash postgresql.sh init
|
||||
;;
|
||||
minio)
|
||||
/bin/bash minio.sh migrate $migration_versions
|
||||
;;
|
||||
clickhouse)
|
||||
/bin/bash clickhouse.sh init
|
||||
;;
|
||||
kafka)
|
||||
/bin/bash kafka.sh init
|
||||
;;
|
||||
*)
|
||||
echo "Unknown operation for db init; exiting."
|
||||
exit 1
|
||||
;;
|
||||
|
||||
esac
|
||||
}
|
||||
|
||||
# dbops.sh true(upgrade) clickhouse
|
||||
case "$is_migrate" in
|
||||
"false")
|
||||
init $2
|
||||
;;
|
||||
"true")
|
||||
migration $2
|
||||
;;
|
||||
*)
|
||||
echo "Unknown operation for db migration; exiting."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
10
scripts/helmcharts/openreplay/templates/configmap.yaml
Normal file
10
scripts/helmcharts/openreplay/templates/configmap.yaml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: openreplay-version
|
||||
namespace: "{{ .Release.Namespace }}"
|
||||
annotations:
|
||||
"helm.sh/hook": post-install, post-upgrade
|
||||
"helm.sh/hook-weight": "-6" # Higher precidence, so the first the config map will get created.
|
||||
data:
|
||||
version: {{ .Chart.AppVersion }}
|
||||
|
|
@ -3,8 +3,8 @@ Don't have to trigger migration if there is no version change
|
|||
Don't have to trigger migration if skipMigration is set
|
||||
Have to trigger migration if forceMigration is set
|
||||
*/}}
|
||||
{{- $versionChange := and (eq .Values.fromVersion .Chart.AppVersion) (.Release.IsUpgrade) }}
|
||||
{{- if or (not (or .Values.skipMigration $versionChange)) .Values.forceMigration }}
|
||||
{{- $versionChange := (or .Values.deployment.argo (and (not (eq .Values.fromVersion .Chart.AppVersion)) .Release.IsUpgrade)) }}
|
||||
{{- if or .Values.forceMigration (and (not .Values.skipMigration) $versionChange) }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
|
|
@ -99,6 +99,12 @@ spec:
|
|||
containers:
|
||||
- name: postgres
|
||||
env:
|
||||
- name: OPENREPLAY_VERSION
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: openreplay-version
|
||||
key: version
|
||||
optional: true
|
||||
- name: FORCE_MIGRATION
|
||||
value: "{{ .Values.forceMigration }}"
|
||||
- name: PREVIOUS_APP_VERSION
|
||||
|
|
@ -145,6 +151,12 @@ spec:
|
|||
- name: minio
|
||||
image: bitnami/minio:2023.11.20
|
||||
env:
|
||||
- name: OPENREPLAY_VERSION
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: openreplay-version
|
||||
key: version
|
||||
optional: true
|
||||
{{- range $key, $val := .Values.global.env }}
|
||||
- name: {{ $key }}
|
||||
value: '{{ $val }}'
|
||||
|
|
@ -268,6 +280,12 @@ spec:
|
|||
- name: clickhouse
|
||||
image: clickhouse/clickhouse-server:22.12-alpine
|
||||
env:
|
||||
- name: OPENREPLAY_VERSION
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: openreplay-version
|
||||
key: version
|
||||
optional: true
|
||||
{{- range $key, $val := .Values.global.env }}
|
||||
- name: {{ $key }}
|
||||
value: '{{ $val }}'
|
||||
|
|
@ -303,6 +321,12 @@ spec:
|
|||
- name: kafka
|
||||
image: bitnami/kafka:2.6.0-debian-10-r30
|
||||
env:
|
||||
- name: OPENREPLAY_VERSION
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: openreplay-version
|
||||
key: version
|
||||
optional: true
|
||||
{{- range $key, $val := .Values.global.env }}
|
||||
- name: {{ $key }}
|
||||
value: '{{ $val }}'
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ migrationJob:
|
|||
migration:
|
||||
env: {}
|
||||
|
||||
deployment:
|
||||
argo: false
|
||||
forceMigration: false
|
||||
skipMigration: false
|
||||
|
||||
redis: &redis
|
||||
tls:
|
||||
enabled: false
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue