Skip to content

Commit 676233c

Browse files
pooknullhors
authored andcommitted
K8SPG-648: fix patroni-version-check behaviour on startup (#1081)
* K8SPG-648: fix `patroni-version-check` behaviour on startup https://perconadev.atlassian.net/browse/K8SPG-648 * better fix * add `pgv2.percona.com/custom-patroni-version` annotation * add example into cr.yaml --------- Co-authored-by: Viacheslav Sarzhan <[email protected]>
1 parent 0381fdb commit 676233c

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

deploy/cr.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ apiVersion: pgv2.percona.com/v2
22
kind: PerconaPGCluster
33
metadata:
44
name: cluster1
5+
# annotations:
6+
# pgv2.percona.com/custom-patroni-version: "4"
57
# finalizers:
68
# - percona.com/delete-pvc
79
# - percona.com/delete-ssl

percona/controller/pgcluster/controller.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
batchv1 "k8s.io/api/batch/v1"
1818
corev1 "k8s.io/api/core/v1"
1919
k8serrors "k8s.io/apimachinery/pkg/api/errors"
20+
"k8s.io/apimachinery/pkg/api/resource"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
"k8s.io/apimachinery/pkg/labels"
2223
"k8s.io/apimachinery/pkg/types"
@@ -334,9 +335,8 @@ func (r *PGClusterReconciler) reconcilePatroniVersionCheck(ctx context.Context,
334335
cr.Annotations = make(map[string]string)
335336
}
336337

337-
// This annotation is used for unit-tests only. Allows to skip the patroni version check
338-
if _, ok := cr.Annotations[pNaming.InternalAnnotationDisablePatroniVersionCheck]; ok {
339-
cr.Annotations[pNaming.AnnotationPatroniVersion] = cr.Status.PatroniVersion
338+
if patroniVersion, ok := cr.Annotations[pNaming.AnnotationCustomPatroniVersion]; ok {
339+
cr.Annotations[pNaming.AnnotationPatroniVersion] = patroniVersion
340340
return nil
341341
}
342342

@@ -371,7 +371,7 @@ func (r *PGClusterReconciler) reconcilePatroniVersionCheck(ctx context.Context,
371371

372372
// If the imageIDs slice contains the imageID from the status, we skip checking the Patroni version.
373373
// This ensures that the Patroni version is only checked after all pods have been updated.
374-
if slices.Contains(imageIDs, cr.Status.Postgres.ImageID) && cr.Status.PatroniVersion != "" {
374+
if (len(imageIDs) == 0 || slices.Contains(imageIDs, cr.Status.Postgres.ImageID)) && cr.Status.PatroniVersion != "" {
375375
cr.Annotations[pNaming.AnnotationPatroniVersion] = cr.Status.PatroniVersion
376376
return nil
377377
}
@@ -404,13 +404,23 @@ func (r *PGClusterReconciler) reconcilePatroniVersionCheck(ctx context.Context,
404404
"bash",
405405
},
406406
Args: []string{
407-
"-c", "sleep 300",
407+
"-c", "sleep 60",
408408
},
409409
Resources: cr.Spec.InstanceSets[0].Resources,
410410
},
411411
},
412412
SecurityContext: cr.Spec.InstanceSets[0].SecurityContext,
413413
TerminationGracePeriodSeconds: ptr.To(int64(5)),
414+
Resources: &corev1.ResourceRequirements{
415+
Limits: corev1.ResourceList{
416+
corev1.ResourceCPU: resource.MustParse("100m"),
417+
corev1.ResourceMemory: resource.MustParse("64Mi"),
418+
},
419+
Requests: corev1.ResourceList{
420+
corev1.ResourceCPU: resource.MustParse("50m"),
421+
corev1.ResourceMemory: resource.MustParse("32Mi"),
422+
},
423+
},
414424
},
415425
}
416426

percona/controller/pgcluster/testutils_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ func readTestCR(name, namespace, testFile string) (*v2.PerconaPGCluster, error)
9898
if cr.Annotations == nil {
9999
cr.Annotations = make(map[string]string)
100100
}
101-
cr.Annotations[pNaming.InternalAnnotationDisablePatroniVersionCheck] = "true"
101+
cr.Annotations[pNaming.AnnotationCustomPatroniVersion] = "4.0.0"
102102
cr.Status.Postgres.Version = cr.Spec.PostgresVersion
103-
cr.Status.PatroniVersion = "4.0.0"
104103
return cr, nil
105104
}
106105

@@ -120,10 +119,9 @@ func readDefaultCR(name, namespace string) (*v2.PerconaPGCluster, error) {
120119
if cr.Annotations == nil {
121120
cr.Annotations = make(map[string]string)
122121
}
123-
cr.Annotations[pNaming.InternalAnnotationDisablePatroniVersionCheck] = "true"
122+
cr.Annotations[pNaming.AnnotationCustomPatroniVersion] = "4.0.0"
124123
cr.Namespace = namespace
125124
cr.Status.Postgres.Version = cr.Spec.PostgresVersion
126-
cr.Status.PatroniVersion = "4.0.0"
127125
return cr, nil
128126
}
129127

percona/naming/annotations.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ const (
4040

4141
AnnotationPatroniVersion = PrefixPerconaPGV2 + "patroni-version"
4242

43-
// Should be used only for unit-testing
44-
InternalAnnotationDisablePatroniVersionCheck = PrefixPerconaInternal + "patroni-version-check-disable"
43+
// Special annotation to disable `patroni-version-check` by overriding the patroni version with a custom value.
44+
AnnotationCustomPatroniVersion = PrefixPerconaPGV2 + "custom-patroni-version"
4545
)

0 commit comments

Comments
 (0)