Skip to content

Commit 3c4f437

Browse files
committed
Set securityContext for backup container
1 parent 2a54e49 commit 3c4f437

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

pkg/cluster/k8sres.go

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -708,9 +708,6 @@ func (c *Cluster) generatePodTemplate(
708708
initContainers []v1.Container,
709709
sidecarContainers []v1.Container,
710710
tolerationsSpec *[]v1.Toleration,
711-
spiloRunAsUser *int64,
712-
spiloRunAsGroup *int64,
713-
spiloFSGroup *int64,
714711
nodeAffinity *v1.Affinity,
715712
schedulerName *string,
716713
terminateGracePeriod int64,
@@ -728,18 +725,22 @@ func (c *Cluster) generatePodTemplate(
728725
terminateGracePeriodSeconds := terminateGracePeriod
729726
containers := []v1.Container{*spiloContainer}
730727
containers = append(containers, sidecarContainers...)
731-
securityContext := v1.PodSecurityContext{}
728+
securityContext := v1.PodSecurityContext{
729+
RunAsUser: c.OpConfig.Resources.SpiloRunAsUser,
730+
RunAsGroup: c.OpConfig.Resources.SpiloRunAsGroup,
731+
FSGroup: c.OpConfig.Resources.SpiloFSGroup,
732+
}
732733

733-
if spiloRunAsUser != nil {
734-
securityContext.RunAsUser = spiloRunAsUser
734+
if c.Spec.SpiloRunAsUser != nil {
735+
securityContext.RunAsUser = c.Spec.SpiloRunAsUser
735736
}
736737

737-
if spiloRunAsGroup != nil {
738-
securityContext.RunAsGroup = spiloRunAsGroup
738+
if c.Spec.SpiloRunAsGroup != nil {
739+
securityContext.RunAsGroup = c.Spec.SpiloRunAsGroup
739740
}
740741

741-
if spiloFSGroup != nil {
742-
securityContext.FSGroup = spiloFSGroup
742+
if c.Spec.SpiloFSGroup != nil {
743+
securityContext.FSGroup = c.Spec.SpiloFSGroup
743744
}
744745

745746
podSpec := v1.PodSpec{
@@ -1193,22 +1194,6 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
11931194
// pickup the docker image for the spilo container
11941195
effectiveDockerImage := util.Coalesce(spec.DockerImage, c.OpConfig.DockerImage)
11951196

1196-
// determine the User, Group and FSGroup for the spilo pod
1197-
effectiveRunAsUser := c.OpConfig.Resources.SpiloRunAsUser
1198-
if spec.SpiloRunAsUser != nil {
1199-
effectiveRunAsUser = spec.SpiloRunAsUser
1200-
}
1201-
1202-
effectiveRunAsGroup := c.OpConfig.Resources.SpiloRunAsGroup
1203-
if spec.SpiloRunAsGroup != nil {
1204-
effectiveRunAsGroup = spec.SpiloRunAsGroup
1205-
}
1206-
1207-
effectiveFSGroup := c.OpConfig.Resources.SpiloFSGroup
1208-
if spec.SpiloFSGroup != nil {
1209-
effectiveFSGroup = spec.SpiloFSGroup
1210-
}
1211-
12121197
volumeMounts := generateVolumeMounts(spec.Volume)
12131198

12141199
// configure TLS with a custom secret volume
@@ -1352,9 +1337,6 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
13521337
initContainers,
13531338
sidecarContainers,
13541339
&tolerationSpec,
1355-
effectiveRunAsUser,
1356-
effectiveRunAsGroup,
1357-
effectiveFSGroup,
13581340
c.nodeAffinity(c.OpConfig.NodeReadinessLabel, spec.NodeAffinity),
13591341
spec.SchedulerName,
13601342
int64(c.OpConfig.PodTerminateGracePeriod.Seconds()),
@@ -2075,9 +2057,6 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1.CronJob, error) {
20752057
[]v1.Container{},
20762058
[]v1.Container{},
20772059
&[]v1.Toleration{},
2078-
nil,
2079-
nil,
2080-
nil,
20812060
c.nodeAffinity(c.OpConfig.NodeReadinessLabel, nil),
20822061
nil,
20832062
int64(c.OpConfig.PodTerminateGracePeriod.Seconds()),

0 commit comments

Comments
 (0)