Skip to content

Commit bb1a86f

Browse files
authored
Properly handle Patroni bootstrap_labels config (#1093)
Additionally fix LOG_S3_TAGS parsing logic
1 parent 771493d commit bb1a86f

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

ENVIRONMENT.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Environment Configuration Settings
106106
- **KUBERNETES_STANDBY_LEADER_LABEL_VALUE**: value of the pod label if Postgres role is standby_leader when running on Kubernetes. Default is 'master'.
107107
- **KUBERNETES_SCOPE_LABEL**: name of the label containing cluster name. Default is 'version'.
108108
- **KUBERNETES_LABELS**: a JSON describing names and values of other labels used by Patroni on Kubernetes to locate its metadata. Default is '{"application": "spilo"}'.
109+
- **KUBERNETES_BOOTSTRAP_LABELS**: a JSON describing names and values of labels used by Patroni as ``kubernetes.bootstrap_labels``. Default is empty.
109110
- **INITDB_LOCALE**: database cluster's default UTF-8 locale (en_US by default)
110111
- **ENABLE_WAL_PATH_COMPAT**: old Spilo images were generating wal path in the backup store using the following template ``/spilo/{WAL_BUCKET_SCOPE_PREFIX}{SCOPE}{WAL_BUCKET_SCOPE_SUFFIX}/wal/``, while new images adding one additional directory (``{PGVERSION}``) to the end. In order to avoid (unlikely) issues with restoring WALs (from S3/GC/and so on) when switching to ``spilo-13`` please set the ``ENABLE_WAL_PATH_COMPAT=true`` when deploying old cluster with ``spilo-13`` for the first time. After that the environment variable could be removed. Change of the WAL path also mean that backups stored in the old location will not be cleaned up automatically.
111112
- **WALE_DISABLE_S3_SSE**, **WALG_DISABLE_S3_SSE**: by default wal-e/wal-g are configured to encrypt files uploaded to S3. In order to disable it you can set this environment variable to ``true``.

postgres-appliance/scripts/configure_spilo.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,7 @@ def get_placeholders(provider):
585585
placeholders.setdefault('KUBERNETES_LABELS', KUBERNETES_DEFAULT_LABELS)
586586
placeholders.setdefault('KUBERNETES_USE_CONFIGMAPS', '')
587587
placeholders.setdefault('KUBERNETES_BYPASS_API_SERVICE', 'true')
588+
placeholders.setdefault('KUBERNETES_BOOTSTRAP_LABELS', '')
588589
placeholders.setdefault('USE_PAUSE_AT_RECOVERY_TARGET', False)
589590
placeholders.setdefault('CLONE_METHOD', '')
590591
placeholders.setdefault('CLONE_WITH_WALE', '')
@@ -741,13 +742,15 @@ def get_dcs_config(config, placeholders):
741742

742743
if USE_KUBERNETES and placeholders.get('DCS_ENABLE_KUBERNETES_API'):
743744
config = {'kubernetes': dcs_configs['kubernetes']}
744-
try:
745-
kubernetes_labels = json.loads(config['kubernetes'].get('labels'))
746-
except (TypeError, ValueError) as e:
747-
logging.warning("could not parse kubernetes labels as a JSON: %r, "
748-
"reverting to the default: %s", e, KUBERNETES_DEFAULT_LABELS)
749-
kubernetes_labels = json.loads(KUBERNETES_DEFAULT_LABELS)
750-
config['kubernetes']['labels'] = kubernetes_labels
745+
746+
for param, default_val in (('labels', KUBERNETES_DEFAULT_LABELS), ('bootstrap_labels', '{}')):
747+
try:
748+
kubernetes_labels = json.loads(config['kubernetes'].get(param))
749+
except (TypeError, ValueError) as e:
750+
logging.warning("could not parse kubernetes %s as a JSON: %r, "
751+
"reverting to the default: %s", param, e, default_val)
752+
kubernetes_labels = json.loads(default_val)
753+
config['kubernetes'][param] = kubernetes_labels
751754

752755
if not config['kubernetes'].pop('use_configmaps'):
753756
config['kubernetes'].update({'use_endpoints': True,
@@ -792,7 +795,12 @@ def write_log_environment(placeholders):
792795
if not os.path.exists(log_env['LOG_ENV_DIR']):
793796
os.makedirs(log_env['LOG_ENV_DIR'])
794797

795-
tags = json.loads(os.getenv('LOG_S3_TAGS'))
798+
try:
799+
tags = json.loads(os.getenv('LOG_S3_TAGS'))
800+
except (TypeError, ValueError) as e:
801+
logging.warning("could not parse LOG_S3_TAGS as a JSON: %r, reverting to the default empty dict", e)
802+
tags = {}
803+
796804
log_env['LOG_S3_TAGS'] = "&".join(f"{key}={os.getenv(value)}" for key, value in tags.items())
797805

798806
for var in ('LOG_TMPDIR',

0 commit comments

Comments
 (0)