Skip to content

Commit d7e1fb5

Browse files
authored
polish global config about sharing postgresql-run socket (zalando#2155)
* polish global config about sharing postgresql-run socket
1 parent be7b52d commit d7e1fb5

File tree

16 files changed

+159
-89
lines changed

16 files changed

+159
-89
lines changed

charts/postgres-operator/crds/operatorconfigurations.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ spec:
314314
secret_name_template:
315315
type: string
316316
default: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
317+
share_pgsocket_with_sidecars:
318+
type: boolean
319+
default: false
317320
spilo_allow_privilege_escalation:
318321
type: boolean
319322
default: true

charts/postgres-operator/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ configKubernetes:
191191
# if the user is in different namespace than cluster and cross namespace secrets
192192
# are enabled via `enable_cross_namespace_secret` flag in the configuration.
193193
secret_name_template: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
194+
# sharing unix socket of PostgreSQL (`pg_socket`) with the sidecars
195+
share_pgsocket_with_sidecars: false
194196
# set user and group for the spilo container (required to run Spilo as non-root process)
195197
# spilo_runasuser: 101
196198
# spilo_runasgroup: 103
199+
197200
# group ID with write-access to volumes (required to run Spilo as non-root process)
198201
# spilo_fsgroup: 103
199202

docs/reference/operator_parameters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ configuration they are grouped under the `kubernetes` key.
344344
to run alongside Spilo on the same pod. Globally defined sidecars are always
345345
enabled. Default is true.
346346

347-
* **share_pg_socket_with_sidecars**
347+
* **share_pgsocket_with_sidecars**
348348
global option to create an emptyDir volume named `postgresql-run`. This is
349349
mounted by all containers at `/var/run/postgresql` sharing the unix socket of
350350
PostgreSQL (`pg_socket`) with the sidecars this way.

docs/user.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,11 +1008,39 @@ If you want to add a sidecar to every cluster managed by the operator, you can s
10081008

10091009
### Accessing the PostgreSQL socket from sidecars
10101010

1011-
If enabled by the `share_pg_socket_with_sidecars` option in the operator
1012-
configuration the PostgreSQL socket is placed in a volume of type
1013-
`emptyDir` named `postgresql-run`.
1014-
To allow access to the socket from any sidecar container simply add a
1015-
VolumeMount to this volume to your sidecar spec.
1011+
If enabled by the `share_pgsocket_with_sidecars` option in the operator
1012+
configuration the PostgreSQL socket is placed in a volume of type `emptyDir`
1013+
named `postgresql-run`. To allow access to the socket from any sidecar
1014+
container simply add a VolumeMount to this volume to your sidecar spec.
1015+
1016+
```yaml
1017+
- name: "container-name"
1018+
image: "company/image:tag"
1019+
volumeMounts:
1020+
- mountPath: /var/run
1021+
name: postgresql-run
1022+
```
1023+
1024+
If you do not want to globally enable this feature and only use it for single
1025+
Postgres clusters, specify an `EmptyDir` volume under `additionalVolumes` in
1026+
the manifest:
1027+
1028+
```yaml
1029+
spec:
1030+
additionalVolumes:
1031+
- name: postgresql-run
1032+
mountPath: /var/run/postgresql
1033+
targetContainers:
1034+
- all
1035+
volumeSource:
1036+
emptyDir: {}
1037+
sidecars:
1038+
- name: "container-name"
1039+
image: "company/image:tag"
1040+
volumeMounts:
1041+
- mountPath: /var/run
1042+
name: postgresql-run
1043+
```
10161044

10171045
## InitContainers Support
10181046

manifests/configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ data:
134134
ring_log_lines: "100"
135135
role_deletion_suffix: "_deleted"
136136
secret_name_template: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
137+
share_pgsocket_with_sidecars: "false"
137138
# sidecar_docker_images: ""
138139
# set_memory_request_to_limit: "false"
139140
spilo_allow_privilege_escalation: "true"

manifests/operatorconfiguration.crd.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ spec:
222222
type: array
223223
items:
224224
type: string
225-
share_pg_socket_with_sidecars:
226-
type: boolean
227-
default: false
228225
infrastructure_roles_secret_name:
229226
type: string
230227
infrastructure_roles_secrets:
@@ -312,6 +309,9 @@ spec:
312309
secret_name_template:
313310
type: string
314311
default: "{username}.{cluster}.credentials.{tprkind}.{tprgroup}"
312+
share_pgsocket_with_sidecars:
313+
type: boolean
314+
default: false
315315
spilo_allow_privilege_escalation:
316316
type: boolean
317317
default: true

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,9 +1289,6 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
12891289
},
12901290
},
12911291
},
1292-
"share_pg_socket_with_sidecars": {
1293-
Type: "boolean",
1294-
},
12951292
"infrastructure_roles_secret_name": {
12961293
Type: "string",
12971294
},
@@ -1419,6 +1416,9 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
14191416
"secret_name_template": {
14201417
Type: "string",
14211418
},
1419+
"share_pgsocket_with_sidecars": {
1420+
Type: "boolean",
1421+
},
14221422
"spilo_runasuser": {
14231423
Type: "integer",
14241424
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ type KubernetesMetaConfiguration struct {
7272
StorageResizeMode string `json:"storage_resize_mode,omitempty"`
7373
EnableInitContainers *bool `json:"enable_init_containers,omitempty"`
7474
EnableSidecars *bool `json:"enable_sidecars,omitempty"`
75-
SharePGSocketWithSidecars *bool `json:"share_pgsocket_with_sidecars,omitempty"`
75+
SharePgSocketWithSidecars *bool `json:"share_pgsocket_with_sidecars,omitempty"`
7676
SecretNameTemplate config.StringTemplate `json:"secret_name_template,omitempty"`
7777
ClusterDomain string `json:"cluster_domain,omitempty"`
7878
OAuthTokenSecretName spec.NamespacedName `json:"oauth_token_secret_name,omitempty"`

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

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

pkg/cluster/k8sres.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ func (c *Cluster) generatePodTemplate(
723723
spiloContainer *v1.Container,
724724
initContainers []v1.Container,
725725
sidecarContainers []v1.Container,
726-
sharePGSocketWithSidecars *bool,
726+
sharePgSocketWithSidecars *bool,
727727
tolerationsSpec *[]v1.Toleration,
728728
spiloRunAsUser *int64,
729729
spiloRunAsGroup *int64,
@@ -792,7 +792,7 @@ func (c *Cluster) generatePodTemplate(
792792
podSpec.PriorityClassName = priorityClassName
793793
}
794794

795-
if sharePGSocketWithSidecars != nil && *sharePGSocketWithSidecars {
795+
if sharePgSocketWithSidecars != nil && *sharePgSocketWithSidecars {
796796
addVarRunVolume(&podSpec)
797797
}
798798

@@ -1378,7 +1378,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
13781378
spiloContainer,
13791379
initContainers,
13801380
sidecarContainers,
1381-
c.OpConfig.SharePGSocketWithSidecars,
1381+
c.OpConfig.SharePgSocketWithSidecars,
13821382
&tolerationSpec,
13831383
effectiveRunAsUser,
13841384
effectiveRunAsGroup,
@@ -1586,8 +1586,8 @@ func addVarRunVolume(podSpec *v1.PodSpec) {
15861586
for i := range podSpec.Containers {
15871587
mounts := append(podSpec.Containers[i].VolumeMounts,
15881588
v1.VolumeMount{
1589-
Name: "postgresql-run",
1590-
MountPath: "/var/run/postgresql",
1589+
Name: constants.RunVolumeName,
1590+
MountPath: constants.RunVolumePath,
15911591
})
15921592
podSpec.Containers[i].VolumeMounts = mounts
15931593
}

0 commit comments

Comments
 (0)