Skip to content

Commit df3aa2b

Browse files
authored
Merge pull request #140 from cybertec-postgresql/ENV
Env
2 parents ebcabee + cb675a2 commit df3aa2b

18 files changed

Lines changed: 589 additions & 149 deletions

File tree

charts/postgres-operator/crds/postgresqls.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ spec:
206206
type: string
207207
user:
208208
type: string
209+
env:
210+
type: array
211+
nullable: true
212+
items:
213+
type: object
214+
x-kubernetes-preserve-unknown-fields: true
215+
labels:
216+
type: object
217+
nullable: true
218+
additionalProperties:
219+
type: string
209220
databases:
210221
type: object
211222
additionalProperties:
@@ -375,6 +386,18 @@ spec:
375386
type: object
376387
additionalProperties:
377388
type: string
389+
monitor:
390+
nullable: true
391+
properties:
392+
image:
393+
type: string
394+
env:
395+
type: array
396+
nullable: true
397+
items:
398+
type: object
399+
x-kubernetes-preserve-unknown-fields: true
400+
type: object
378401
nodeAffinity:
379402
type: object
380403
properties:
@@ -553,6 +576,17 @@ spec:
553576
type: object
554577
additionalProperties:
555578
type: string
579+
env:
580+
type: array
581+
nullable: true
582+
items:
583+
type: object
584+
x-kubernetes-preserve-unknown-fields: true
585+
labels:
586+
type: object
587+
nullable: true
588+
additionalProperties:
589+
type: string
556590
preparedDatabases:
557591
type: object
558592
additionalProperties:
@@ -976,6 +1010,17 @@ spec:
9761010
memory:
9771011
type: string
9781012
pattern: '^(\d+(e\d+)?|\d+(\.\d+)?(e\d+)?[EPTGMK]i?)$'
1013+
env:
1014+
type: array
1015+
nullable: true
1016+
items:
1017+
type: object
1018+
x-kubernetes-preserve-unknown-fields: true
1019+
labels:
1020+
type: object
1021+
nullable: true
1022+
additionalProperties:
1023+
type: string
9791024
required:
9801025
- image
9811026
- repos

charts/postgres-operator/templates/clusterrole.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ rules:
196196
- get
197197
- list
198198
- patch
199+
- update
199200
# to CRUD cron jobs for logical backups
200201
- apiGroups:
201202
- batch

docs/hugo/content/en/connection_pooler/_index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ CPO relies on pgBouncer, a popular and above all lightweight open source tool. p
3131
- 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.
3232
- connection_pooler.mode - Defines pooler mode. Available Value: `session`, `transaction` or `statement`. Default is `transaction`.
3333
- connection_pooler.resources - Hardware definition for the pooler pods
34+
- env: Allows you to add custom environment variables
3435

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

3839
```
3940
spec:
4041
connectionPooler:
42+
env:
43+
- name: POOLER_ENV
44+
value: 'custom value'
45+
labels:
46+
custom_pooler_label: 'custom value'
4147
mode: transaction
4248
numberOfInstances: 2
4349
resources:

docs/hugo/content/en/crd/crd-postgresql.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ weight: 331
3535
| enableMasterPoolerLoadBalancer | boolean | false | Define whether to enable the load balancer pointing to the primary ConnectionPooler |
3636
| enableReplicaPoolerLoadBalancer| boolean | false | Define whether to enable the load balancer pointing to the Replica-ConnectionPooler |
3737
| 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. |
38-
| [env](#env) | array | false | Allows to add own Envs to the PostgreSQL containers |
38+
| [env](#env) | array | false | Allows you to add custom environment variables to all cluster containers |
3939
| [initContainers](#initcontainers) | array | false | Enables the definition of init-containers |
40+
| [labels](#labels) | object | false | Allows you to add custom labels to all cluster pods |
4041
| logicalBackupSchedule | string | false | Enables the scheduling of logical backups based on cron-syntax. Example: `30 00 * * *` |
4142
| maintenanceWindows | array | false | Enables the definition of maintenance windows for the cluster. Example: `Sat:00:00-04:00` |
4243
| masterServiceAnnotations | map | false | Enables the definition of annotations for the Primary Service |
@@ -113,6 +114,9 @@ key, operator, value, effect and tolerationSeconds |
113114

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

150154
---
151155

156+
#### labels
157+
158+
| Name | Type | required | Description |
159+
| ------------------------------ |:-------:| ---------:| ------------------:|
160+
| <key> | string | true | Namefield for the label |
161+
| <value> | string | true | Value for the label |
162+
163+
{{< back >}}
164+
165+
---
166+
152167
#### monitor
153168

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

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

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

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
title: "Environment variables"
3+
date: 2023-12-28T14:26:51+01:00
4+
draft: false
5+
weight: 1
6+
---
7+
8+
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.
9+
Hierarchy and Scope
10+
The variables are defined within the Custom Resource (CR). The following logic applies for inheritance and assignment:
11+
12+
| object | Scope | Description |
13+
| :--- | :--- | :--- |
14+
| `spec.env` | **Global** | These ENVs are inherited by **all** containers within the cluster (PostgreSQL, Backup, Monitoring, etc.). |
15+
| `spec.postgresql.env` | **PostgreSQL** | These ENVs apply exclusively to the **PostgreSQL containers**. |
16+
| `spec.backup.pgbackrest.env` | **pgBackRest** | These ENVs apply exclusively to the **Backup containers**. |
17+
| `spec.monitor.env` | **Exporter-Sidecar** | These ENVs apply exclusively to the **ConnectionPooler containers**. |
18+
| `spec.connectionPooler.env` | **ConnectionPooler** | These ENVs apply exclusively to the **Monitoring sidecars**. |
19+
20+
{{< hint type=Warning >}}Updating the ENVs triggers a rolling update to the respective containers.{{< /hint >}}
21+
22+
23+
### Configuration Logic
24+
25+
The definition of variables follows the standard Kubernetes schema for key-value pairs.
26+
27+
```yaml
28+
env:
29+
- name: ENV_NAME
30+
value: ‘value’
31+
```
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: "Custom Labels"
3+
date: 2023-12-28T14:26:51+01:00
4+
draft: false
5+
weight: 2
6+
---
7+
8+
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.
9+
10+
| object | Scope | Description |
11+
| :--- | :--- | :--- |
12+
| `spec.labels` | **Global** | These labels are adopted by **all** pods within the cluster (**PostgreSQL**, **Backup**, **Pooler**, etc.). |
13+
| `spec.postgresql.labels` | **PostgreSQL** | These labels apply exclusively to the PostgreSQL pods. **PostgreSQL pods**. |
14+
| `spec.backup.pgbackrest.labels` | **pgBackRest** | These labels apply exclusively to the backup pods **pgBackRest pods**. |
15+
| `spec.connectionPooler.labels` | **ConnectionPooler** | These labels apply exclusively to the **ConnectionPooler pods**. |
16+
17+
{{< hint type=Warning >}}Updating the labels triggers a rolling update to the respective pods.{{< /hint >}}
18+
19+
20+
### Configuration Logic
21+
22+
The definition of labels follows the standard Kubernetes schema for key-value pairs.
23+
24+
```yaml
25+
labels:
26+
custom_label: ‘value’
27+
```

docs/hugo/content/en/customize_cluster/sidecars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "Sidecars"
33
date: 2023-12-28T14:26:51+01:00
44
draft: false
5-
weight: 1
5+
weight: 2
66
---
77
Starting with the Single-Node-Cluster from the previous section, we want to modify the Instance a bit to see.
88
## CPU and Memory

pkg/apis/cpo.opensource.cybertec.at/v1/crds.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,26 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
338338
"user": {
339339
Type: "string",
340340
},
341+
"env": {
342+
Type: "array",
343+
Nullable: true,
344+
Items: &apiextv1.JSONSchemaPropsOrArray{
345+
Schema: &apiextv1.JSONSchemaProps{
346+
Type: "object",
347+
XPreserveUnknownFields: util.True(),
348+
},
349+
},
350+
},
351+
"labels": {
352+
Type: "object",
353+
Nullable: true,
354+
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
355+
Allows: true,
356+
Schema: &apiextv1.JSONSchemaProps{
357+
Type: "string",
358+
},
359+
},
360+
},
341361
},
342362
},
343363
"databases": {
@@ -385,6 +405,16 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
385405
},
386406
},
387407
},
408+
"labels": {
409+
Type: "object",
410+
Nullable: true,
411+
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
412+
Allows: true,
413+
Schema: &apiextv1.JSONSchemaProps{
414+
Type: "string",
415+
},
416+
},
417+
},
388418
"init_containers": {
389419
Type: "array",
390420
Description: "deprecated",
@@ -759,6 +789,26 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
759789
},
760790
},
761791
},
792+
"env": {
793+
Type: "array",
794+
Nullable: true,
795+
Items: &apiextv1.JSONSchemaPropsOrArray{
796+
Schema: &apiextv1.JSONSchemaProps{
797+
Type: "object",
798+
XPreserveUnknownFields: util.True(),
799+
},
800+
},
801+
},
802+
"labels": {
803+
Type: "object",
804+
Nullable: true,
805+
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
806+
Allows: true,
807+
Schema: &apiextv1.JSONSchemaProps{
808+
Type: "string",
809+
},
810+
},
811+
},
762812
},
763813
},
764814
"preparedDatabases": {
@@ -1433,6 +1483,26 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
14331483
},
14341484
},
14351485
},
1486+
"env": {
1487+
Type: "array",
1488+
Nullable: true,
1489+
Items: &apiextv1.JSONSchemaPropsOrArray{
1490+
Schema: &apiextv1.JSONSchemaProps{
1491+
Type: "object",
1492+
XPreserveUnknownFields: util.True(),
1493+
},
1494+
},
1495+
},
1496+
"labels": {
1497+
Type: "object",
1498+
Nullable: true,
1499+
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
1500+
Allows: true,
1501+
Schema: &apiextv1.JSONSchemaProps{
1502+
Type: "string",
1503+
},
1504+
},
1505+
},
14361506
},
14371507
},
14381508
},
@@ -1465,6 +1535,16 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
14651535
"image": {
14661536
Type: "string",
14671537
},
1538+
"env": {
1539+
Type: "array",
1540+
Nullable: true,
1541+
Items: &apiextv1.JSONSchemaPropsOrArray{
1542+
Schema: &apiextv1.JSONSchemaProps{
1543+
Type: "object",
1544+
XPreserveUnknownFields: util.True(),
1545+
},
1546+
},
1547+
},
14681548
},
14691549
},
14701550
},

0 commit comments

Comments
 (0)