Skip to content

Commit e3525fe

Browse files
pooknulleleo007hors
authored
K8SPG-613: fix .spec.initContainer (#1191)
* K8SPG-613: fix .spec.initContainer https://perconadev.atlassian.net/browse/K8SPG-613 * revert formatting * fix lint --------- Co-authored-by: Eleonora Zinchenko <eleonora.zinchenko@percona.com> Co-authored-by: Viacheslav Sarzhan <slava.sarzhan@percona.com>
1 parent d29085b commit e3525fe

File tree

12 files changed

+69
-2
lines changed

12 files changed

+69
-2
lines changed

build/crd/crunchy/generated/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ spec:
649649
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
650650
type: object
651651
type: object
652+
required:
653+
- image
652654
type: object
653655
jobs:
654656
description: Jobs field allows configuration for all backup
@@ -8885,6 +8887,8 @@ spec:
88858887
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
88868888
type: object
88878889
type: object
8890+
required:
8891+
- image
88888892
type: object
88898893
instances:
88908894
description: |-
@@ -11718,6 +11722,8 @@ spec:
1171811722
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1171911723
type: object
1172011724
type: object
11725+
required:
11726+
- image
1172111727
type: object
1172211728
initContainers:
1172311729
description: |-

build/crd/percona/generated/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,8 @@ spec:
807807
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
808808
type: object
809809
type: object
810+
required:
811+
- image
810812
type: object
811813
jobs:
812814
description: Jobs field allows configuration for all backup
@@ -8690,6 +8692,8 @@ spec:
86908692
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
86918693
type: object
86928694
type: object
8695+
required:
8696+
- image
86938697
type: object
86948698
instances:
86958699
description: |-
@@ -10151,6 +10155,8 @@ spec:
1015110155
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1015210156
type: object
1015310157
type: object
10158+
required:
10159+
- image
1015410160
type: object
1015510161
initContainers:
1015610162
description: |-

config/crd/bases/pgv2.percona.com_perconapgclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,8 @@ spec:
12141214
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
12151215
type: object
12161216
type: object
1217+
required:
1218+
- image
12171219
type: object
12181220
jobs:
12191221
description: Jobs field allows configuration for all backup
@@ -9097,6 +9099,8 @@ spec:
90979099
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
90989100
type: object
90999101
type: object
9102+
required:
9103+
- image
91009104
type: object
91019105
instances:
91029106
description: |-
@@ -10558,6 +10562,8 @@ spec:
1055810562
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1055910563
type: object
1056010564
type: object
10565+
required:
10566+
- image
1056110567
type: object
1056210568
initContainers:
1056310569
description: |-

config/crd/bases/postgres-operator.crunchydata.com_postgresclusters.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,8 @@ spec:
641641
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
642642
type: object
643643
type: object
644+
required:
645+
- image
644646
type: object
645647
jobs:
646648
description: Jobs field allows configuration for all backup
@@ -8840,6 +8842,8 @@ spec:
88408842
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
88418843
type: object
88428844
type: object
8845+
required:
8846+
- image
88438847
type: object
88448848
instances:
88458849
description: |-
@@ -11660,6 +11664,8 @@ spec:
1166011664
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1166111665
type: object
1166211666
type: object
11667+
required:
11668+
- image
1166311669
type: object
1166411670
initContainers:
1166511671
description: |-

deploy/bundle.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,8 @@ spec:
15111511
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
15121512
type: object
15131513
type: object
1514+
required:
1515+
- image
15141516
type: object
15151517
jobs:
15161518
description: Jobs field allows configuration for all backup
@@ -9394,6 +9396,8 @@ spec:
93949396
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
93959397
type: object
93969398
type: object
9399+
required:
9400+
- image
93979401
type: object
93989402
instances:
93999403
description: |-
@@ -10855,6 +10859,8 @@ spec:
1085510859
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1085610860
type: object
1085710861
type: object
10862+
required:
10863+
- image
1085810864
type: object
1085910865
initContainers:
1086010866
description: |-
@@ -27149,6 +27155,8 @@ spec:
2714927155
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
2715027156
type: object
2715127157
type: object
27158+
required:
27159+
- image
2715227160
type: object
2715327161
jobs:
2715427162
description: Jobs field allows configuration for all backup
@@ -35348,6 +35356,8 @@ spec:
3534835356
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
3534935357
type: object
3535035358
type: object
35359+
required:
35360+
- image
3535135361
type: object
3535235362
instances:
3535335363
description: |-
@@ -38168,6 +38178,8 @@ spec:
3816838178
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
3816938179
type: object
3817038180
type: object
38181+
required:
38182+
- image
3817138183
type: object
3817238184
initContainers:
3817338185
description: |-

deploy/crd.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,8 @@ spec:
15111511
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
15121512
type: object
15131513
type: object
1514+
required:
1515+
- image
15141516
type: object
15151517
jobs:
15161518
description: Jobs field allows configuration for all backup
@@ -9394,6 +9396,8 @@ spec:
93949396
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
93959397
type: object
93969398
type: object
9399+
required:
9400+
- image
93979401
type: object
93989402
instances:
93999403
description: |-
@@ -10855,6 +10859,8 @@ spec:
1085510859
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1085610860
type: object
1085710861
type: object
10862+
required:
10863+
- image
1085810864
type: object
1085910865
initContainers:
1086010866
description: |-
@@ -27149,6 +27155,8 @@ spec:
2714927155
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
2715027156
type: object
2715127157
type: object
27158+
required:
27159+
- image
2715227160
type: object
2715327161
jobs:
2715427162
description: Jobs field allows configuration for all backup
@@ -35348,6 +35356,8 @@ spec:
3534835356
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
3534935357
type: object
3535035358
type: object
35359+
required:
35360+
- image
3535135361
type: object
3535235362
instances:
3535335363
description: |-
@@ -38168,6 +38178,8 @@ spec:
3816838178
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
3816938179
type: object
3817038180
type: object
38181+
required:
38182+
- image
3817138183
type: object
3817238184
initContainers:
3817338185
description: |-

deploy/cw-bundle.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,8 @@ spec:
15111511
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
15121512
type: object
15131513
type: object
1514+
required:
1515+
- image
15141516
type: object
15151517
jobs:
15161518
description: Jobs field allows configuration for all backup
@@ -9394,6 +9396,8 @@ spec:
93949396
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
93959397
type: object
93969398
type: object
9399+
required:
9400+
- image
93979401
type: object
93989402
instances:
93999403
description: |-
@@ -10855,6 +10859,8 @@ spec:
1085510859
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
1085610860
type: object
1085710861
type: object
10862+
required:
10863+
- image
1085810864
type: object
1085910865
initContainers:
1086010866
description: |-
@@ -27149,6 +27155,8 @@ spec:
2714927155
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
2715027156
type: object
2715127157
type: object
27158+
required:
27159+
- image
2715227160
type: object
2715327161
jobs:
2715427162
description: Jobs field allows configuration for all backup
@@ -35348,6 +35356,8 @@ spec:
3534835356
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
3534935357
type: object
3535035358
type: object
35359+
required:
35360+
- image
3535135361
type: object
3535235362
instances:
3535335363
description: |-
@@ -38168,6 +38178,8 @@ spec:
3816838178
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
3816938179
type: object
3817038180
type: object
38181+
required:
38182+
- image
3817138183
type: object
3817238184
initContainers:
3817338185
description: |-

internal/controller/postgrescluster/pgbackrest.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,7 @@ func generateBackupJobSpecIntent(ctx context.Context, postgresCluster *v1beta1.P
843843
}
844844
initContainers = []corev1.Container{
845845
k8s.InitContainer(
846+
postgresCluster,
846847
naming.PGBackRestRepoContainerName,
847848
initImage,
848849
postgresCluster.Spec.ImagePullPolicy,

internal/patroni/reconcile.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func InstancePod(ctx context.Context,
148148
// K8SPG-708 instanceInitContainer adds the instance init container
149149
func instanceInitContainer(cluster *v1beta1.PostgresCluster, container *corev1.Container, instancePod *corev1.PodTemplateSpec, inInstanceSpec *v1beta1.PostgresInstanceSetSpec, initImage string) {
150150
instancePod.Spec.InitContainers = append(instancePod.Spec.InitContainers, k8s.InitContainer(
151+
cluster,
151152
naming.ContainerDatabase,
152153
initImage,
153154
cluster.Spec.ImagePullPolicy,

percona/k8s/util.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,21 @@ func GetWatchNamespace() (string, error) {
3939
return ns, nil
4040
}
4141

42-
func InitContainer(componentName, image string,
42+
func InitContainer(cluster *v1beta1.PostgresCluster, componentName, image string,
4343
pullPolicy corev1.PullPolicy,
4444
secCtx *corev1.SecurityContext,
4545
resources corev1.ResourceRequirements,
4646
component ComponentWithInit,
4747
) corev1.Container {
4848
if component != nil && component.GetInitContainer() != nil && component.GetInitContainer().Resources != nil {
4949
resources = *component.GetInitContainer().Resources
50+
} else if ic := cluster.Spec.InitContainer; ic != nil && ic.Resources != nil {
51+
resources = *ic.Resources
5052
}
5153
if component != nil && component.GetInitContainer() != nil && component.GetInitContainer().ContainerSecurityContext != nil {
5254
secCtx = component.GetInitContainer().ContainerSecurityContext
55+
} else if ic := cluster.Spec.InitContainer; ic != nil && ic.ContainerSecurityContext != nil {
56+
secCtx = ic.ContainerSecurityContext
5357
}
5458

5559
volumeMounts := []corev1.VolumeMount{

0 commit comments

Comments
 (0)