Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2859269

Browse files
committedMar 21, 2025·
fix
1 parent 846797a commit 2859269

20 files changed

+91
-34
lines changed
 

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

+3
Original file line numberDiff line numberDiff line change
@@ -8400,6 +8400,9 @@ spec:
84008400
type: object
84018401
x-kubernetes-map-type: atomic
84028402
type: array
8403+
initImage:
8404+
description: K8SPG-613
8405+
type: string
84038406
instances:
84048407
description: |-
84058408
Specifies one or more sets of PostgreSQL pods that replicate data for

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

+2
Original file line numberDiff line numberDiff line change
@@ -8201,6 +8201,8 @@ spec:
82018201
type: object
82028202
x-kubernetes-map-type: atomic
82038203
type: array
8204+
initImage:
8205+
type: string
82048206
instances:
82058207
description: |-
82068208
Specifies one or more sets of PostgreSQL pods that replicate data for

‎config/bundle/kustomization.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ resources:
66
- ../manager/namespace
77
images:
88
- name: postgres-operator
9-
newName: perconalab/percona-postgresql-operator
10-
newTag: main
9+
newName: ademajazzserve/percona-postgresql-operator
10+
newTag: dev_K8SPG-613-6

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

+2
Original file line numberDiff line numberDiff line change
@@ -8606,6 +8606,8 @@ spec:
86068606
type: object
86078607
x-kubernetes-map-type: atomic
86088608
type: array
8609+
initImage:
8610+
type: string
86098611
instances:
86108612
description: |-
86118613
Specifies one or more sets of PostgreSQL pods that replicate data for

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

+3
Original file line numberDiff line numberDiff line change
@@ -8355,6 +8355,9 @@ spec:
83558355
type: object
83568356
x-kubernetes-map-type: atomic
83578357
type: array
8358+
initImage:
8359+
description: K8SPG-613
8360+
type: string
83588361
instances:
83598362
description: |-
83608363
Specifies one or more sets of PostgreSQL pods that replicate data for

‎config/cw-bundle/kustomization.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ resources:
77

88
images:
99
- name: postgres-operator
10-
newName: perconalab/percona-postgresql-operator
11-
newTag: main
10+
newName: ademajazzserve/percona-postgresql-operator
11+
newTag: dev_K8SPG-613-6

‎config/manager/cluster/kustomization.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ patchesStrategicMerge:
88

99
images:
1010
- name: postgres-operator
11-
newName: perconalab/percona-postgresql-operator
12-
newTag: main
11+
newName: ademajazzserve/percona-postgresql-operator
12+
newTag: dev_K8SPG-613-6

‎config/manager/namespace/kustomization.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ patchesStrategicMerge:
99

1010
images:
1111
- name: postgres-operator
12-
newName: perconalab/percona-postgresql-operator
13-
newTag: main
12+
newName: ademajazzserve/percona-postgresql-operator
13+
newTag: dev_K8SPG-613-6

‎deploy/bundle.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -8899,6 +8899,8 @@ spec:
88998899
type: object
89008900
x-kubernetes-map-type: atomic
89018901
type: array
8902+
initImage:
8903+
type: string
89028904
instances:
89038905
description: |-
89048906
Specifies one or more sets of PostgreSQL pods that replicate data for
@@ -34035,6 +34037,9 @@ spec:
3403534037
type: object
3403634038
x-kubernetes-map-type: atomic
3403734039
type: array
34040+
initImage:
34041+
description: K8SPG-613
34042+
type: string
3403834043
instances:
3403934044
description: |-
3404034045
Specifies one or more sets of PostgreSQL pods that replicate data for
@@ -45993,7 +45998,7 @@ spec:
4599345998
value: INFO
4599445999
- name: DISABLE_TELEMETRY
4599546000
value: "false"
45996-
image: perconalab/percona-postgresql-operator:main
46001+
image: ademajazzserve/percona-postgresql-operator:dev_K8SPG-613-6
4599746002
imagePullPolicy: Always
4599846003
livenessProbe:
4599946004
failureThreshold: 3

‎deploy/cr.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ metadata:
1010
# - percona.com/delete-backups
1111
spec:
1212
crVersion: 2.6.0
13+
# initImage: perconalab/percona-postgresql-operator:main
1314
# metadata:
1415
# annotations:
1516
# example-annotation: value

‎deploy/crd.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -8899,6 +8899,8 @@ spec:
88998899
type: object
89008900
x-kubernetes-map-type: atomic
89018901
type: array
8902+
initImage:
8903+
type: string
89028904
instances:
89038905
description: |-
89048906
Specifies one or more sets of PostgreSQL pods that replicate data for
@@ -34035,6 +34037,9 @@ spec:
3403534037
type: object
3403634038
x-kubernetes-map-type: atomic
3403734039
type: array
34040+
initImage:
34041+
description: K8SPG-613
34042+
type: string
3403834043
instances:
3403934044
description: |-
3404034045
Specifies one or more sets of PostgreSQL pods that replicate data for

‎deploy/cw-bundle.yaml

+6-1
Original file line numberDiff line numberDiff line change
@@ -8899,6 +8899,8 @@ spec:
88998899
type: object
89008900
x-kubernetes-map-type: atomic
89018901
type: array
8902+
initImage:
8903+
type: string
89028904
instances:
89038905
description: |-
89048906
Specifies one or more sets of PostgreSQL pods that replicate data for
@@ -34035,6 +34037,9 @@ spec:
3403534037
type: object
3403634038
x-kubernetes-map-type: atomic
3403734039
type: array
34040+
initImage:
34041+
description: K8SPG-613
34042+
type: string
3403834043
instances:
3403934044
description: |-
3404034045
Specifies one or more sets of PostgreSQL pods that replicate data for
@@ -45991,7 +45996,7 @@ spec:
4599145996
value: INFO
4599245997
- name: DISABLE_TELEMETRY
4599345998
value: "false"
45994-
image: perconalab/percona-postgresql-operator:main
45999+
image: ademajazzserve/percona-postgresql-operator:dev_K8SPG-613-6
4599546000
imagePullPolicy: Always
4599646001
livenessProbe:
4599746002
failureThreshold: 3

‎deploy/cw-operator.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ spec:
4242
value: INFO
4343
- name: DISABLE_TELEMETRY
4444
value: "false"
45-
image: perconalab/percona-postgresql-operator:main
45+
image: ademajazzserve/percona-postgresql-operator:dev_K8SPG-613-6
4646
imagePullPolicy: Always
4747
livenessProbe:
4848
failureThreshold: 3

‎deploy/operator.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ spec:
4545
value: INFO
4646
- name: DISABLE_TELEMETRY
4747
value: "false"
48-
image: perconalab/percona-postgresql-operator:main
48+
image: ademajazzserve/percona-postgresql-operator:dev_K8SPG-613-6
4949
imagePullPolicy: Always
5050
livenessProbe:
5151
failureThreshold: 3

‎internal/controller/postgrescluster/pgbackrest.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ func generateBackupJobSpecIntent(ctx context.Context, postgresCluster *v1beta1.P
872872
initImage,
873873
postgresCluster.Spec.ImagePullPolicy,
874874
initialize.RestrictedSecurityContext(postgresCluster.CompareVersion("2.5.0") >= 0),
875-
postgresCluster.Spec.Proxy.PGBouncer.Resources,
875+
container.Resources,
876876
),
877877
},
878878
},
@@ -2460,7 +2460,7 @@ func (r *Reconciler) reconcileManualBackup(ctx context.Context,
24602460
backupJob.ObjectMeta.Annotations = annotations
24612461

24622462
// K8SPG-613
2463-
initImage, err := k8s.InitImage(ctx, r.Client)
2463+
initImage, err := k8s.InitImage(ctx, r.Client, postgresCluster)
24642464
if err != nil {
24652465
return err
24662466
}
@@ -2632,7 +2632,7 @@ func (r *Reconciler) reconcileReplicaCreateBackup(ctx context.Context,
26322632
backupJob.ObjectMeta.Annotations = annotations
26332633

26342634
// K8SPG-613
2635-
initImage, err := k8s.InitImage(ctx, r.Client)
2635+
initImage, err := k8s.InitImage(ctx, r.Client, postgresCluster)
26362636
if err != nil {
26372637
return err
26382638
}
@@ -3069,7 +3069,7 @@ func (r *Reconciler) reconcilePGBackRestCronJob(
30693069
backupOpts := []string{"--type=" + backupType}
30703070

30713071
// K8SPG-613
3072-
initImage, err := k8s.InitImage(ctx, r.Client)
3072+
initImage, err := k8s.InitImage(ctx, r.Client, cluster)
30733073
if err != nil {
30743074
return err
30753075
}

‎internal/controller/postgrescluster/pgbackrest_test.go

+38-13
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func fakePostgresCluster(clusterName, namespace, clusterUID string,
6565
ImagePullSecrets: []corev1.LocalObjectReference{{
6666
Name: "myImagePullSecret"},
6767
},
68+
InitImage: "some-init-image",
6869
Image: "example.com/crunchy-postgres-ha:test",
6970
InstanceSets: []v1beta1.PostgresInstanceSetSpec{{
7071
Name: "instance1",
@@ -970,10 +971,10 @@ func TestReconcileReplicaCreateBackup(t *testing.T) {
970971
}
971972
}
972973
// verify mounted configuration is present
973-
assert.Assert(t, len(container.VolumeMounts) == 1)
974+
assert.Assert(t, len(container.VolumeMounts) == 2)
974975

975976
// verify volume for configuration is present
976-
assert.Assert(t, len(backupJob.Spec.Template.Spec.Volumes) == 1)
977+
assert.Assert(t, len(backupJob.Spec.Template.Spec.Volumes) == 2)
977978

978979
// verify the image pull secret
979980
assert.Assert(t, backupJob.Spec.Template.Spec.ImagePullSecrets != nil)
@@ -2460,7 +2461,7 @@ func TestGenerateBackupJobIntent(t *testing.T) {
24602461
},
24612462
},
24622463
v1beta1.PGBackRestRepo{},
2463-
"",
2464+
"", "",
24642465
nil, nil,
24652466
)
24662467
assert.Assert(t, cmp.MarshalMatches(spec.Template.Spec, `
@@ -2492,14 +2493,38 @@ containers:
24922493
seccompProfile:
24932494
type: RuntimeDefault
24942495
volumeMounts:
2496+
- mountPath: /opt/crunchy
2497+
name: crunchy-bin
24952498
- mountPath: /etc/pgbackrest/conf.d
24962499
name: pgbackrest-config
24972500
readOnly: true
24982501
enableServiceLinks: false
2502+
initContainers:
2503+
- command:
2504+
- /usr/local/bin/init-entrypoint.sh
2505+
name: pgbackrest-init
2506+
resources: {}
2507+
securityContext:
2508+
allowPrivilegeEscalation: false
2509+
capabilities:
2510+
drop:
2511+
- ALL
2512+
privileged: false
2513+
readOnlyRootFilesystem: true
2514+
runAsNonRoot: true
2515+
seccompProfile:
2516+
type: RuntimeDefault
2517+
terminationMessagePath: /dev/termination-log
2518+
terminationMessagePolicy: File
2519+
volumeMounts:
2520+
- mountPath: /opt/crunchy
2521+
name: crunchy-bin
24992522
restartPolicy: Never
25002523
securityContext:
25012524
fsGroupChangePolicy: OnRootMismatch
25022525
volumes:
2526+
- emptyDir: {}
2527+
name: crunchy-bin
25032528
- name: pgbackrest-config
25042529
projected:
25052530
sources:
@@ -2533,7 +2558,7 @@ volumes:
25332558
}
25342559
job := generateBackupJobSpecIntent(ctx,
25352560
cluster, v1beta1.PGBackRestRepo{},
2536-
"",
2561+
"", "",
25372562
nil, nil,
25382563
)
25392564
assert.Equal(t, job.Template.Spec.Containers[0].ImagePullPolicy, corev1.PullAlways)
@@ -2548,7 +2573,7 @@ volumes:
25482573
}
25492574
job := generateBackupJobSpecIntent(ctx,
25502575
cluster, v1beta1.PGBackRestRepo{},
2551-
"",
2576+
"", "",
25522577
nil, nil,
25532578
)
25542579
assert.DeepEqual(t, job.Template.Spec.Containers[0].Resources,
@@ -2565,7 +2590,7 @@ volumes:
25652590
}
25662591
job := generateBackupJobSpecIntent(ctx,
25672592
cluster, v1beta1.PGBackRestRepo{},
2568-
"",
2593+
"", "",
25692594
nil, nil,
25702595
)
25712596
assert.DeepEqual(t, job.Template.Spec.Containers[0].Resources,
@@ -2604,7 +2629,7 @@ volumes:
26042629
}
26052630
job := generateBackupJobSpecIntent(ctx,
26062631
cluster, v1beta1.PGBackRestRepo{},
2607-
"",
2632+
"", "",
26082633
nil, nil,
26092634
)
26102635
assert.Equal(t, job.Template.Spec.Affinity, affinity)
@@ -2617,7 +2642,7 @@ volumes:
26172642
}
26182643
job := generateBackupJobSpecIntent(ctx,
26192644
cluster, v1beta1.PGBackRestRepo{},
2620-
"",
2645+
"", "",
26212646
nil, nil,
26222647
)
26232648
assert.Equal(t, job.Template.Spec.PriorityClassName, "some-priority-class")
@@ -2635,7 +2660,7 @@ volumes:
26352660
}
26362661
job := generateBackupJobSpecIntent(ctx,
26372662
cluster, v1beta1.PGBackRestRepo{},
2638-
"",
2663+
"", "",
26392664
nil, nil,
26402665
)
26412666
assert.DeepEqual(t, job.Template.Spec.Tolerations, tolerations)
@@ -2648,14 +2673,14 @@ volumes:
26482673
cluster.Spec.Backups.PGBackRest.Jobs = nil
26492674

26502675
spec := generateBackupJobSpecIntent(ctx,
2651-
cluster, v1beta1.PGBackRestRepo{}, "", nil, nil,
2676+
cluster, v1beta1.PGBackRestRepo{}, "", "", nil, nil,
26522677
)
26532678
assert.Assert(t, spec.TTLSecondsAfterFinished == nil)
26542679

26552680
cluster.Spec.Backups.PGBackRest.Jobs = &v1beta1.BackupJobs{}
26562681

26572682
spec = generateBackupJobSpecIntent(ctx,
2658-
cluster, v1beta1.PGBackRestRepo{}, "", nil, nil,
2683+
cluster, v1beta1.PGBackRestRepo{}, "", "", nil, nil,
26592684
)
26602685
assert.Assert(t, spec.TTLSecondsAfterFinished == nil)
26612686
})
@@ -2666,7 +2691,7 @@ volumes:
26662691
}
26672692

26682693
spec := generateBackupJobSpecIntent(ctx,
2669-
cluster, v1beta1.PGBackRestRepo{}, "", nil, nil,
2694+
cluster, v1beta1.PGBackRestRepo{}, "", "", nil, nil,
26702695
)
26712696
if assert.Check(t, spec.TTLSecondsAfterFinished != nil) {
26722697
assert.Equal(t, *spec.TTLSecondsAfterFinished, int32(0))
@@ -2679,7 +2704,7 @@ volumes:
26792704
}
26802705

26812706
spec := generateBackupJobSpecIntent(ctx,
2682-
cluster, v1beta1.PGBackRestRepo{}, "", nil, nil,
2707+
cluster, v1beta1.PGBackRestRepo{}, "", "", nil, nil,
26832708
)
26842709
if assert.Check(t, spec.TTLSecondsAfterFinished != nil) {
26852710
assert.Equal(t, *spec.TTLSecondsAfterFinished, int32(100))

‎percona/controller/pgcluster/testutils_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ func readDefaultCR(name, namespace string) (*v2.PerconaPGCluster, error) {
119119
if cr.Annotations == nil {
120120
cr.Annotations = make(map[string]string)
121121
}
122+
cr.Spec.InitImage = "some-image"
122123
cr.Annotations[pNaming.AnnotationCustomPatroniVersion] = "4.0.0"
123124
cr.Namespace = namespace
124125
cr.Status.Postgres.Version = cr.Spec.PostgresVersion

‎percona/k8s/util.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"sigs.k8s.io/controller-runtime/pkg/client"
1818

1919
"github.com/percona/percona-postgresql-operator/percona/naming"
20+
"github.com/percona/percona-postgresql-operator/pkg/apis/postgres-operator.crunchydata.com/v1beta1"
2021
)
2122

2223
const WatchNamespaceEnvVar = "WATCH_NAMESPACE"
@@ -63,11 +64,10 @@ func InitContainer(component, image string,
6364
}
6465
}
6566

66-
func InitImage(ctx context.Context, cl client.Reader) (string, error) {
67-
// TODO:
68-
//if image := cr.Spec.InitImage; len(image) > 0 {
69-
// return image, nil
70-
//}
67+
func InitImage(ctx context.Context, cl client.Reader, cluster *v1beta1.PostgresCluster) (string, error) {
68+
if cluster != nil && len(cluster.Spec.InitImage) > 0 {
69+
return cluster.Spec.InitImage, nil
70+
}
7171
return OperatorImage(ctx, cl)
7272
}
7373

‎pkg/apis/pgv2.percona.com/v2/perconapgcluster_types.go

+2
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,8 @@ func (cr *PerconaPGCluster) ToCrunchy(ctx context.Context, postgresCluster *crun
362362

363363
postgresCluster.Spec.TLSOnly = cr.Spec.TLSOnly
364364

365+
postgresCluster.Spec.InitImage = cr.Spec.InitImage
366+
365367
return postgresCluster, nil
366368
}
367369

‎pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go

+3
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ type PostgresClusterSpec struct {
187187
Config PostgresAdditionalConfig `json:"config,omitempty"`
188188

189189
Extensions ExtensionsSpec `json:"extensions,omitempty"`
190+
191+
// K8SPG-613
192+
InitImage string `json:"initImage,omitempty"`
190193
}
191194

192195
type ExtensionsSpec struct {

0 commit comments

Comments
 (0)
Please sign in to comment.