@@ -172,6 +172,40 @@ var _ = Describe("PostgreSQL Operator end-to-end tests", func() {
172
172
Expect (svc .Spec .Ports [0 ].Name ).To (Equal ("postgresql" ))
173
173
Expect (svc .Spec .Ports [0 ].Port ).To (Equal (int32 (5432 )))
174
174
Expect (svc .Spec .Ports [0 ].Protocol ).To (Equal (corev1 .ProtocolTCP ))
175
+ Expect (svc .Spec .Ports ).To (HaveLen (1 ))
176
+ })
177
+
178
+ By ("creating a Service that points to all of the pods for the Patroni API" , func () {
179
+ svc := & corev1.Service {}
180
+ Expect (k8sClient .Get (ctx ,
181
+ types.NamespacedName {
182
+ Name : postgresql .PatroniService (
183
+ instance .GetName ()),
184
+ Namespace : instance .GetNamespace ()},
185
+ svc )).To (Succeed ())
186
+
187
+ By ("checking a8s labels added to Service" , func () {
188
+ Expect (svc .Labels ).To (HaveKeyWithValue ("a8s.a9s/dsi-name" , pg .Name ))
189
+ Expect (svc .Labels ).
190
+ To (HaveKeyWithValue ("a8s.a9s/dsi-group" , "postgresql.anynines.com" ))
191
+ Expect (svc .Labels ).
192
+ To (HaveKeyWithValue ("a8s.a9s/dsi-kind" , "Postgresql" ))
193
+ })
194
+
195
+ By ("checking a8s labels as selector" , func () {
196
+ Expect (svc .Spec .Selector ).To (HaveKeyWithValue ("a8s.a9s/dsi-name" , pg .Name ))
197
+ Expect (svc .Spec .Selector ).
198
+ To (HaveKeyWithValue ("a8s.a9s/dsi-group" , "postgresql.anynines.com" ))
199
+ Expect (svc .Spec .Selector ).To (HaveKeyWithValue ("a8s.a9s/dsi-kind" , "Postgresql" ))
200
+ Expect (svc .Spec .Selector ).To (HaveKeyWithValue ("a8s.a9s/replication-role" , "master" ))
201
+ Expect (len (svc .Spec .Selector )).To (Equal (4 ))
202
+ })
203
+
204
+ Expect (svc .Spec .Type ).To (Equal (corev1 .ServiceTypeClusterIP ))
205
+ Expect (svc .Spec .Ports [0 ].Name ).To (Equal ("patroni" ))
206
+ Expect (svc .Spec .Ports [0 ].Port ).To (Equal (int32 (8008 )))
207
+ Expect (svc .Spec .Ports [0 ].Protocol ).To (Equal (corev1 .ProtocolTCP ))
208
+ Expect (svc .Spec .Ports ).To (HaveLen (1 ))
175
209
})
176
210
177
211
By ("creating the ServiceAccount" , func () {
@@ -301,10 +335,10 @@ var _ = Describe("PostgreSQL Operator end-to-end tests", func() {
301
335
},
302
336
})).To (Succeed (), "failed to list events emitted for test DSI" )
303
337
304
- Expect (len (instanceEvents .Items )).To (Equal (6 ), "found more events than expected, " +
338
+ Expect (len (instanceEvents .Items )).To (Equal (7 ), "found more events than expected, " +
305
339
"there should be one for every secondary API object that the Operator " +
306
- "directly creates (ServiceAccount, RoleBinding, master Service, StatefulSet , " +
307
- "two Secrets)" )
340
+ "directly creates (ServiceAccount, RoleBinding, master Service, patroni Service , " +
341
+ "StatefulSet, two Secrets)" )
308
342
309
343
// Sort events by message so that we know for which secondary API object each event
310
344
// is created w/o having to inspect the event first. *This is a hack that makes the
@@ -320,8 +354,9 @@ var _ = Describe("PostgreSQL Operator end-to-end tests", func() {
320
354
adminSecretEvent := instanceEvents .Items [1 ]
321
355
standbySecretsEvent := instanceEvents .Items [2 ]
322
356
masterSvcEvent := instanceEvents .Items [3 ]
323
- svcAccountEvent := instanceEvents .Items [4 ]
324
- ssetEvent := instanceEvents .Items [5 ]
357
+ patroniSvcEvent := instanceEvents .Items [4 ]
358
+ svcAccountEvent := instanceEvents .Items [5 ]
359
+ ssetEvent := instanceEvents .Items [6 ]
325
360
326
361
By ("emitting an event for the creation of the roleBinding" , func () {
327
362
Expect (roleBindingEvent .Message ).To (Equal ("Successfully created roleBinding" ),
@@ -397,6 +432,25 @@ var _ = Describe("PostgreSQL Operator end-to-end tests", func() {
397
432
"wrong event involvedObject.apiVersion" )
398
433
})
399
434
435
+ By ("emitting an event for the creation of the patroni service" , func () {
436
+ Expect (patroniSvcEvent .Message ).
437
+ To (Equal (fmt .Sprintf ("Successfully created service: %s/%s-patroni" ,
438
+ pg .Namespace ,
439
+ pg .Name )),
440
+ "wrong event message" )
441
+ Expect (patroniSvcEvent .Type ).To (Equal (corev1 .EventTypeNormal ),
442
+ "wrong event type" )
443
+ Expect (patroniSvcEvent .Reason ).To (Equal ("Created" ), "wrong event reason" )
444
+ Expect (patroniSvcEvent .Count ).To (Equal (int32 (1 )), "wrong event count" )
445
+ Expect (patroniSvcEvent .Source .Component ).To (Equal ("postgresql-controller" ),
446
+ "wrong event source.component" )
447
+ Expect (patroniSvcEvent .InvolvedObject .Kind ).To (Equal ("Postgresql" ),
448
+ "wrong event involvedObject.kind" )
449
+ Expect (patroniSvcEvent .InvolvedObject .APIVersion ).
450
+ To (Equal ("postgresql.anynines.com/v1beta3" ),
451
+ "wrong event involvedObject.apiVersion" )
452
+ })
453
+
400
454
By ("emitting an event for the creation of the serviceAcccount" , func () {
401
455
Expect (svcAccountEvent .Message ).To (Equal ("Successfully created serviceAccount" ),
402
456
"wrong event message" )
@@ -615,6 +669,35 @@ var _ = Describe("PostgreSQL Operator end-to-end tests", func() {
615
669
}, asyncOpsTimeoutMins , 1 * time .Second ).Should (Succeed ())
616
670
})
617
671
672
+ By ("Ensuring patroni service labels are updated" , func () {
673
+ Eventually (func (g Gomega ) {
674
+ svc := & corev1.Service {}
675
+ Expect (k8sClient .Get (ctx ,
676
+ types.NamespacedName {
677
+ Name : postgresql .PatroniService (
678
+ instance .GetName ()),
679
+ Namespace : instance .GetNamespace ()},
680
+ svc )).To (Succeed ())
681
+ g .Expect (err ).To (BeNil ())
682
+
683
+ g .Expect (svc .Labels ).To (HaveKeyWithValue ("test-label-1" , "val3" ))
684
+ g .Expect (svc .Labels ).To (HaveKeyWithValue ("test-label-4" , "val4" ))
685
+ g .Expect (svc .Labels ).To (HaveKeyWithValue ("a8s.a9s/dsi-name" , instance .GetName ()))
686
+ g .Expect (svc .Labels ).
687
+ To (HaveKeyWithValue ("a8s.a9s/dsi-group" , "postgresql.anynines.com" ))
688
+ g .Expect (svc .Labels ).To (HaveKeyWithValue ("a8s.a9s/dsi-kind" , "Postgresql" ))
689
+ g .Expect (len (svc .Labels )).To (Equal (numA8SLabels + 2 ))
690
+
691
+ g .Expect (svc .Spec .Selector ).
692
+ To (HaveKeyWithValue ("a8s.a9s/replication-role" , "master" ))
693
+ g .Expect (svc .Spec .Selector ).To (HaveKeyWithValue ("a8s.a9s/dsi-name" , instance .GetName ()))
694
+ g .Expect (svc .Spec .Selector ).
695
+ To (HaveKeyWithValue ("a8s.a9s/dsi-group" , "postgresql.anynines.com" ))
696
+ g .Expect (svc .Spec .Selector ).To (HaveKeyWithValue ("a8s.a9s/dsi-kind" , "Postgresql" ))
697
+ g .Expect (len (svc .Spec .Selector )).To (Equal (numA8SLabels + 1 ))
698
+ }, asyncOpsTimeoutMins , 1 * time .Second ).Should (Succeed ())
699
+ })
700
+
618
701
By ("Ensuring ServiceAccount labels are updated" , func () {
619
702
Eventually (func (g Gomega ) {
620
703
sa := & corev1.ServiceAccount {}
@@ -751,6 +834,17 @@ var _ = Describe("PostgreSQL Operator end-to-end tests", func() {
751
834
}, asyncOpsTimeoutMins ).Should (BeTrue ())
752
835
})
753
836
837
+ By ("removing the service that points to the patroni API" , func () {
838
+ Eventually (func () bool {
839
+ err := k8sClient .Get (ctx ,
840
+ types.NamespacedName {
841
+ Name : postgresql .PatroniService (instance .GetName ()),
842
+ Namespace : instance .GetNamespace ()},
843
+ & corev1.Service {})
844
+ return err != nil && k8serrors .IsNotFound (err )
845
+ }, asyncOpsTimeoutMins ).Should (BeTrue ())
846
+ })
847
+
754
848
By ("removing the RoleBinding between the PostgreSQL instance service account and the Spilo role" , func () {
755
849
Eventually (func () bool {
756
850
err := k8sClient .Get (
0 commit comments