Skip to content

Commit cdb5c8d

Browse files
committed
remove custom patroni annotation
1 parent ab6185c commit cdb5c8d

File tree

6 files changed

+6
-227
lines changed

6 files changed

+6
-227
lines changed

deploy/cr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: PerconaPGCluster
33
metadata:
44
name: cluster1
55
# annotations:
6-
# pgv2.percona.com/custom-patroni-version: "4"
6+
# test-annotation: value
77
# finalizers:
88
# - percona.com/delete-pvc
99
# - percona.com/delete-ssl

percona/controller/pgcluster/patroniversion.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
k8serrors "k8s.io/apimachinery/pkg/api/errors"
1414
"k8s.io/apimachinery/pkg/api/resource"
1515
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
"k8s.io/apimachinery/pkg/types"
1716
"k8s.io/apimachinery/pkg/util/wait"
1817
"k8s.io/client-go/util/retry"
1918
"k8s.io/utils/ptr"
@@ -34,41 +33,6 @@ func (r *PGClusterReconciler) reconcilePatroniVersion(ctx context.Context, cr *v
3433
cr.Annotations = make(map[string]string)
3534
}
3635

37-
if patroniVersion, ok := cr.Annotations[pNaming.AnnotationCustomPatroniVersion]; ok {
38-
patroniVersionUpdateFunc := func() error {
39-
cluster := &v2.PerconaPGCluster{}
40-
if err := r.Client.Get(ctx, types.NamespacedName{
41-
Name: cr.Name,
42-
Namespace: cr.Namespace,
43-
}, cluster); err != nil {
44-
return errors.Wrap(err, "get PerconaPGCluster")
45-
}
46-
47-
orig := cluster.DeepCopy()
48-
49-
cluster.Status.Patroni.Version = patroniVersion
50-
cluster.Status.PatroniVersion = patroniVersion
51-
52-
if err := r.Client.Status().Patch(ctx, cluster.DeepCopy(), client.MergeFrom(orig)); err != nil {
53-
return errors.Wrap(err, "failed to patch patroni version")
54-
}
55-
56-
err := r.patchPatroniVersionAnnotation(ctx, cr, patroniVersion)
57-
if err != nil {
58-
return errors.Wrap(err, "failed to patch patroni version annotation")
59-
}
60-
61-
return nil
62-
}
63-
64-
// To ensure that the update was done given that conflicts can be caused by
65-
// other code making unrelated updates to the same resource at the same time.
66-
if err := retry.RetryOnConflict(retry.DefaultRetry, patroniVersionUpdateFunc); err != nil {
67-
return errors.Wrap(err, "failed to patch patroni version")
68-
}
69-
return nil
70-
}
71-
7236
// Starting from version 2.8.0, the patroni version check pod should not be executed.
7337
if cr.CompareVersion("2.8.0") >= 0 {
7438

percona/controller/pgcluster/patroniversion_test.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,62 +18,6 @@ import (
1818
var _ = Describe("patroni version check", Ordered, func() {
1919
ctx := context.Background()
2020

21-
const crName = "patroni-version-test"
22-
const ns = crName
23-
crNamespacedName := types.NamespacedName{Name: crName, Namespace: ns}
24-
25-
namespace := &corev1.Namespace{
26-
ObjectMeta: metav1.ObjectMeta{
27-
Name: crName,
28-
Namespace: ns,
29-
},
30-
}
31-
32-
BeforeAll(func() {
33-
By("Creating the Namespace to perform the tests")
34-
err := k8sClient.Create(ctx, namespace)
35-
Expect(err).To(Not(HaveOccurred()))
36-
})
37-
38-
AfterAll(func() {
39-
By("Deleting the Namespace to perform the tests")
40-
_ = k8sClient.Delete(ctx, namespace)
41-
})
42-
43-
Context("With custom patroni version annotation", func() {
44-
cr, err := readDefaultCR(crName, ns)
45-
It("should read default cr.yaml", func() {
46-
Expect(err).NotTo(HaveOccurred())
47-
})
48-
49-
It("should create PerconaPGCluster with custom patroni version", func() {
50-
if cr.Annotations == nil {
51-
cr.Annotations = make(map[string]string)
52-
}
53-
cr.Annotations[pNaming.AnnotationCustomPatroniVersion] = "3.2.1"
54-
55-
status := cr.Status
56-
Expect(k8sClient.Create(ctx, cr)).Should(Succeed())
57-
cr.Status = status
58-
Expect(k8sClient.Status().Update(ctx, cr)).Should(Succeed())
59-
})
60-
61-
It("should successfully reconcile patroni version check", func() {
62-
reconcilerInstance := reconciler(cr)
63-
err := reconcilerInstance.reconcilePatroniVersion(ctx, cr)
64-
Expect(err).NotTo(HaveOccurred())
65-
})
66-
67-
It("should copy custom patroni version to status", func() {
68-
updatedCR := &v2.PerconaPGCluster{}
69-
Expect(k8sClient.Get(ctx, crNamespacedName, updatedCR)).Should(Succeed())
70-
71-
Expect(updatedCR.Status.Patroni.Version).To(Equal("3.2.1"))
72-
Expect(updatedCR.Status.PatroniVersion).To(Equal("3.2.1"))
73-
Expect(updatedCR.Annotations[pNaming.AnnotationPatroniVersion]).To(Equal("3.2.1"))
74-
})
75-
})
76-
7721
Context("Without custom patroni version annotation for cr version <=2.7", func() {
7822
const crName2 = "patroni-version-test-2"
7923
const ns2 = crName2
@@ -104,11 +48,6 @@ var _ = Describe("patroni version check", Ordered, func() {
10448
})
10549

10650
It("should create PerconaPGCluster without custom patroni version annotation", func() {
107-
if cr2.Annotations == nil {
108-
cr2.Annotations = make(map[string]string)
109-
}
110-
delete(cr2.Annotations, pNaming.AnnotationCustomPatroniVersion)
111-
11251
uid := int64(1001)
11352
cr2.Spec.InstanceSets[0].SecurityContext = &corev1.PodSecurityContext{
11453
RunAsUser: &uid,

percona/naming/annotations.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ const (
1616
// The value of the annotation will be a type of a backup (e.g. "manual" or "replica-create).
1717
AnnotationPGBackrestBackupJobType = AnnotationPGBackrestBackup + "-job-type"
1818

19-
// AnnotationPGBackRestRestore is the annotation that is added to a PerconaPGCluster to initiate an in-place
20-
// restore. The value of the annotation will be a unique identfier for a restore Job (e.g. a
21-
// timestamp), which will be stored in the PostgresCluster status to properly track completion
22-
// of the Job.
23-
AnnotationPGBackRestRestore = PrefixPerconaPGV2 + "pgbackrest-restore"
24-
2519
// AnnotationPMMSecretHash is the annotation that is added to instance annotations to
2620
// rollout restart PG pods in case PMM credentials are rotated.
2721
AnnotationPMMSecretHash = PrefixPerconaPGV2 + "pmm-secret-hash"
@@ -43,7 +37,4 @@ const (
4337
AnnotationClusterBootstrapRestore = PrefixPerconaPGV2 + "cluster-bootstrap-restore"
4438

4539
AnnotationPatroniVersion = PrefixPerconaPGV2 + "patroni-version"
46-
47-
// Special annotation to disable `patroni-version-check` by overriding the patroni version with a custom value.
48-
AnnotationCustomPatroniVersion = PrefixPerconaPGV2 + "custom-patroni-version"
4940
)

percona/postgres/common.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"k8s.io/apimachinery/pkg/labels"
1010
"sigs.k8s.io/controller-runtime/pkg/client"
1111

12-
pNaming "github.com/percona/percona-postgresql-operator/v2/percona/naming"
1312
v2 "github.com/percona/percona-postgresql-operator/v2/pkg/apis/pgv2.percona.com/v2"
1413
)
1514

@@ -59,12 +58,8 @@ func determineVersion(cr *v2.PerconaPGCluster) string {
5958
if cr.CompareVersion("2.7.0") <= 0 {
6059
return cr.Status.PatroniVersion
6160
}
62-
patroniVersion, ok := cr.Annotations[pNaming.AnnotationPatroniVersion]
63-
if !ok {
64-
// If the annotation is non-existing, the operator is assuming version 4.x.x by default
65-
// in order to enforce the use of "primary" role. Patroni version after 4.x.x will also
66-
// use "primary", so the operator will be compatible with them as well.
67-
return patroniVersion4
68-
}
69-
return patroniVersion
61+
// The operator is assuming version 4.x.x by default in order to enforce the
62+
// use of "primary" role. Patroni version after 4.x.x will also
63+
// use "primary", so the operator will be compatible with them as well.
64+
return patroniVersion4
7065
}

percona/postgres/common_test.go

Lines changed: 1 addition & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -24,49 +24,7 @@ func TestGetPrimaryPod(t *testing.T) {
2424
expectedError string
2525
expectedPod string
2626
}{
27-
"patroni 4.1.0 with annotation": {
28-
cr: &v2.PerconaPGCluster{
29-
Spec: v2.PerconaPGClusterSpec{
30-
CRVersion: version.Version(),
31-
},
32-
ObjectMeta: metav1.ObjectMeta{
33-
Name: "test-cluster",
34-
Namespace: "test-namespace",
35-
Annotations: map[string]string{
36-
pNaming.AnnotationPatroniVersion: "4.1.0",
37-
},
38-
},
39-
Status: v2.PerconaPGClusterStatus{
40-
Patroni: v2.Patroni{
41-
Version: "4.0.0",
42-
},
43-
},
44-
},
45-
pods: []corev1.Pod{
46-
{
47-
ObjectMeta: metav1.ObjectMeta{
48-
Name: "test-cluster-primary-0",
49-
Namespace: "test-namespace",
50-
Labels: map[string]string{
51-
"app.kubernetes.io/instance": "test-cluster",
52-
"postgres-operator.crunchydata.com/role": "primary",
53-
},
54-
},
55-
},
56-
{
57-
ObjectMeta: metav1.ObjectMeta{
58-
Name: "test-cluster-primary-1",
59-
Namespace: "test-namespace",
60-
Labels: map[string]string{
61-
"app.kubernetes.io/instance": "test-cluster",
62-
"postgres-operator.crunchydata.com/role": "something",
63-
},
64-
},
65-
},
66-
},
67-
expectedPod: "test-cluster-primary-0",
68-
},
69-
"patroni 4.0.0 without annotation": {
27+
"patroni 4.0.0": {
7028
cr: &v2.PerconaPGCluster{
7129
Spec: v2.PerconaPGClusterSpec{
7230
CRVersion: version.Version(),
@@ -132,74 +90,6 @@ func TestGetPrimaryPod(t *testing.T) {
13290
},
13391
expectedPod: "test-cluster-master-0",
13492
},
135-
"patroni version from annotation overrides status for version >= 2.8.0": {
136-
cr: &v2.PerconaPGCluster{
137-
ObjectMeta: metav1.ObjectMeta{
138-
Name: "test-cluster",
139-
Namespace: "test-namespace",
140-
Annotations: map[string]string{
141-
pNaming.AnnotationPatroniVersion: "4.1.0",
142-
},
143-
},
144-
Spec: v2.PerconaPGClusterSpec{
145-
PostgresVersion: 16,
146-
CRVersion: version.Version(),
147-
},
148-
Status: v2.PerconaPGClusterStatus{
149-
PatroniVersion: "3.0.0",
150-
Postgres: v2.PostgresStatus{
151-
Version: 16,
152-
},
153-
},
154-
},
155-
pods: []corev1.Pod{
156-
{
157-
ObjectMeta: metav1.ObjectMeta{
158-
Name: "test-cluster-primary-0",
159-
Namespace: "test-namespace",
160-
Labels: map[string]string{
161-
"app.kubernetes.io/instance": "test-cluster",
162-
"postgres-operator.crunchydata.com/role": "primary",
163-
},
164-
},
165-
},
166-
},
167-
expectedPod: "test-cluster-primary-0",
168-
},
169-
"patroni version from status used for version < 2.8.0": {
170-
cr: &v2.PerconaPGCluster{
171-
ObjectMeta: metav1.ObjectMeta{
172-
Name: "test-cluster",
173-
Namespace: "test-namespace",
174-
Annotations: map[string]string{
175-
pNaming.AnnotationPatroniVersion: "4.0.0",
176-
},
177-
},
178-
Spec: v2.PerconaPGClusterSpec{
179-
PostgresVersion: 14,
180-
CRVersion: "2.7.0",
181-
},
182-
Status: v2.PerconaPGClusterStatus{
183-
PatroniVersion: "3.0.0",
184-
Postgres: v2.PostgresStatus{
185-
Version: 14,
186-
},
187-
},
188-
},
189-
pods: []corev1.Pod{
190-
{
191-
ObjectMeta: metav1.ObjectMeta{
192-
Name: "test-cluster-master-0",
193-
Namespace: "test-namespace",
194-
Labels: map[string]string{
195-
"app.kubernetes.io/instance": "test-cluster",
196-
"postgres-operator.crunchydata.com/role": "master",
197-
},
198-
},
199-
},
200-
},
201-
expectedPod: "test-cluster-master-0",
202-
},
20393
"no primary pod found": {
20494
cr: &v2.PerconaPGCluster{
20595
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)