Skip to content

Commit 27c969d

Browse files
addreasFxKu
andauthored
Set securityContext for backup container (#2117)
Co-authored-by: Felix Kunde <felix-kunde@gmx.de>
1 parent 030c24f commit 27c969d

1 file changed

Lines changed: 11 additions & 32 deletions

File tree

pkg/cluster/k8sres.go

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,6 @@ func (c *Cluster) generatePodTemplate(
818818
sidecarContainers []v1.Container,
819819
sharePgSocketWithSidecars *bool,
820820
tolerationsSpec *[]v1.Toleration,
821-
spiloRunAsUser *int64,
822-
spiloRunAsGroup *int64,
823-
spiloFSGroup *int64,
824821
nodeAffinity *v1.Affinity,
825822
schedulerName *string,
826823
terminateGracePeriod int64,
@@ -839,18 +836,22 @@ func (c *Cluster) generatePodTemplate(
839836
terminateGracePeriodSeconds := terminateGracePeriod
840837
containers := []v1.Container{*spiloContainer}
841838
containers = append(containers, sidecarContainers...)
842-
securityContext := v1.PodSecurityContext{}
839+
securityContext := v1.PodSecurityContext{
840+
RunAsUser: c.OpConfig.Resources.SpiloRunAsUser,
841+
RunAsGroup: c.OpConfig.Resources.SpiloRunAsGroup,
842+
FSGroup: c.OpConfig.Resources.SpiloFSGroup,
843+
}
843844

844-
if spiloRunAsUser != nil {
845-
securityContext.RunAsUser = spiloRunAsUser
845+
if c.Spec.SpiloRunAsUser != nil {
846+
securityContext.RunAsUser = c.Spec.SpiloRunAsUser
846847
}
847848

848-
if spiloRunAsGroup != nil {
849-
securityContext.RunAsGroup = spiloRunAsGroup
849+
if c.Spec.SpiloRunAsGroup != nil {
850+
securityContext.RunAsGroup = c.Spec.SpiloRunAsGroup
850851
}
851852

852-
if spiloFSGroup != nil {
853-
securityContext.FSGroup = spiloFSGroup
853+
if c.Spec.SpiloFSGroup != nil {
854+
securityContext.FSGroup = c.Spec.SpiloFSGroup
854855
}
855856

856857
podSpec := v1.PodSpec{
@@ -1352,22 +1353,6 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
13521353
// pickup the docker image for the spilo container
13531354
effectiveDockerImage := util.Coalesce(spec.DockerImage, c.OpConfig.DockerImage)
13541355

1355-
// determine the User, Group and FSGroup for the spilo pod
1356-
effectiveRunAsUser := c.OpConfig.Resources.SpiloRunAsUser
1357-
if spec.SpiloRunAsUser != nil {
1358-
effectiveRunAsUser = spec.SpiloRunAsUser
1359-
}
1360-
1361-
effectiveRunAsGroup := c.OpConfig.Resources.SpiloRunAsGroup
1362-
if spec.SpiloRunAsGroup != nil {
1363-
effectiveRunAsGroup = spec.SpiloRunAsGroup
1364-
}
1365-
1366-
effectiveFSGroup := c.OpConfig.Resources.SpiloFSGroup
1367-
if spec.SpiloFSGroup != nil {
1368-
effectiveFSGroup = spec.SpiloFSGroup
1369-
}
1370-
13711356
volumeMounts := generateVolumeMounts(spec.Volume)
13721357

13731358
// configure TLS with a custom secret volume
@@ -1485,9 +1470,6 @@ func (c *Cluster) generateStatefulSet(spec *acidv1.PostgresSpec) (*appsv1.Statef
14851470
sidecarContainers,
14861471
c.OpConfig.SharePgSocketWithSidecars,
14871472
&tolerationSpec,
1488-
effectiveRunAsUser,
1489-
effectiveRunAsGroup,
1490-
effectiveFSGroup,
14911473
c.nodeAffinity(c.OpConfig.NodeReadinessLabel, spec.NodeAffinity),
14921474
spec.SchedulerName,
14931475
int64(c.OpConfig.PodTerminateGracePeriod.Seconds()),
@@ -2379,9 +2361,6 @@ func (c *Cluster) generateLogicalBackupJob() (*batchv1.CronJob, error) {
23792361
[]v1.Container{},
23802362
util.False(),
23812363
&tolerationsSpec,
2382-
nil,
2383-
nil,
2384-
nil,
23852364
c.nodeAffinity(c.OpConfig.NodeReadinessLabel, nil),
23862365
nil,
23872366
int64(c.OpConfig.PodTerminateGracePeriod.Seconds()),

0 commit comments

Comments
 (0)