Skip to content

Commit dc403f8

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

File tree

8 files changed

+49
-0
lines changed

8 files changed

+49
-0
lines changed

docs/reference/operator_parameters.md

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

340+
* **share_pg_socket_with_sidecars**
341+
global option to create an emptyDir volume named `postgresql-run`. This is
342+
mounted by all containers at `/var/run/postgresql` sharing the unix socket of
343+
PostgreSQL (`pg_socket`) with the sidecars this way.
344+
Default is `false`.
345+
340346
* **secret_name_template**
341347
a template for the name of the database user secrets generated by the
342348
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
@@ -216,6 +216,9 @@ spec:
216216
type: array
217217
items:
218218
type: string
219+
share_pg_socket_with_sidecars:
220+
type: boolean
221+
default: false
219222
infrastructure_roles_secret_name:
220223
type: string
221224
infrastructure_roles_secrets:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,9 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
12831283
},
12841284
},
12851285
},
1286+
"share_pg_socket_with_sidecars": {
1287+
Type: "boolean",
1288+
},
12861289
"infrastructure_roles_secret_name": {
12871290
Type: "string",
12881291
},

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/apis/acid.zalan.do/v1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 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: 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,
@@ -1510,6 +1516,28 @@ func addShmVolume(podSpec *v1.PodSpec) {
15101516
podSpec.Volumes = volumes
15111517
}
15121518

1519+
func addVarRunVolume(podSpec *v1.PodSpec) {
1520+
volumes := append(podSpec.Volumes, v1.Volume{
1521+
Name: "postgresql-run",
1522+
VolumeSource: v1.VolumeSource{
1523+
EmptyDir: &v1.EmptyDirVolumeSource{
1524+
Medium: "Memory",
1525+
},
1526+
},
1527+
})
1528+
1529+
for i := range podSpec.Containers {
1530+
mounts := append(podSpec.Containers[i].VolumeMounts,
1531+
v1.VolumeMount{
1532+
Name: "postgresql-run",
1533+
MountPath: "/var/run/postgresql",
1534+
})
1535+
podSpec.Containers[i].VolumeMounts = mounts
1536+
}
1537+
1538+
podSpec.Volumes = volumes
1539+
}
1540+
15131541
func addSecretVolume(podSpec *v1.PodSpec, additionalSecretMount string, additionalSecretMountPath string) {
15141542
volumes := append(podSpec.Volumes, v1.Volume{
15151543
Name: additionalSecretMount,
@@ -2045,6 +2073,7 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1beta1.CronJob, error) {
20452073
logicalBackupContainer,
20462074
[]v1.Container{},
20472075
[]v1.Container{},
2076+
util.False(),
20482077
&[]v1.Toleration{},
20492078
nil,
20502079
nil,

pkg/controller/operator_config.go

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

pkg/util/config/config.go

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

0 commit comments

Comments
 (0)