postgres-operator icon indicating copy to clipboard operation
postgres-operator copied to clipboard

Allow chained references of custom environment variables to all generated envs

Open siegenthalerroger opened this issue 7 months ago • 1 comments

Fixes #2227

Currently custom environment variables are added after most generated envs but notably before WAL_BUCKET_SCOPE_SUFFIX and _PREFIX. This means that referencing one of these values from a custom env is impossible (k8s has an implied ordering of env vars).

I have changed this to always have custom envs being at the end of the list while still respecting the overrideability of only certain envs. It is now possible to use WAL-E with Azure Storage Accounts while including the UID of the cluster in the backup path.

tldr: Works now, didn't before


apiVersion: v1
kind: ConfigMap
metadata:
  name: pod-env-overrides
  namespace: postgres-operator-system
data:
  WALG_AZ_PREFIX: "azure://container-name/$(SCOPE)$(WAL_BUCKET_SCOPE_SUFFIX)/$(PGVERSION)"

siegenthalerroger avatar Apr 22 '25 20:04 siegenthalerroger

@sdudoladov @Jan-M @FxKu @jopadi @idanovinda @hughcapet @macedigital any chance for a review/merge?

siegenthalerroger avatar Jun 23 '25 11:06 siegenthalerroger

How would you override the WAL_BUCKET_SCOPE_SUFFIX/PREFIX with values from config map or secret. This is the reason why they are added before.

FxKu avatar Jul 15 '25 09:07 FxKu

@FxKu That is true, that is no longer possible with this approach. If that is a requirement then there would need to be a change in Spilo to make sure the behaviour on Azure is the same as on AWS & GCS (the S3 upload path interpolation is different for WAL-E and WAL-G iirc, it's been a while tbh).

An alternative solution would be to add a new "operator" env variable that contains the cluster UID, opening up the possibility for using that for interpolation wherever one could want (regardless of what the operator or spilo defaults to). I thought I read that this was unlikely to be merged but can't find that anymore. What do you think?

siegenthalerroger avatar Jul 20 '25 18:07 siegenthalerroger