mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-03 18:47:04 +09:00
The operator image is pinned to 1.27.3 while the vendored chart and CRDs still advertise 1.27.1. Kubernetes prunes Backup status.instanceID.sessionID, causing false instance-manager restart failures. Import the official 1.27.3 CRDs, align the chart appVersion, and preserve the overlay across make update. Add render and API round-trip regression coverage. Assisted-By: GPT-5 <noreply@openai.com> Signed-off-by: Myasnikov Daniil <myasnikovdaniil2001@gmail.com>
78 lines
3.6 KiB
Bash
78 lines
3.6 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
@test "Create DB PostgreSQL" {
|
|
name='test'
|
|
kubectl -n tenant-test delete postgreses.apps.cozystack.io $name --ignore-not-found --timeout=2m || true
|
|
kubectl apply -f - <<EOF
|
|
apiVersion: apps.cozystack.io/v1alpha1
|
|
kind: Postgres
|
|
metadata:
|
|
name: $name
|
|
namespace: tenant-test
|
|
spec:
|
|
external: false
|
|
size: 10Gi
|
|
replicas: 2
|
|
storageClass: ""
|
|
postgresql:
|
|
parameters:
|
|
max_connections: "100"
|
|
quorum:
|
|
minSyncReplicas: 0
|
|
maxSyncReplicas: 0
|
|
users:
|
|
testuser:
|
|
password: xai7Wepo
|
|
databases:
|
|
testdb:
|
|
roles:
|
|
admin:
|
|
- testuser
|
|
backup:
|
|
enabled: false
|
|
s3Region: us-east-1
|
|
s3Bucket: s3.example.org/postgres-backups
|
|
schedule: "0 2 * * *"
|
|
cleanupStrategy: "--keep-last=3 --keep-daily=3 --keep-within-weekly=1m"
|
|
s3AccessKey: oobaiRus9pah8PhohL1ThaeTa4UVa7gu
|
|
s3SecretKey: ju3eum4dekeich9ahM1te8waeGai0oog
|
|
resticPassword: ChaXoveekoh6eigh4siesheeda2quai0
|
|
resources: {}
|
|
resourcesPreset: "nano"
|
|
EOF
|
|
# Wait for the operator to materialise the HelmRelease before kubectl wait
|
|
# kicks in (kubectl wait errors immediately if the object does not exist yet).
|
|
timeout 60 sh -ec "until kubectl -n tenant-test get hr postgres-$name >/dev/null 2>&1; do sleep 2; done"
|
|
kubectl -n tenant-test wait hr postgres-$name --timeout=5m --for=condition=ready
|
|
timeout 60 sh -ec "until kubectl -n tenant-test get job.batch postgres-$name-init-job >/dev/null 2>&1; do sleep 2; done"
|
|
kubectl -n tenant-test wait job.batch postgres-$name-init-job --timeout=50s --for=condition=Complete
|
|
timeout 40 sh -ec "until kubectl -n tenant-test get svc postgres-$name-r -o jsonpath='{.spec.ports[0].port}' | grep -q '5432'; do sleep 10; done"
|
|
timeout 40 sh -ec "until kubectl -n tenant-test get svc postgres-$name-ro -o jsonpath='{.spec.ports[0].port}' | grep -q '5432'; do sleep 10; done"
|
|
timeout 40 sh -ec "until kubectl -n tenant-test get svc postgres-$name-rw -o jsonpath='{.spec.ports[0].port}' | grep -q '5432'; do sleep 10; done"
|
|
timeout 120 sh -ec "until kubectl -n tenant-test get endpoints postgres-$name-r -o jsonpath='{.subsets[*].addresses[*].ip}' | grep -q '[0-9]'; do sleep 10; done"
|
|
# for some reason it takes longer for the read-only endpoint to be ready
|
|
#timeout 120 sh -ec "until kubectl -n tenant-test get endpoints postgres-$name-ro -o jsonpath='{.subsets[*].addresses[*].ip}' | grep -q '[0-9]'; do sleep 10; done"
|
|
timeout 120 sh -ec "until kubectl -n tenant-test get endpoints postgres-$name-rw -o jsonpath='{.subsets[*].addresses[*].ip}' | grep -q '[0-9]'; do sleep 10; done"
|
|
backup_name="$name-session-id-schema"
|
|
kubectl -n tenant-test delete backups.postgresql.cnpg.io "$backup_name" --ignore-not-found --timeout=2m
|
|
kubectl -n tenant-test apply -f - <<EOF
|
|
apiVersion: postgresql.cnpg.io/v1
|
|
kind: Backup
|
|
metadata:
|
|
name: $backup_name
|
|
spec:
|
|
cluster:
|
|
name: postgres-$name
|
|
EOF
|
|
kubectl -n tenant-test patch backups.postgresql.cnpg.io "$backup_name" --subresource=status --type=merge -p='{"status":{"phase":"failed","instanceID":{"podName":"schema-probe","sessionID":"cozystack-schema-probe"}}}'
|
|
actual_session_id="$(kubectl -n tenant-test get backups.postgresql.cnpg.io "$backup_name" -o jsonpath='{.status.instanceID.sessionID}')"
|
|
[ "$actual_session_id" = "cozystack-schema-probe" ] || {
|
|
echo "Backup status sessionID was not preserved by the API server"
|
|
kubectl -n tenant-test get backups.postgresql.cnpg.io "$backup_name" -o yaml
|
|
false
|
|
}
|
|
kubectl -n tenant-test delete backups.postgresql.cnpg.io "$backup_name" --timeout=2m
|
|
kubectl -n tenant-test delete postgreses.apps.cozystack.io $name
|
|
kubectl -n tenant-test delete job.batch/postgres-$name-init-job
|
|
}
|