@@ -67,7 +67,7 @@ type spiloConfiguration struct {
6767}
6868
6969func (c * Cluster ) containerName () string {
70- return "postgres"
70+ return constants . PostgresContainerName
7171}
7272
7373func (c * Cluster ) statefulSetName () string {
@@ -1401,14 +1401,18 @@ func addShmVolume(podSpec *v1.PodSpec) {
14011401 },
14021402 })
14031403
1404- pgIdx := constants .PostgresContainerIdx
1405- mounts := append (podSpec .Containers [pgIdx ].VolumeMounts ,
1406- v1.VolumeMount {
1407- Name : constants .ShmVolumeName ,
1408- MountPath : constants .ShmVolumePath ,
1409- })
1404+ for i , container := range podSpec .Containers {
1405+ if container .Name == constants .PostgresContainerName {
1406+ mounts := append (container .VolumeMounts ,
1407+ v1.VolumeMount {
1408+ Name : constants .ShmVolumeName ,
1409+ MountPath : constants .ShmVolumePath ,
1410+ })
1411+
1412+ podSpec .Containers [i ].VolumeMounts = mounts
1413+ }
1414+ }
14101415
1411- podSpec .Containers [0 ].VolumeMounts = mounts
14121416 podSpec .Volumes = volumes
14131417}
14141418
@@ -1439,54 +1443,58 @@ func (c *Cluster) addAdditionalVolumes(podSpec *v1.PodSpec,
14391443
14401444 volumes := podSpec .Volumes
14411445 mountPaths := map [string ]acidv1.AdditionalVolume {}
1442- for i , v := range additionalVolumes {
1443- if previousVolume , exist := mountPaths [v .MountPath ]; exist {
1446+ for i , additionalVolume := range additionalVolumes {
1447+ if previousVolume , exist := mountPaths [additionalVolume .MountPath ]; exist {
14441448 msg := "Volume %+v cannot be mounted to the same path as %+v"
1445- c .logger .Warningf (msg , v , previousVolume )
1449+ c .logger .Warningf (msg , additionalVolume , previousVolume )
14461450 continue
14471451 }
14481452
1449- if v .MountPath == constants .PostgresDataMount {
1453+ if additionalVolume .MountPath == constants .PostgresDataMount {
14501454 msg := "Cannot mount volume on postgresql data directory, %+v"
1451- c .logger .Warningf (msg , v )
1455+ c .logger .Warningf (msg , additionalVolume )
14521456 continue
14531457 }
14541458
1455- if len (v .TargetContainers ) == 0 {
1456- spiloContainer := podSpec .Containers [0 ]
1457- additionalVolumes [i ].TargetContainers = []string {spiloContainer .Name }
1459+ // if no target container is defined assign it to postgres container
1460+ if len (additionalVolume .TargetContainers ) == 0 {
1461+ for j := range podSpec .Containers {
1462+ if podSpec .Containers [j ].Name == c .containerName () {
1463+ additionalVolumes [i ].TargetContainers = []string {c .containerName ()}
1464+ }
1465+ }
14581466 }
14591467
1460- for _ , target := range v .TargetContainers {
1461- if target == "all" && len (v .TargetContainers ) != 1 {
1468+ for _ , target := range additionalVolume .TargetContainers {
1469+ if target == "all" && len (additionalVolume .TargetContainers ) != 1 {
14621470 msg := `Target containers could be either "all" or a list
14631471 of containers, mixing those is not allowed, %+v`
1464- c .logger .Warningf (msg , v )
1472+ c .logger .Warningf (msg , additionalVolume )
14651473 continue
14661474 }
14671475 }
14681476
14691477 volumes = append (volumes ,
14701478 v1.Volume {
1471- Name : v .Name ,
1472- VolumeSource : v .VolumeSource ,
1479+ Name : additionalVolume .Name ,
1480+ VolumeSource : additionalVolume .VolumeSource ,
14731481 },
14741482 )
14751483
1476- mountPaths [v .MountPath ] = v
1484+ mountPaths [additionalVolume .MountPath ] = additionalVolume
14771485 }
14781486
14791487 c .logger .Infof ("Mount additional volumes: %+v" , additionalVolumes )
14801488
14811489 for i := range podSpec .Containers {
14821490 mounts := podSpec .Containers [i ].VolumeMounts
1483- for _ , v := range additionalVolumes {
1484- for _ , target := range v .TargetContainers {
1491+ for _ , additionalVolume := range additionalVolumes {
1492+ for _ , target := range additionalVolume .TargetContainers {
14851493 if podSpec .Containers [i ].Name == target || target == "all" {
14861494 mounts = append (mounts , v1.VolumeMount {
1487- Name : v .Name ,
1488- MountPath : v .MountPath ,
1489- SubPath : v .SubPath ,
1495+ Name : additionalVolume .Name ,
1496+ MountPath : additionalVolume .MountPath ,
1497+ SubPath : additionalVolume .SubPath ,
14901498 })
14911499 }
14921500 }
0 commit comments