zalando / postgres-operator

Postgres operator creates and manages PostgreSQL clusters running in Kubernetes
https://postgres-operator.readthedocs.io/
MIT License
4.14k stars 950 forks source link

S3 location is missing UID when configured against custom S3 provider #2457

Open bo0ts opened 8 months ago

bo0ts commented 8 months ago

We are running:

We use the following configmap to configure our postgres pods:

kind: ConfigMap
apiVersion: v1
metadata:
  name: postgres-pod-config
data:
  AWS_ACCESS_KEY_ID: ...
  AWS_SECRET_ACCESS_KEY: ...
  AWS_S3_FORCE_PATH_STYLE: "true"
  AWS_REGION: us-east-1
  AWS_ENDPOINT: http://s3-backup.intern:9000
  USE_WALG_BACKUP: "true"
  USE_WALG_RESTORE: "true"
  WALG_DISABLE_S3_SSE: "true"
  WAL_S3_BUCKET: backup

After that all backups end up in s3://backup/spilo/${NAMESPACE_NAME}-${INSTANCE_NAME}/wal/${PG_VERSION} and the cluster UID is missing.

Is this intentional and why is this the case? Backup/Restore works except the restore in-place case, which we would like to see working as well.

jhoelzel commented 6 months ago

i can confirm this to be the case with a digitialocean bucket too but i suspect its not the storage but my conf:

apiVersion: v1
kind: ConfigMap
metadata:
  name: postgres-operator-conf
data:
  WAL_S3_BUCKET: prod-postgres
  WAL_BUCKET_SCOPE_PREFIX: ""
  WAL_BUCKET_SCOPE_SUFFIX: "production"
  USE_WALG_BACKUP: "true"
  USE_WALG_RESTORE: "true"
  CLONE_USE_WALG_RESTORE: "true"
  BACKUP_SCHEDULE: '00 1 * * *' # 1 am at night
  AWS_S3_FORCE_PATH_STYLE: "true" # needed for MinIO
  AWS_ENDPOINT: https://nyc3.digitaloceanspaces.com # Endpoint URL to your S3 Endpoint; DO in this example
  AWS_REGION: us-east-1
  BACKUP_NUM_TO_RETAIN: "5"
c0deaddict commented 3 weeks ago

I also hit this issue, but with S3.. Looked in the source of the operator and found out that if you set the S3 bucket in the env vars of the postgresql resource, it does not configure the env variable WAL_BUCKET_SCOPE_SUFFIX with the uid of the cluster. The operator can be tricked into injecting the env variable by setting in the Helm values:

configAwsOrGcp:
  wal_s3_bucket: configured-per-instance

Now the postgres pods have a uid in the env var WAL_BUCKET_SCOPE_SUFFIX (prepended with a slash) while the bucket can still be overriden via the env.