@@ -856,19 +856,15 @@ func (c *Cluster) generatePodTemplate(
856856 c .logger .Debugf ("Repo-host Configmap added to this pod template is %s" , configmapName )
857857 } else if c .Postgresql .Spec .Backup != nil && c .Postgresql .Spec .Backup .Pgbackrest != nil {
858858 //this will be done for the pg-pod when we have pvc or not but have pgbackrest
859- configmapName := c .getPgbackrestConfigmapName ()
860- secretName := c .Postgresql .Spec .Backup .Pgbackrest .Configuration .Secret
861- // If the secret is not provided and the repo has pvc type then use the secret name generated
862- // by the operator, because in this case secret is not provided in the manifest
863- if secretName == "" && c .Postgresql .Spec .Backup .Pgbackrest .Repos != nil {
864- for _ , repo := range c .Postgresql .Spec .Backup .Pgbackrest .Repos {
865- if repo .Storage == "pvc" {
866- secretName = c .getPgbackrestCertSecretName ()
867- }
868- }
869- }
870- addPgbackrestConfigVolume (& podSpec , configmapName , secretName )
871- c .logger .Debugf ("Configmap added to this pod template is %s" , configmapName )
859+ certSecret := ""
860+ if specHasPgbackrestPVCRepo (& c .Postgresql .Spec ) {
861+ certSecret = c .getPgbackrestCertSecretName ()
862+ }
863+ addPgbackrestConfigVolume (& podSpec ,
864+ c .getPgbackrestConfigmapName (),
865+ c .Postgresql .Spec .Backup .Pgbackrest .Configuration .Secret ,
866+ certSecret ,
867+ )
872868 }
873869
874870 if podAntiAffinity {
@@ -2268,61 +2264,78 @@ func addPgbackrestConfigVolumePVC(podSpec *v1.PodSpec, configmapName string, sec
22682264 podSpec .Volumes = volumes
22692265}
22702266
2271- func addPgbackrestConfigVolume (podSpec * v1.PodSpec , configmapName string , secretName string ) {
2267+ func addPgbackrestConfigVolume (podSpec * v1.PodSpec , configmapName , secretName , certSecret string ) {
22722268
2273- name := "pgbackrest-config"
2274- path := "/etc/pgbackrest/conf.d"
22752269 defaultMode := int32 (0640 )
2276- postgresContainerIdx := 0
2277- postgresInitContainerIdx := - 1
22782270
2279- volumes := append (podSpec .Volumes , v1.Volume {
2280- Name : name ,
2281- VolumeSource : v1.VolumeSource {
2282- Projected : & v1.ProjectedVolumeSource {
2283- DefaultMode : & defaultMode ,
2284- Sources : []v1.VolumeProjection {
2285- {ConfigMap : & v1.ConfigMapProjection {
2286- LocalObjectReference : v1.LocalObjectReference {Name : configmapName },
2287- Optional : util .True (),
2288- },
2289- },
2290- {Secret : & v1.SecretProjection {
2291- LocalObjectReference : v1.LocalObjectReference {Name : secretName },
2292- Optional : util .True (),
2293- },
2271+ projections := []v1.VolumeProjection {
2272+ {ConfigMap : & v1.ConfigMapProjection {
2273+ LocalObjectReference : v1.LocalObjectReference {Name : configmapName },
2274+ Optional : util .True (),
2275+ },
2276+ },
2277+ }
2278+ if secretName != "" {
2279+ projections = append (projections , v1.VolumeProjection {
2280+ Secret : & v1.SecretProjection {
2281+ LocalObjectReference : v1.LocalObjectReference {Name : secretName },
2282+ Optional : util .True (),
2283+ },
2284+ })
2285+ }
2286+ podSpec .Volumes = append (podSpec .Volumes ,
2287+ v1.Volume {
2288+ Name : "pgbackrest-config" ,
2289+ VolumeSource : v1.VolumeSource {
2290+ Projected : & v1.ProjectedVolumeSource {
2291+ DefaultMode : & defaultMode ,
2292+ Sources : projections ,
2293+ },
2294+ },
2295+ })
2296+
2297+ if certSecret != "" {
2298+ podSpec .Volumes = append (podSpec .Volumes , v1.Volume {
2299+ Name : "pgbackrest-certs" ,
2300+ VolumeSource : v1.VolumeSource {
2301+ Projected : & v1.ProjectedVolumeSource {
2302+ DefaultMode : & defaultMode ,
2303+ Sources : []v1.VolumeProjection {
2304+ {Secret : & v1.SecretProjection {
2305+ LocalObjectReference : v1.LocalObjectReference {Name : certSecret },
2306+ Optional : util .True (),
2307+ },
2308+ },
22942309 },
22952310 },
22962311 },
2312+ })
2313+ }
2314+
2315+ newMounts := []v1.VolumeMount {
2316+ v1.VolumeMount {
2317+ Name : "pgbackrest-config" ,
2318+ MountPath : "/etc/pgbackrest/conf.d" ,
22972319 },
2298- })
2320+ }
2321+ if certSecret != "" {
2322+ newMounts = append (newMounts , v1.VolumeMount {
2323+ Name : "pgbackrest-certs" ,
2324+ MountPath : "/etc/pgbackrest/certs" ,
2325+ })
2326+ }
22992327
23002328 for i , container := range podSpec .Containers {
23012329 if container .Name == constants .PostgresContainerName {
2302- postgresContainerIdx = i
2330+ podSpec . Containers [ i ]. VolumeMounts = append ( podSpec . Containers [ i ]. VolumeMounts , newMounts ... )
23032331 }
23042332 }
23052333
2306- mounts := append (podSpec .Containers [postgresContainerIdx ].VolumeMounts ,
2307- v1.VolumeMount {
2308- Name : name ,
2309- MountPath : path ,
2310- })
2311-
2312- podSpec .Containers [postgresContainerIdx ].VolumeMounts = mounts
2313-
2314- // Add pgbackrest-Config to init-container
23152334 for i , container := range podSpec .InitContainers {
23162335 if container .Name == "pgbackrest-restore" {
2317- postgresInitContainerIdx = i
2336+ podSpec . InitContainers [ i ]. VolumeMounts = append ( podSpec . InitContainers [ i ]. VolumeMounts , newMounts ... )
23182337 }
23192338 }
2320-
2321- if postgresInitContainerIdx >= 0 {
2322- podSpec .InitContainers [postgresInitContainerIdx ].VolumeMounts = mounts
2323- }
2324-
2325- podSpec .Volumes = volumes
23262339}
23272340
23282341func (c * Cluster ) generatePersistentVolumeClaimTemplate (volumeSize , volumeStorageClass string ,
@@ -3050,9 +3063,9 @@ func (c *Cluster) generatePgbackrestConfigmap() (*v1.ConfigMap, error) {
30503063 config := "[db]\n pg1-path = /home/postgres/pgdata/pgroot/data\n pg1-port = 5432\n pg1-socket-path = /var/run/postgresql/\n "
30513064 config += "\n [global]\n log-path = /home/postgres/pgdata/pgbackrest/log\n spool-path = /home/postgres/pgdata/pgbackrest/spool-path"
30523065 config += "\n tls-server-address=*"
3053- config += "\n tls-server-ca-file = /etc/pgbackrest/conf.d /pgbackrest.ca-roots"
3054- config += "\n tls-server-cert-file = /etc/pgbackrest/conf.d /pgbackrest-client.crt"
3055- config += "\n tls-server-key-file = /etc/pgbackrest/conf.d /pgbackrest-client.key"
3066+ config += "\n tls-server-ca-file = /etc/pgbackrest/certs /pgbackrest.ca-roots"
3067+ config += "\n tls-server-cert-file = /etc/pgbackrest/certs /pgbackrest-client.crt"
3068+ config += "\n tls-server-key-file = /etc/pgbackrest/certs /pgbackrest-client.key"
30563069 config += "\n tls-server-auth = " + c .clientCommonName () + "=*"
30573070 if c .Postgresql .Spec .Backup != nil && c .Postgresql .Spec .Backup .Pgbackrest != nil {
30583071 if global := c .Postgresql .Spec .Backup .Pgbackrest .Global ; global != nil {
@@ -3067,9 +3080,9 @@ func (c *Cluster) generatePgbackrestConfigmap() (*v1.ConfigMap, error) {
30673080 if repo .Storage == "pvc" {
30683081 c .logger .Debugf ("DEBUG_OUTPUT %s %s" , c .clusterName ().Name , c .Namespace )
30693082 config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host = " + c .clusterName ().Name + "-pgbackrest-repo-host-0." + c .serviceName (ClusterPods ) + "." + c .Namespace + ".svc." + c .OpConfig .ClusterDomain
3070- config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-ca-file = /etc/pgbackrest/conf.d /pgbackrest.ca-roots"
3071- config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-cert-file = /etc/pgbackrest/conf.d /pgbackrest-client.crt"
3072- config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-key-file = /etc/pgbackrest/conf.d /pgbackrest-client.key"
3083+ config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-ca-file = /etc/pgbackrest/certs /pgbackrest.ca-roots"
3084+ config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-cert-file = /etc/pgbackrest/certs /pgbackrest-client.crt"
3085+ config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-key-file = /etc/pgbackrest/certs /pgbackrest-client.key"
30733086 config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-type = tls"
30743087 config += "\n repo" + fmt .Sprintf ("%d" , i + 1 ) + "-host-user = postgres"
30753088 } else {
0 commit comments