@@ -19,6 +19,7 @@ import (
1919 "sigs.k8s.io/yaml"
2020
2121 "github.com/percona/percona-postgresql-operator/v2/internal/naming"
22+ "github.com/percona/percona-postgresql-operator/v2/internal/patroni/dcs"
2223 "github.com/percona/percona-postgresql-operator/v2/internal/postgres"
2324 "github.com/percona/percona-postgresql-operator/v2/internal/testing/cmp"
2425 "github.com/percona/percona-postgresql-operator/v2/internal/testing/require"
@@ -27,24 +28,6 @@ import (
2728 "github.com/percona/percona-postgresql-operator/v2/pkg/apis/upstream.pgv2.percona.com/v1beta1"
2829)
2930
30- // kubernetesClusterYAML stands in for dcs.For(cluster).ClusterYAML(cluster)
31- // (see internal/patroni/dcs) without importing that package from here.
32- func kubernetesClusterYAML (cluster * v1beta1.PostgresCluster ) map [string ]any {
33- labels := map [string ]string {naming .LabelCluster : cluster .Name }
34- if cluster .CompareVersion ("2.9.0" ) >= 0 {
35- labels = naming .Merge (cluster .Spec .Metadata .GetLabelsOrNil (), labels )
36- }
37- return map [string ]any {
38- "kubernetes" : map [string ]any {
39- "namespace" : cluster .Namespace ,
40- "role_label" : naming .LabelRole ,
41- "scope_label" : naming .LabelPatroni ,
42- "use_endpoints" : true ,
43- "labels" : labels ,
44- },
45- }
46- }
47-
4831func TestClusterYAML (t * testing.T ) {
4932 t .Parallel ()
5033
@@ -55,7 +38,7 @@ func TestClusterYAML(t *testing.T) {
5538 cluster .Namespace = "some-namespace"
5639 cluster .Name = "cluster-name"
5740
58- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
41+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
5942 assert .NilError (t , err )
6043 assert .Equal (t , data , strings .TrimSpace (`
6144# Generated by postgres-operator. DO NOT EDIT UNLESS YOU KNOW WHAT YOU'RE DOING.
@@ -122,7 +105,7 @@ watchdog:
122105 },
123106 }
124107
125- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
108+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
126109 assert .NilError (t , err )
127110
128111 var parsed map [string ]any
@@ -152,7 +135,7 @@ watchdog:
152135 }
153136 cluster .Spec .Patroni .Default ()
154137
155- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
138+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
156139 assert .NilError (t , err )
157140
158141 var parsed map [string ]any
@@ -174,7 +157,7 @@ watchdog:
174157 }
175158 cluster .Spec .Patroni .Default ()
176159
177- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
160+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
178161 assert .NilError (t , err )
179162
180163 var parsed map [string ]any
@@ -199,7 +182,7 @@ watchdog:
199182 }
200183 cluster .Spec .Patroni .Default ()
201184
202- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
185+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
203186 assert .NilError (t , err )
204187
205188 var parsed map [string ]any
@@ -221,7 +204,7 @@ watchdog:
221204 cluster .Spec .PostgresVersion = 17
222205 cluster .Spec .Extensions .PGTDE .Enabled = true
223206
224- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
207+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
225208 assert .NilError (t , err )
226209
227210 var parsed map [string ]any
@@ -248,7 +231,7 @@ watchdog:
248231 cluster .Spec .Patroni = & v1beta1.PatroniSpec {}
249232 cluster .Spec .Patroni .Default ()
250233
251- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
234+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
252235 assert .NilError (t , err )
253236
254237 var parsed map [string ]any
@@ -268,7 +251,7 @@ watchdog:
268251 cluster .Name = "cluster-name"
269252 cluster .Spec .PostgresVersion = 14
270253
271- data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, kubernetesClusterYAML (cluster ))
254+ data , err := clusterYAML (cluster , postgres.HBAs {}, postgres.Parameters {}, dcs . For ( cluster ). ClusterYAML (cluster ))
272255 assert .NilError (t , err )
273256 assert .Equal (t , data , strings .TrimSpace (`
274257# Generated by postgres-operator. DO NOT EDIT UNLESS YOU KNOW WHAT YOU'RE DOING.
0 commit comments