Skip to content

Commit 39a11d1

Browse files
committed
Add config switch to share pg_socket in /var/run/postgresql via an emptyDir with the sidecar containers
1 parent 7d4da92 commit 39a11d1

File tree

7 files changed

+43
-0
lines changed

7 files changed

+43
-0
lines changed

docs/reference/operator_parameters.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,12 @@ configuration they are grouped under the `kubernetes` key.
331331
to run alongside Spilo on the same pod. Globally defined sidecars are always
332332
enabled. Default is true.
333333

334+
* **share_pg_socket_with_sidecars**
335+
global option to create an emptyDir volume named `postgresql-run`. This is
336+
mounted by all containers at `/var/run/postgresql` sharing the unix socket of
337+
PostgreSQL (`pg_socket`) with the sidecars this way.
338+
Default is `false`.
339+
334340
* **secret_name_template**
335341
a template for the name of the database user secrets generated by the
336342
operator. `{namespace}` is replaced with name of the namespace if

manifests/operatorconfiguration.crd.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ spec:
214214
type: array
215215
items:
216216
type: string
217+
share_pg_socket_with_sidecars:
218+
type: boolean
219+
default: false
217220
infrastructure_roles_secret_name:
218221
type: string
219222
infrastructure_roles_secrets:

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,8 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
12791279
Type: "string",
12801280
},
12811281
},
1282+
"share_pg_socket_with_sidecars": {
1283+
Type: "boolean",
12821284
},
12831285
"infrastructure_roles_secret_name": {
12841286
Type: "string",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +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"`
7576
SecretNameTemplate config.StringTemplate `json:"secret_name_template,omitempty"`
7677
ClusterDomain string `json:"cluster_domain,omitempty"`
7778
OAuthTokenSecretName spec.NamespacedName `json:"oauth_token_secret_name,omitempty"`

pkg/cluster/k8sres.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,7 @@ func (c *Cluster) generatePodTemplate(
674674
spiloContainer *v1.Container,
675675
initContainers []v1.Container,
676676
sidecarContainers []v1.Container,
677+
sharePGSocketWithSidecars *bool,
677678
tolerationsSpec *[]v1.Toleration,
678679
spiloRunAsUser *int64,
679680
spiloRunAsGroup *int64,
@@ -736,6 +737,10 @@ func (c *Cluster) generatePodTemplate(
736737
podSpec.PriorityClassName = priorityClassName
737738
}
738739

740+
if sharePGSocketWithSidecars != nil && *sharePGSocketWithSidecars {
741+
addVarRunVolume(&podSpec)
742+
}
743+
739744
if additionalSecretMount != "" {
740745
addSecretVolume(&podSpec, additionalSecretMount, additionalSecretMountPath)
741746
}
@@ -1317,6 +1322,7 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
13171322
spiloContainer,
13181323
initContainers,
13191324
sidecarContainers,
1325+
c.OpConfig.SharePGSocketWithSidecars,
13201326
&tolerationSpec,
13211327
effectiveRunAsUser,
13221328
effectiveRunAsGroup,
@@ -1502,6 +1508,28 @@ func addShmVolume(podSpec *v1.PodSpec) {
15021508
podSpec.Volumes = volumes
15031509
}
15041510

1511+
func addVarRunVolume(podSpec *v1.PodSpec) {
1512+
volumes := append(podSpec.Volumes, v1.Volume{
1513+
Name: "postgresql-run",
1514+
VolumeSource: v1.VolumeSource{
1515+
EmptyDir: &v1.EmptyDirVolumeSource{
1516+
Medium: "Memory",
1517+
},
1518+
},
1519+
})
1520+
1521+
for i := range podSpec.Containers {
1522+
mounts := append(podSpec.Containers[i].VolumeMounts,
1523+
v1.VolumeMount{
1524+
Name: "postgresql-run",
1525+
MountPath: "/var/run/postgresql",
1526+
})
1527+
podSpec.Containers[i].VolumeMounts = mounts
1528+
}
1529+
1530+
podSpec.Volumes = volumes
1531+
}
1532+
15051533
func addSecretVolume(podSpec *v1.PodSpec, additionalSecretMount string, additionalSecretMountPath string) {
15061534
volumes := append(podSpec.Volumes, v1.Volume{
15071535
Name: additionalSecretMount,
@@ -2037,6 +2065,7 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1beta1.CronJob, error) {
20372065
logicalBackupContainer,
20382066
[]v1.Container{},
20392067
[]v1.Container{},
2068+
util.False(),
20402069
&[]v1.Toleration{},
20412070
nil,
20422071
nil,

pkg/controller/operator_config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
8484
result.StorageResizeMode = util.Coalesce(fromCRD.Kubernetes.StorageResizeMode, "pvc")
8585
result.EnableInitContainers = util.CoalesceBool(fromCRD.Kubernetes.EnableInitContainers, util.True())
8686
result.EnableSidecars = util.CoalesceBool(fromCRD.Kubernetes.EnableSidecars, util.True())
87+
result.SharePGSocketWithSidecars = util.CoalesceBool(fromCRD.Kubernetes.SharePGSocketWithSidecars, util.False())
8788
result.SecretNameTemplate = fromCRD.Kubernetes.SecretNameTemplate
8889
result.OAuthTokenSecretName = fromCRD.Kubernetes.OAuthTokenSecretName
8990
result.EnableCrossNamespaceSecret = fromCRD.Kubernetes.EnableCrossNamespaceSecret

pkg/util/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ type Config struct {
208208
EnablePodDisruptionBudget *bool `name:"enable_pod_disruption_budget" default:"true"`
209209
EnableInitContainers *bool `name:"enable_init_containers" default:"true"`
210210
EnableSidecars *bool `name:"enable_sidecars" default:"true"`
211+
SharePGSocketWithSidecars *bool `name:"share_pg_socket_with_sidecars" default:"false"`
211212
Workers uint32 `name:"workers" default:"8"`
212213
APIPort int `name:"api_port" default:"8080"`
213214
RingLogLines int `name:"ring_log_lines" default:"100"`

0 commit comments

Comments
 (0)