Skip to content
Merged

Env #140

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ae8faeb
added ENV for postgres,pgbackrest,monitor & connectionPooler
Schmaetz Mar 20, 2026
c9caf49
added ENV for postgres,pgbackrest,monitor & connectionPooler
Schmaetz Mar 20, 2026
7462e0a
added missing exporter-object and new env-objects
Schmaetz Mar 20, 2026
f7c7ebd
added global and pg-specific env to pg-container
Schmaetz Mar 20, 2026
1780a19
added ENVs to postgres and pgbackrest containers (container, init-con…
Schmaetz Mar 20, 2026
d6a9076
added ENVs to connection-pooler
Schmaetz Mar 20, 2026
908b357
added ENVs to postgres and pgbackrest containers (container, init-con…
Schmaetz Mar 20, 2026
5a423ef
crd fix for env (connection-pooler)
Schmaetz Mar 21, 2026
5c626e4
update crd-docu
Schmaetz Mar 21, 2026
36e4a51
added ENV to pooler doc
Schmaetz Mar 21, 2026
965c8c3
add ENV to documentation and change weight for pages
Schmaetz Mar 23, 2026
6ac945d
add label-array to crd
Schmaetz Mar 23, 2026
41dee35
remove labels from monitor-object, bcs. only use postgres-object for …
Schmaetz Mar 23, 2026
fc72867
updated crd labels with value
Schmaetz Mar 23, 2026
38268ad
add labels to connectionpooler
Schmaetz Mar 23, 2026
7abe034
update util.go for handling pod-specific-labels
Schmaetz Mar 23, 2026
c6b8c56
update util.go for handling pod-specific-labels
Schmaetz Mar 23, 2026
26a1c14
Ensure based on label changes pooler deployment is synced
Schmaetz Mar 23, 2026
ec804f9
add labels to connectionPooler and update code and test_class
Schmaetz Mar 26, 2026
396f08a
add labels
Schmaetz Mar 26, 2026
fb23185
add labels to connectionPooler, postgres,pgbackrest
Schmaetz Mar 26, 2026
53fcb13
update crd and rbac
Schmaetz Mar 26, 2026
1db26bb
upodate crd docu
Schmaetz Mar 26, 2026
cdc24a6
change label syntax in crd and all references
Schmaetz Mar 26, 2026
9e16d9f
ensure pgbackrest-job is updated in case if label changes
Schmaetz Mar 26, 2026
40669cc
add logging info for labels-sync
Schmaetz Mar 26, 2026
cb675a2
update labels in crd chart
Schmaetz Mar 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions charts/postgres-operator/crds/postgresqls.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ spec:
type: string
user:
type: string
env:
type: array
nullable: true
items:
type: object
x-kubernetes-preserve-unknown-fields: true
labels:
type: object
nullable: true
additionalProperties:
type: string
databases:
type: object
additionalProperties:
Expand Down Expand Up @@ -375,6 +386,18 @@ spec:
type: object
additionalProperties:
type: string
monitor:
nullable: true
properties:
image:
type: string
env:
type: array
nullable: true
items:
type: object
x-kubernetes-preserve-unknown-fields: true
type: object
nodeAffinity:
type: object
properties:
Expand Down Expand Up @@ -553,6 +576,17 @@ spec:
type: object
additionalProperties:
type: string
env:
type: array
nullable: true
items:
type: object
x-kubernetes-preserve-unknown-fields: true
labels:
type: object
nullable: true
additionalProperties:
type: string
preparedDatabases:
type: object
additionalProperties:
Expand Down Expand Up @@ -976,6 +1010,17 @@ spec:
memory:
type: string
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
env:
type: array
nullable: true
items:
type: object
x-kubernetes-preserve-unknown-fields: true
labels:
type: object
nullable: true
additionalProperties:
type: string
required:
- image
- repos
Expand Down
1 change: 1 addition & 0 deletions charts/postgres-operator/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ rules:
- get
- list
- patch
- update
# to CRUD cron jobs for logical backups
- apiGroups:
- batch
Expand Down
6 changes: 6 additions & 0 deletions docs/hugo/content/en/connection_pooler/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ CPO relies on pgBouncer, a popular and above all lightweight open source tool. p
- connection_poole.max_db_connections - How many connections the pooler can max hold. This value is divided among the pooler pods. Default is 60 which will make up 30 connections per pod for the default setup with two instances.
- connection_pooler.mode - Defines pooler mode. Available Value: `session`, `transaction` or `statement`. Default is `transaction`.
- connection_pooler.resources - Hardware definition for the pooler pods
- env: Allows you to add custom environment variables

- enableConnectionPooler - Defines whether poolers for read/write access should be created based on the spec.connectionPooler definition.
- enableReplicaConnectionPooler- Defines whether poolers for read-only access should be created based on the spec.connectionPooler definition.

```
spec:
connectionPooler:
env:
- name: POOLER_ENV
value: 'custom value'
labels:
custom_pooler_label: 'custom value'
mode: transaction
numberOfInstances: 2
resources:
Expand Down
22 changes: 21 additions & 1 deletion docs/hugo/content/en/crd/crd-postgresql.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ weight: 331
| enableMasterPoolerLoadBalancer | boolean | false | Define whether to enable the load balancer pointing to the primary ConnectionPooler |
| enableReplicaPoolerLoadBalancer| boolean | false | Define whether to enable the load balancer pointing to the Replica-ConnectionPooler |
| enableShmVolume | boolean | false | Start a database pod without limitations on shm memory. By default Docker limit /dev/shm to 64M (see e.g. the docker issue, which could be not enough if PostgreSQL uses parallel workers heavily. If this option is present and value is true, to the target database pod will be mounted a new tmpfs volume to remove this limitation. |
| [env](#env) | array | false | Allows to add own Envs to the PostgreSQL containers |
| [env](#env) | array | false | Allows you to add custom environment variables to all cluster containers |
| [initContainers](#initcontainers) | array | false | Enables the definition of init-containers |
| [labels](#labels) | object | false | Allows you to add custom labels to all cluster pods |
| logicalBackupSchedule | string | false | Enables the scheduling of logical backups based on cron-syntax. Example: `30 00 * * *` |
| maintenanceWindows | array | false | Enables the definition of maintenance windows for the cluster. Example: `Sat:00:00-04:00` |
| masterServiceAnnotations | map | false | Enables the definition of annotations for the Primary Service |
Expand Down Expand Up @@ -113,6 +114,9 @@ key, operator, value, effect and tolerationSeconds |

| Name | Type | required | Description |
| ------------------------------ |:-------:| ---------:| ------------------:|
| [env](#env) | array | false | Allows you to add custom environment variables to connection-pooler containers |
| [labels](#labels) | object | false | Allows you to add custom labels to connection-pooler pods |
| dockerImage | string | true | Defines the used pgbouncer container image for this cluster |
| numberOfInstances | int | true | Number of Pods per Pooler |
| mode | string | true | pooling mode for pgBouncer (session, transaction, statement) |
| schema | string | true | Schema for Pooler (Default: pooler) |
Expand Down Expand Up @@ -149,10 +153,22 @@ key, operator, value, effect and tolerationSeconds |

---

#### labels

| Name | Type | required | Description |
| ------------------------------ |:-------:| ---------:| ------------------:|
| <key> | string | true | Namefield for the label |
| <value> | string | true | Value for the label |

{{< back >}}

---

#### monitor

| Name | Type | required | Description |
| ------------------------------ |:-------:| ---------:| ------------------:|
| [env](#env) | array | false | Allows you to add custom environment variables to all expoerter-sidecar containers |
| image | string | true | Docker-Image for the metric exporter |

{{< back >}}
Expand Down Expand Up @@ -184,6 +200,8 @@ key, operator, value, effect and tolerationSeconds |

| Name | Type | required | Description |
| ------------------------------ |:-------:| ---------:| ------------------:|
| [env](#env) | array | false | Allows you to add custom environment variables to all postgresql containers |
| [labels](#labels) | object | false | Allows you to add custom labels to poostgresql pods |
| parameters | map | false | PostgreSQL-Parameter as item (Example: max_connections: "100"). For help check out the [CYBERTEC PostgreSQL Configurator](https://pgconfigurator.cybertec.at) |
| version | string | false | a map of key-value pairs describing initdb parameters |

Expand Down Expand Up @@ -401,8 +419,10 @@ key, operator, value, effect and tolerationSeconds |
| Name | Type | required | Description |
| ------------------------------ |:-------:| ---------:| ------------------:|
| [configuration](#configuration)| object | false | Enables the definition of a pgbackrest-setup for the cluster |
| [env](#env) | array | false | Allows you to add custom environment variables to all pgbackrest containers |
| global | object | false | |
| image | string | true | |
| [labels](#labels) | object | false | Allows you to add custom labels to pgbackrest pods |
| [repos](#repos) | array | true | |
| [resources](#resources) | object | false | CPU & Memory (Limit & Request) definition for the pgBackRest container|

Expand Down
31 changes: 31 additions & 0 deletions docs/hugo/content/en/customize_cluster/env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: "Environment variables"
date: 2023-12-28T14:26:51+01:00
draft: false
weight: 1
---

To flexibly manage containers within a cluster, the operator allows environment variables to be defined at various levels. This enables both global settings and specific configurations for individual components.
Hierarchy and Scope
The variables are defined within the Custom Resource (CR). The following logic applies for inheritance and assignment:

| object | Scope | Description |
| :--- | :--- | :--- |
| `spec.env` | **Global** | These ENVs are inherited by **all** containers within the cluster (PostgreSQL, Backup, Monitoring, etc.). |
| `spec.postgresql.env` | **PostgreSQL** | These ENVs apply exclusively to the **PostgreSQL containers**. |
| `spec.backup.pgbackrest.env` | **pgBackRest** | These ENVs apply exclusively to the **Backup containers**. |
| `spec.monitor.env` | **Exporter-Sidecar** | These ENVs apply exclusively to the **ConnectionPooler containers**. |
| `spec.connectionPooler.env` | **ConnectionPooler** | These ENVs apply exclusively to the **Monitoring sidecars**. |

{{< hint type=Warning >}}Updating the ENVs triggers a rolling update to the respective containers.{{< /hint >}}


### Configuration Logic

The definition of variables follows the standard Kubernetes schema for key-value pairs.

```yaml
env:
- name: ENV_NAME
value: ‘value’
```
27 changes: 27 additions & 0 deletions docs/hugo/content/en/customize_cluster/labels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: "Custom Labels"
date: 2023-12-28T14:26:51+01:00
draft: false
weight: 2
---

To manage and organise pods flexibly within a cluster, the operator allows labels to be defined at various levels. This enables both global labelling and specific metadata for individual components. Unlike environment variables, labels always refer to the pod as a whole, not to individual containers.

| object | Scope | Description |
| :--- | :--- | :--- |
| `spec.labels` | **Global** | These labels are adopted by **all** pods within the cluster (**PostgreSQL**, **Backup**, **Pooler**, etc.). |
| `spec.postgresql.labels` | **PostgreSQL** | These labels apply exclusively to the PostgreSQL pods. **PostgreSQL pods**. |
| `spec.backup.pgbackrest.labels` | **pgBackRest** | These labels apply exclusively to the backup pods **pgBackRest pods**. |
| `spec.connectionPooler.labels` | **ConnectionPooler** | These labels apply exclusively to the **ConnectionPooler pods**. |

{{< hint type=Warning >}}Updating the labels triggers a rolling update to the respective pods.{{< /hint >}}


### Configuration Logic

The definition of labels follows the standard Kubernetes schema for key-value pairs.

```yaml
labels:
custom_label: ‘value’
```
2 changes: 1 addition & 1 deletion docs/hugo/content/en/customize_cluster/sidecars.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Sidecars"
date: 2023-12-28T14:26:51+01:00
draft: false
weight: 1
weight: 2
---
Starting with the Single-Node-Cluster from the previous section, we want to modify the Instance a bit to see.
## CPU and Memory
Expand Down
80 changes: 80 additions & 0 deletions pkg/apis/cpo.opensource.cybertec.at/v1/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,26 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
"user": {
Type: "string",
},
"env": {
Type: "array",
Nullable: true,
Items: &apiextv1.JSONSchemaPropsOrArray{
Schema: &apiextv1.JSONSchemaProps{
Type: "object",
XPreserveUnknownFields: util.True(),
},
},
},
"labels": {
Type: "object",
Nullable: true,
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
Allows: true,
Schema: &apiextv1.JSONSchemaProps{
Type: "string",
},
},
},
},
},
"databases": {
Expand Down Expand Up @@ -385,6 +405,16 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
},
},
},
"labels": {
Type: "object",
Nullable: true,
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
Allows: true,
Schema: &apiextv1.JSONSchemaProps{
Type: "string",
},
},
},
"init_containers": {
Type: "array",
Description: "deprecated",
Expand Down Expand Up @@ -759,6 +789,26 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
},
},
},
"env": {
Type: "array",
Nullable: true,
Items: &apiextv1.JSONSchemaPropsOrArray{
Schema: &apiextv1.JSONSchemaProps{
Type: "object",
XPreserveUnknownFields: util.True(),
},
},
},
"labels": {
Type: "object",
Nullable: true,
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
Allows: true,
Schema: &apiextv1.JSONSchemaProps{
Type: "string",
},
},
},
},
},
"preparedDatabases": {
Expand Down Expand Up @@ -1433,6 +1483,26 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
},
},
},
"env": {
Type: "array",
Nullable: true,
Items: &apiextv1.JSONSchemaPropsOrArray{
Schema: &apiextv1.JSONSchemaProps{
Type: "object",
XPreserveUnknownFields: util.True(),
},
},
},
"labels": {
Type: "object",
Nullable: true,
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
Allows: true,
Schema: &apiextv1.JSONSchemaProps{
Type: "string",
},
},
},
},
},
},
Expand Down Expand Up @@ -1465,6 +1535,16 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
"image": {
Type: "string",
},
"env": {
Type: "array",
Nullable: true,
Items: &apiextv1.JSONSchemaPropsOrArray{
Schema: &apiextv1.JSONSchemaProps{
Type: "object",
XPreserveUnknownFields: util.True(),
},
},
},
},
},
},
Expand Down
Loading
Loading