Skip to content

Commit 168abfe

Browse files
authored
Fully speced global sidecars (zalando#890)
* implement fully speced global sidecars * fix issue zalando#924
1 parent f32c615 commit 168abfe

File tree

15 files changed

+462
-140
lines changed

15 files changed

+462
-140
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ spec:
8484
type: object
8585
additionalProperties:
8686
type: string
87+
sidecars:
88+
type: array
89+
nullable: true
90+
items:
91+
type: object
92+
additionalProperties: true
8793
workers:
8894
type: integer
8995
minimum: 1

docs/administrator.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,33 @@ A secret can be pre-provisioned in different ways:
507507
* Automatically provisioned via a custom K8s controller like
508508
[kube-aws-iam-controller](https://github.com/mikkeloscar/kube-aws-iam-controller)
509509

510+
## Sidecars for Postgres clusters
511+
512+
A list of sidecars is added to each cluster created by the
513+
operator. The default is empty list.
514+
515+
516+
```yaml
517+
kind: OperatorConfiguration
518+
configuration:
519+
sidecars:
520+
- image: image:123
521+
name: global-sidecar
522+
ports:
523+
- containerPort: 80
524+
volumeMounts:
525+
- mountPath: /custom-pgdata-mountpoint
526+
name: pgdata
527+
- ...
528+
```
529+
530+
In addition to any environment variables you specify, the following environment variables are always passed to sidecars:
531+
532+
- `POD_NAME` - field reference to `metadata.name`
533+
- `POD_NAMESPACE` - field reference to `metadata.namespace`
534+
- `POSTGRES_USER` - the superuser that can be used to connect to the database
535+
- `POSTGRES_PASSWORD` - the password for the superuser
536+
510537
## Setting up the Postgres Operator UI
511538

512539
Since the v1.2 release the Postgres Operator is shipped with a browser-based

docs/reference/operator_parameters.md

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,17 @@ Those are top-level keys, containing both leaf keys and groups.
9393
repository](https://github.com/zalando/spilo).
9494

9595
* **sidecar_docker_images**
96-
a map of sidecar names to Docker images to run with Spilo. In case of the name
97-
conflict with the definition in the cluster manifest the cluster-specific one
98-
is preferred.
96+
*deprecated*: use **sidecars** instead. A map of sidecar names to Docker images to
97+
run with Spilo. In case of the name conflict with the definition in the cluster
98+
manifest the cluster-specific one is preferred.
99+
100+
* **sidecars**
101+
a list of sidecars to run with Spilo, for any cluster (i.e. globally defined sidecars).
102+
Each item in the list is of type
103+
[Container](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#container-v1-core).
104+
Globally defined sidecars can be overwritten by specifying a sidecar in the custom resource with
105+
the same name. Note: This field is not part of the schema validation. If the container specification
106+
is invalid, then the operator fails to create the statefulset.
99107

100108
* **enable_shm_volume**
101109
Instruct operator to start any new database pod without limitations on shm
@@ -133,8 +141,9 @@ Those are top-level keys, containing both leaf keys and groups.
133141
at the cost of overprovisioning memory and potential scheduling problems for
134142
containers with high memory limits due to the lack of memory on Kubernetes
135143
cluster nodes. This affects all containers created by the operator (Postgres,
136-
Scalyr sidecar, and other sidecars); to set resources for the operator's own
137-
container, change the [operator deployment manually](../../manifests/postgres-operator.yaml#L20).
144+
Scalyr sidecar, and other sidecars except **sidecars** defined in the operator
145+
configuration); to set resources for the operator's own container, change the
146+
[operator deployment manually](../../manifests/postgres-operator.yaml#L20).
138147
The default is `false`.
139148

140149
## Postgres users
@@ -206,12 +215,12 @@ configuration they are grouped under the `kubernetes` key.
206215
Default is true.
207216

208217
* **enable_init_containers**
209-
global option to allow for creating init containers to run actions before
210-
Spilo is started. Default is true.
218+
global option to allow for creating init containers in the cluster manifest to
219+
run actions before Spilo is started. Default is true.
211220

212221
* **enable_sidecars**
213-
global option to allow for creating sidecar containers to run alongside Spilo
214-
on the same pod. Default is true.
222+
global option to allow for creating sidecar containers in the cluster manifest
223+
to run alongside Spilo on the same pod. Globally defined sidecars are always enabled. Default is true.
215224

216225
* **secret_name_template**
217226
a template for the name of the database user secrets generated by the

docs/user.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,8 @@ The PostgreSQL volume is shared with sidecars and is mounted at
442442
specified but globally disabled in the configuration. The `enable_sidecars`
443443
option must be set to `true`.
444444

445+
If you want to add a sidecar to every cluster managed by the operator, you can specify it in the [operator configuration](administrator.md#sidecars-for-postgres-clusters) instead.
446+
445447
## InitContainers Support
446448

447449
Each cluster can specify arbitrary init containers to run. These containers can

manifests/operatorconfiguration.crd.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ spec:
6060
type: object
6161
additionalProperties:
6262
type: string
63+
sidecars:
64+
type: array
65+
nullable: true
66+
items:
67+
type: object
68+
additionalProperties: true
6369
workers:
6470
type: integer
6571
minimum: 1

manifests/postgresql-operator-default-configuration.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ configuration:
1313
resync_period: 30m
1414
repair_period: 5m
1515
# set_memory_request_to_limit: false
16-
# sidecar_docker_images:
17-
# example: "exampleimage:exampletag"
16+
# sidecars:
17+
# - image: image:123
18+
# name: global-sidecar-1
19+
# ports:
20+
# - containerPort: 80
1821
workers: 4
1922
users:
2023
replication_username: standby

pkg/apis/acid.zalan.do/v1/crds.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,17 @@ var OperatorConfigCRDResourceValidation = apiextv1beta1.CustomResourceValidation
797797
},
798798
},
799799
},
800+
"sidecars": {
801+
Type: "array",
802+
Items: &apiextv1beta1.JSONSchemaPropsOrArray{
803+
Schema: &apiextv1beta1.JSONSchemaProps{
804+
Type: "object",
805+
AdditionalProperties: &apiextv1beta1.JSONSchemaPropsOrBool{
806+
Allows: true,
807+
},
808+
},
809+
},
810+
},
800811
"workers": {
801812
Type: "integer",
802813
Minimum: &min1,

pkg/apis/acid.zalan.do/v1/operator_configuration_type.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"time"
99

1010
"github.com/zalando/postgres-operator/pkg/spec"
11+
v1 "k8s.io/api/core/v1"
1112
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1213
)
1314

@@ -181,18 +182,20 @@ type OperatorLogicalBackupConfiguration struct {
181182

182183
// OperatorConfigurationData defines the operation config
183184
type OperatorConfigurationData struct {
184-
EnableCRDValidation *bool `json:"enable_crd_validation,omitempty"`
185-
EtcdHost string `json:"etcd_host,omitempty"`
186-
KubernetesUseConfigMaps bool `json:"kubernetes_use_configmaps,omitempty"`
187-
DockerImage string `json:"docker_image,omitempty"`
188-
Workers uint32 `json:"workers,omitempty"`
189-
MinInstances int32 `json:"min_instances,omitempty"`
190-
MaxInstances int32 `json:"max_instances,omitempty"`
191-
ResyncPeriod Duration `json:"resync_period,omitempty"`
192-
RepairPeriod Duration `json:"repair_period,omitempty"`
193-
SetMemoryRequestToLimit bool `json:"set_memory_request_to_limit,omitempty"`
194-
ShmVolume *bool `json:"enable_shm_volume,omitempty"`
195-
Sidecars map[string]string `json:"sidecar_docker_images,omitempty"`
185+
EnableCRDValidation *bool `json:"enable_crd_validation,omitempty"`
186+
EtcdHost string `json:"etcd_host,omitempty"`
187+
KubernetesUseConfigMaps bool `json:"kubernetes_use_configmaps,omitempty"`
188+
DockerImage string `json:"docker_image,omitempty"`
189+
Workers uint32 `json:"workers,omitempty"`
190+
MinInstances int32 `json:"min_instances,omitempty"`
191+
MaxInstances int32 `json:"max_instances,omitempty"`
192+
ResyncPeriod Duration `json:"resync_period,omitempty"`
193+
RepairPeriod Duration `json:"repair_period,omitempty"`
194+
SetMemoryRequestToLimit bool `json:"set_memory_request_to_limit,omitempty"`
195+
ShmVolume *bool `json:"enable_shm_volume,omitempty"`
196+
// deprecated in favour of SidecarContainers
197+
SidecarImages map[string]string `json:"sidecar_docker_images,omitempty"`
198+
SidecarContainers []v1.Container `json:"sidecars,omitempty"`
196199
PostgresUsersConfiguration PostgresUsersConfiguration `json:"users"`
197200
Kubernetes KubernetesMetaConfiguration `json:"kubernetes"`
198201
PostgresPodResources PostgresPodResourcesDefaults `json:"postgres_pod_resources"`

pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go

Lines changed: 9 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)