Skip to content

Commit 107334f

Browse files
authored
Add global option to enable/disable init containers and sidecars (zalando#478)
* Add global option to enable/disable init containers and sidecars * update dependencies
1 parent 0761165 commit 107334f

21 files changed

+138
-47
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ spec:
107107
type: object
108108
additionalProperties:
109109
type: string
110+
enable_init_containers:
111+
type: boolean
110112
enable_pod_antiaffinity:
111113
type: boolean
112114
enable_pod_disruption_budget:
113115
type: boolean
116+
enable_sidecars:
117+
type: boolean
114118
infrastructure_roles_secret_name:
115119
type: string
116120
inherited_labels:

charts/postgres-operator/values-crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,14 @@ configKubernetes:
6363
# keya: valuea
6464
# keyb: valueb
6565

66+
# enables initContainers to run actions before Spilo is started
67+
enable_init_containers: true
6668
# toggles pod anti affinity on the Postgres pods
6769
enable_pod_antiaffinity: false
6870
# toggles PDB to set to MinAvailabe 0 or 1
6971
enable_pod_disruption_budget: true
72+
# enables sidecar containers to run alongside Spilo in the same pod
73+
enable_sidecars: true
7074
# name of the secret containing infrastructure roles names and passwords
7175
# infrastructure_roles_secret_name: postgresql-infrastructure-roles
7276

charts/postgres-operator/values.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ configKubernetes:
5757
# label assigned to Kubernetes objects created by the operator
5858
cluster_name_label: version
5959
# annotations attached to each database pod
60-
# custom_pod_annotations: keya:valuea,keyb:valueb
60+
# custom_pod_annotations: "keya:valuea,keyb:valueb"
6161

62+
# enables initContainers to run actions before Spilo is started
63+
enable_init_containers: "true"
6264
# toggles pod anti affinity on the Postgres pods
6365
enable_pod_antiaffinity: "false"
6466
# toggles PDB to set to MinAvailabe 0 or 1
6567
enable_pod_disruption_budget: "true"
68+
# enables sidecar containers to run alongside Spilo in the same pod
69+
enable_sidecars: "true"
6670
# name of the secret containing infrastructure roles names and passwords
6771
# infrastructure_roles_secret_name: postgresql-infrastructure-roles
6872

docs/reference/operator_parameters.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ Those are top-level keys, containing both leaf keys and groups.
8787
repository](https://github.com/zalando/spilo).
8888

8989
* **sidecar_docker_images**
90-
a map of sidecar names to docker images for the containers to run alongside
91-
Spilo. In case of the name conflict with the definition in the cluster
92-
manifest the cluster-specific one is preferred.
90+
a map of sidecar names to docker images to run with Spilo. In case of the name
91+
conflict with the definition in the cluster manifest the cluster-specific one
92+
is preferred.
9393

9494
* **enable_shm_volume**
9595
Instruct operator to start any new database pod without limitations on shm
@@ -196,6 +196,14 @@ configuration they are grouped under the `kubernetes` key.
196196
[admin docs](../administrator.md#pod-disruption-budget) for more information.
197197
Default is true.
198198

199+
* **enable_init_containers**
200+
global option to allow for creating init containers to run actions before
201+
Spilo is started. Default is true.
202+
203+
* **enable_sidecars**
204+
global option to allow for creating sidecar containers to run alongside Spilo
205+
on the same pod. Default is true.
206+
199207
* **secret_name_template**
200208
a template for the name of the database user secrets generated by the
201209
operator. `{username}` is replaced with name of the secret, `{cluster}` with

docs/user.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,10 @@ variables are always passed to sidecars:
350350
The PostgreSQL volume is shared with sidecars and is mounted at
351351
`/home/postgres/pgdata`.
352352

353+
**Note**: The operator will not create a cluster if sidecar containers are
354+
specified but globally disabled in the configuration. The `enable_sidecars`
355+
option must be set to `true`.
356+
353357
## InitContainers Support
354358

355359
Each cluster can specify arbitrary init containers to run. These containers can
@@ -374,6 +378,10 @@ spec:
374378

375379
`initContainers` accepts full `v1.Container` definition.
376380

381+
**Note**: The operator will not create a cluster if `initContainers` are
382+
specified but globally disabled in the configuration. The
383+
`enable_init_containers` option must be set to `true`.
384+
377385
## Increase volume size
378386

379387
PostgreSQL operator supports statefulset volume resize if you're using the

e2e/tests/test_e2e.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,17 +182,12 @@ def test_logical_backup_cron_job(self):
182182

183183
# update the cluster-wide image of the logical backup pod
184184
image = "test-image-name"
185-
config_map_patch = {
185+
patch_logical_backup_image = {
186186
"data": {
187187
"logical_backup_docker_image": image,
188188
}
189189
}
190-
k8s.api.core_v1.patch_namespaced_config_map("postgres-operator", "default", config_map_patch)
191-
192-
operator_pod = k8s.api.core_v1.list_namespaced_pod(
193-
'default', label_selector="name=postgres-operator").items[0].metadata.name
194-
k8s.api.core_v1.delete_namespaced_pod(operator_pod, "default") # restart reloads the conf
195-
k8s.wait_for_operator_pod_start()
190+
k8s.update_config(patch_logical_backup_image)
196191

197192
jobs = k8s.get_logical_backup_job().items
198193
actual_image = jobs[0].spec.job_template.spec.template.spec.containers[0].image
@@ -319,6 +314,14 @@ def wait_for_logical_backup_job_deletion(self):
319314
def wait_for_logical_backup_job_creation(self):
320315
self.wait_for_logical_backup_job(expected_num_of_jobs=1)
321316

317+
def update_config(self, config_map_patch):
318+
self.api.core_v1.patch_namespaced_config_map("postgres-operator", "default", config_map_patch)
319+
320+
operator_pod = self.api.core_v1.list_namespaced_pod(
321+
'default', label_selector="name=postgres-operator").items[0].metadata.name
322+
self.api.core_v1.delete_namespaced_pod(operator_pod, "default") # restart reloads the conf
323+
self.wait_for_operator_pod_start()
324+
322325
def create_with_kubectl(self, path):
323326
subprocess.run(["kubectl", "create", "-f", path])
324327

go.mod

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ module github.com/zalando/postgres-operator
33
go 1.12
44

55
require (
6-
github.com/aws/aws-sdk-go v1.25.1
7-
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
8-
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
9-
github.com/googleapis/gnostic v0.3.0 // indirect
10-
github.com/imdario/mergo v0.3.7 // indirect
6+
github.com/aws/aws-sdk-go v1.25.44
7+
github.com/imdario/mergo v0.3.8 // indirect
118
github.com/lib/pq v1.2.0
129
github.com/motomux/pretty v0.0.0-20161209205251-b2aad2c9a95d
1310
github.com/sirupsen/logrus v1.4.2
14-
golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c // indirect
11+
golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e // indirect
1512
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 // indirect
1613
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
17-
golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f // indirect
14+
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d // indirect
1815
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
19-
gopkg.in/yaml.v2 v2.2.5
16+
gopkg.in/yaml.v2 v2.2.4
2017
k8s.io/api v0.0.0-20191121015604-11707872ac1c
2118
k8s.io/apiextensions-apiserver v0.0.0-20191121021419-88daf26ec3b8
2219
k8s.io/apimachinery v0.0.0-20191121015412-41065c7a8c2a
2320
k8s.io/client-go v11.0.0+incompatible
2421
k8s.io/code-generator v0.0.0-20191121015212-c4c8f8345c7e
22+
sigs.k8s.io/kind v0.5.1 // indirect
2523
)

0 commit comments

Comments
 (0)