mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 12:16:03 +09:00
fix(postgres): render the declared databases in a stable order
keys returns a map's keys in Go's randomized iteration order, so a
release with several databases rendered DEFINED_DBS in a different
order on each upgrade. The init-script Secret, and the checksum the
init Job carries, then changed on upgrades that left the databases
untouched, which makes a no-op upgrade look like a real change in the
release history.
Assisted-by: LLM
Signed-off-by: Mattia Eleuteri <mattia@hidora.io>
(cherry picked from commit dc94660a44)
Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
This commit is contained in:
1 parent
e21c351c1d
commit
b658dffe7c
2 files changed
+38
-1
No files matched your search
@@ -337,7 +337,7 @@ stringData:
|
||||
RESTORE_MARK={{ with .Values.bootstrap.newServerName }}$(echo {{ b64enc . }} | base64 -d){{ end }}
|
||||
ADOPTED_MARK=$(psql -v ON_ERROR_STOP=1 -t -A --dbname postgres -c "SELECT current_setting('cozystack.adopted_restore', true)")
|
||||
MANAGED_DBS=$(psql -v ON_ERROR_STOP=1 -t -A -c "SELECT datname FROM pg_database d JOIN pg_shdescription s ON d.oid = s.objoid WHERE s.description = 'database managed by helm'")
|
||||
DEFINED_DBS="{{ join " " (keys .Values.databases) }}"
|
||||
DEFINED_DBS="{{ join " " (keys .Values.databases | sortAlpha) }}"
|
||||
DELETE_DBS=$(for db in $MANAGED_DBS; do case " $DEFINED_DBS " in *" $db "*) :;; *) echo $db;; esac; done)
|
||||
|
||||
if [ -n "$RESTORE_MARK" ] && [ "$ADOPTED_MARK" != "$RESTORE_MARK" ]; then
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
suite: init-script renders the same for the same values
|
||||
|
||||
# keys returns a map's keys in Go's randomized iteration order, so a release with
|
||||
# several databases rendered DEFINED_DBS in a different order on each upgrade. The
|
||||
# init-script Secret then changed on upgrades that changed nothing in the
|
||||
# databases, and so did the checksum the init Job carries.
|
||||
|
||||
templates:
|
||||
- templates/init-script.yaml
|
||||
|
||||
release:
|
||||
name: pg-test
|
||||
namespace: tenant-test
|
||||
|
||||
set:
|
||||
_cluster:
|
||||
scheduling: {}
|
||||
|
||||
tests:
|
||||
- it: lists the declared databases in a stable order
|
||||
set:
|
||||
databases:
|
||||
hotel: {}
|
||||
alpha: {}
|
||||
golf: {}
|
||||
charlie: {}
|
||||
foxtrot: {}
|
||||
bravo: {}
|
||||
echo: {}
|
||||
delta: {}
|
||||
documentSelector:
|
||||
path: metadata.name
|
||||
value: pg-test-init-script
|
||||
asserts:
|
||||
- matchRegex:
|
||||
path: stringData["init.sh"]
|
||||
pattern: 'DEFINED_DBS="alpha bravo charlie delta echo foxtrot golf hotel"'
|
||||
Reference in new issue
Block a user