Skip to content

Commit 9ab5634

Browse files
committed
fix unit-test
1 parent 2ee4e8b commit 9ab5634

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

percona/controller/pgcluster/controller.go

+6
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ func (r *PGClusterReconciler) reconcilePatroniVersionCheck(ctx context.Context,
334334
cr.Annotations = make(map[string]string)
335335
}
336336

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
340+
return nil
341+
}
342+
337343
getImageIDFromPod := func(pod *corev1.Pod, containerName string) string {
338344
idx := slices.IndexFunc(pod.Status.ContainerStatuses, func(s corev1.ContainerStatus) bool {
339345
return s.Name == containerName

percona/controller/pgcluster/controller_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ var _ = Describe("Annotations", Ordered, func() {
113113
})
114114

115115
It("should create PerconaPGCluster with annotations", func() {
116-
cr.Annotations = make(map[string]string)
117116
cr.Annotations["pgv2.percona.com/trigger-switchover"] = "true"
118117
cr.Annotations["egedemo.com/test"] = "true"
119118

percona/controller/pgcluster/testutils_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/percona/percona-postgresql-operator/internal/controller/postgrescluster"
2222
"github.com/percona/percona-postgresql-operator/internal/naming"
2323
"github.com/percona/percona-postgresql-operator/percona/controller/pgbackup"
24+
pNaming "github.com/percona/percona-postgresql-operator/percona/naming"
2425
"github.com/percona/percona-postgresql-operator/percona/utils/registry"
2526
"github.com/percona/percona-postgresql-operator/percona/watcher"
2627
v2 "github.com/percona/percona-postgresql-operator/pkg/apis/pgv2.percona.com/v2"
@@ -94,6 +95,10 @@ func readTestCR(name, namespace, testFile string) (*v2.PerconaPGCluster, error)
9495
if cr.Spec.PostgresVersion == 0 {
9596
return nil, errors.New("postgresVersion should be specified")
9697
}
98+
if cr.Annotations == nil {
99+
cr.Annotations = make(map[string]string)
100+
}
101+
cr.Annotations[pNaming.InternalAnnotationDisablePatroniVersionCheck] = "true"
97102
cr.Status.Postgres.Version = cr.Spec.PostgresVersion
98103
cr.Status.PatroniVersion = "4.0.0"
99104
return cr, nil
@@ -112,6 +117,10 @@ func readDefaultCR(name, namespace string) (*v2.PerconaPGCluster, error) {
112117
}
113118

114119
cr.Name = name
120+
if cr.Annotations == nil {
121+
cr.Annotations = make(map[string]string)
122+
}
123+
cr.Annotations[pNaming.InternalAnnotationDisablePatroniVersionCheck] = "true"
115124
cr.Namespace = namespace
116125
cr.Status.Postgres.Version = cr.Spec.PostgresVersion
117126
cr.Status.PatroniVersion = "4.0.0"

percona/naming/annotations.go

+3
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,7 @@ const (
3939
AnnotationClusterBootstrapRestore = PrefixPerconaPGV2 + "cluster-bootstrap-restore"
4040

4141
AnnotationPatroniVersion = PrefixPerconaPGV2 + "patroni-version"
42+
43+
// Should be used only for unit-testing
44+
InternalAnnotationDisablePatroniVersionCheck = PrefixPerconaInternal + "patroni-version-check-disable"
4245
)

0 commit comments

Comments
 (0)