Skip to content

Commit

Permalink
fix to pooler TLS support (#2219)
Browse files Browse the repository at this point in the history
* fix to pooler TLS support, security context fsGroup added (#2216)
* add environment variable of CA cert path in pooler pod template
* additional logic for custom CA secrets and mount path
* fix ca file name
  • Loading branch information
2tvenom committed Mar 7, 2023
1 parent d504aeb commit 6953f72
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pkg/cluster/connection_pooler.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,20 +348,33 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
// Env vars
crtFile := spec.TLS.CertificateFile
keyFile := spec.TLS.PrivateKeyFile
caFile := spec.TLS.CAFile
mountPath := "/tls"
mountPathCA := mountPath

if crtFile == "" {
crtFile = "tls.crt"
}
if keyFile == "" {
keyFile = "tls.key"
}
if caFile == "" {
caFile = "ca.crt"
}
if spec.TLS.CASecretName != "" {
mountPathCA = mountPath + "ca"
}

envVars = append(
envVars,
v1.EnvVar{
Name: "CONNECTION_POOLER_CLIENT_TLS_CRT", Value: filepath.Join("/tls", crtFile),
Name: "CONNECTION_POOLER_CLIENT_TLS_CRT", Value: filepath.Join(mountPath, crtFile),
},
v1.EnvVar{
Name: "CONNECTION_POOLER_CLIENT_TLS_KEY", Value: filepath.Join(mountPath, keyFile),
},
v1.EnvVar{
Name: "CONNECTION_POOLER_CLIENT_TLS_KEY", Value: filepath.Join("/tls", keyFile),
Name: "CONNECTION_POOLER_CLIENT_CA_FILE", Value: filepath.Join(mountPathCA, caFile),
},
)

Expand Down Expand Up @@ -402,6 +415,12 @@ func (c *Cluster) generateConnectionPoolerPodTemplate(role PostgresRole) (
},
}

if spec.TLS != nil && spec.TLS.SecretName != "" && spec.SpiloFSGroup != nil {
podTemplate.Spec.SecurityContext = &v1.PodSecurityContext{
FSGroup: spec.SpiloFSGroup,
}
}

nodeAffinity := c.nodeAffinity(c.OpConfig.NodeReadinessLabel, spec.NodeAffinity)
if c.OpConfig.EnablePodAntiAffinity {
labelsSet := labels.Set(c.connectionPoolerLabels(role, false).MatchLabels)
Expand Down

0 comments on commit 6953f72

Please sign in to comment.