@@ -10,7 +10,6 @@ import (
1010 memcachedv1 "github.com/openstack-k8s-operators/infra-operator/apis/memcached/v1beta1"
1111 condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
1212 . "github.com/openstack-k8s-operators/lib-common/modules/common/test/helpers"
13- mariadbv1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
1413 watcherv1beta1 "github.com/openstack-k8s-operators/watcher-operator/api/v1beta1"
1514 corev1 "k8s.io/api/core/v1"
1615 "k8s.io/utils/ptr"
@@ -114,14 +113,6 @@ var _ = Describe("WatcherAPI controller", func() {
114113 },
115114 )
116115 DeferCleanup (k8sClient .Delete , ctx , secret )
117- mariadb .CreateMariaDBDatabase (watcherTest .WatcherDatabaseName .Namespace , watcherTest .WatcherDatabaseName .Name , mariadbv1.MariaDBDatabaseSpec {})
118- DeferCleanup (k8sClient .Delete , ctx , mariadb .GetMariaDBDatabase (watcherTest .WatcherDatabaseName ))
119-
120- mariadb .SimulateMariaDBTLSDatabaseCompleted (watcherTest .WatcherDatabaseName )
121- apiMariaDBAccount , apiMariaDBSecret := mariadb .CreateMariaDBAccountAndSecret (
122- watcherTest .WatcherDatabaseAccount , mariadbv1.MariaDBAccountSpec {})
123- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBAccount )
124- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBSecret )
125116 DeferCleanup (th .DeleteInstance , CreateWatcherAPI (watcherTest .WatcherAPI , GetDefaultWatcherAPISpec ()))
126117 DeferCleanup (keystone .DeleteKeystoneAPI , keystone .CreateKeystoneAPI (watcherTest .WatcherAPI .Namespace ))
127118 memcachedSpec := memcachedv1.MemcachedSpec {
@@ -183,18 +174,18 @@ var _ = Describe("WatcherAPI controller", func() {
183174 Expect (container .LivenessProbe .HTTPGet .Port .IntVal ).To (Equal (int32 (9322 )))
184175 Expect (container .ReadinessProbe .HTTPGet .Port .IntVal ).To (Equal (int32 (9322 )))
185176 })
186- It ("creates the public and internal services for the watcher-api service" , func () {
177+ It ("exposes the watcher-api service" , func () {
187178 th .ExpectCondition (
188179 watcherTest .WatcherAPI ,
189180 ConditionGetterFunc (WatcherAPIConditionGetter ),
190- condition .CreateServiceReadyCondition ,
181+ condition .ExposeServiceReadyCondition ,
191182 corev1 .ConditionTrue ,
192183 )
193184 public := th .GetService (watcherTest .WatcherPublicServiceName )
194185 Expect (public .Labels ["service" ]).To (Equal ("watcher-api" ))
195186 internal := th .GetService (watcherTest .WatcherInternalServiceName )
196187 Expect (internal .Labels ["service" ]).To (Equal ("watcher-api" ))
197-
188+ th . AssertRouteExists ( watcherTest . WatcherRouteName )
198189 })
199190 })
200191 When ("the secret is created but missing fields" , func () {
@@ -204,14 +195,6 @@ var _ = Describe("WatcherAPI controller", func() {
204195 map [string ][]byte {},
205196 )
206197 DeferCleanup (k8sClient .Delete , ctx , secret )
207- mariadb .CreateMariaDBDatabase (watcherTest .WatcherDatabaseName .Namespace , watcherTest .WatcherDatabaseName .Name , mariadbv1.MariaDBDatabaseSpec {})
208- DeferCleanup (k8sClient .Delete , ctx , mariadb .GetMariaDBDatabase (watcherTest .WatcherDatabaseName ))
209-
210- mariadb .SimulateMariaDBTLSDatabaseCompleted (watcherTest .WatcherDatabaseName )
211- apiMariaDBAccount , apiMariaDBSecret := mariadb .CreateMariaDBAccountAndSecret (
212- watcherTest .WatcherDatabaseAccount , mariadbv1.MariaDBAccountSpec {})
213- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBAccount )
214- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBSecret )
215198 DeferCleanup (th .DeleteInstance , CreateWatcherAPI (watcherTest .WatcherAPI , GetDefaultWatcherAPISpec ()))
216199 })
217200 It ("should have input false" , func () {
@@ -265,14 +248,7 @@ var _ = Describe("WatcherAPI controller", func() {
265248 },
266249 )
267250 DeferCleanup (k8sClient .Delete , ctx , secret )
268- mariadb .CreateMariaDBDatabase (watcherTest .WatcherDatabaseName .Namespace , watcherTest .WatcherDatabaseName .Name , mariadbv1.MariaDBDatabaseSpec {})
269- DeferCleanup (k8sClient .Delete , ctx , mariadb .GetMariaDBDatabase (watcherTest .WatcherDatabaseName ))
270251
271- mariadb .SimulateMariaDBTLSDatabaseCompleted (watcherTest .WatcherDatabaseName )
272- apiMariaDBAccount , apiMariaDBSecret := mariadb .CreateMariaDBAccountAndSecret (
273- watcherTest .WatcherDatabaseAccount , mariadbv1.MariaDBAccountSpec {})
274- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBAccount )
275- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBSecret )
276252 DeferCleanup (th .DeleteInstance , CreateWatcherAPI (watcherTest .WatcherAPI , GetDefaultWatcherAPISpec ()))
277253 })
278254 It ("should have input ready true" , func () {
@@ -307,14 +283,6 @@ var _ = Describe("WatcherAPI controller", func() {
307283 },
308284 )
309285 DeferCleanup (k8sClient .Delete , ctx , secret )
310- mariadb .CreateMariaDBDatabase (watcherTest .WatcherDatabaseName .Namespace , watcherTest .WatcherDatabaseName .Name , mariadbv1.MariaDBDatabaseSpec {})
311- DeferCleanup (k8sClient .Delete , ctx , mariadb .GetMariaDBDatabase (watcherTest .WatcherDatabaseName ))
312-
313- mariadb .SimulateMariaDBTLSDatabaseCompleted (watcherTest .WatcherDatabaseName )
314- apiMariaDBAccount , apiMariaDBSecret := mariadb .CreateMariaDBAccountAndSecret (
315- watcherTest .WatcherDatabaseAccount , mariadbv1.MariaDBAccountSpec {})
316- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBAccount )
317- DeferCleanup (k8sClient .Delete , ctx , apiMariaDBSecret )
318286 memcachedSpec := memcachedv1.MemcachedSpec {
319287 MemcachedSpecCore : memcachedv1.MemcachedSpecCore {
320288 Replicas : ptr .To (int32 (1 )),
@@ -356,4 +324,67 @@ var _ = Describe("WatcherAPI controller", func() {
356324 )
357325 })
358326 })
327+ When ("WatcherAPI is created with extrenalEndpoints" , func () {
328+ BeforeEach (func () {
329+ secret := th .CreateSecret (
330+ watcherTest .InternalTopLevelSecretName ,
331+ map [string ][]byte {
332+ "WatcherPassword" : []byte ("service-password" ),
333+ "transport_url" : []byte ("url" ),
334+ },
335+ )
336+ DeferCleanup (k8sClient .Delete , ctx , secret )
337+ spec := GetDefaultWatcherAPISpec ()
338+ var externalEndpoints []interface {}
339+ externalEndpoints = append (
340+ externalEndpoints , map [string ]interface {}{
341+ "endpoint" : "internal" ,
342+ "ipAddressPool" : "osp-internalapi" ,
343+ "loadBalancerIPs" : []string {"internal-lb-ip-1" , "internal-lb-ip-2" },
344+ },
345+ )
346+ spec ["externalEndpoints" ] = externalEndpoints
347+ DeferCleanup (th .DeleteInstance , CreateWatcherAPI (watcherTest .WatcherAPI , spec ))
348+ DeferCleanup (keystone .DeleteKeystoneAPI , keystone .CreateKeystoneAPI (watcherTest .WatcherAPI .Namespace ))
349+ memcachedSpec := memcachedv1.MemcachedSpec {
350+ MemcachedSpecCore : memcachedv1.MemcachedSpecCore {
351+ Replicas : ptr .To (int32 (1 )),
352+ },
353+ }
354+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (watcherTest .WatcherAPI .Namespace , MemcachedInstance , memcachedSpec ))
355+ infra .SimulateMemcachedReady (watcherTest .MemcachedNamespace )
356+
357+ })
358+ It ("creates MetalLB service" , func () {
359+ th .SimulateDeploymentReplicaReady (watcherTest .WatcherAPIDeployment )
360+
361+ // As the public endpoint is not mentioned in the ExternalEndpoints
362+ // a generic Service and a Route is created
363+ public := th .GetService (watcherTest .WatcherPublicServiceName )
364+ Expect (public .Annotations ).NotTo (HaveKey ("metallb.universe.tf/address-pool" ))
365+ Expect (public .Annotations ).NotTo (HaveKey ("metallb.universe.tf/allow-shared-ip" ))
366+ Expect (public .Annotations ).NotTo (HaveKey ("metallb.universe.tf/loadBalancerIPs" ))
367+ th .AssertRouteExists (watcherTest .WatcherRouteName )
368+
369+ // As the internal endpoint is configure in ExternalEndpoints it
370+ // does not get a Route but a Service with MetalLB annotations
371+ // instead
372+ internal := th .GetService (watcherTest .WatcherInternalServiceName )
373+ Expect (internal .Annotations ).To (HaveKeyWithValue ("metallb.universe.tf/address-pool" , "osp-internalapi" ))
374+ Expect (internal .Annotations ).To (HaveKeyWithValue ("metallb.universe.tf/allow-shared-ip" , "osp-internalapi" ))
375+ Expect (internal .Annotations ).To (HaveKeyWithValue ("metallb.universe.tf/loadBalancerIPs" , "internal-lb-ip-1,internal-lb-ip-2" ))
376+ th .AssertRouteNotExists (watcherTest .WatcherInternalRouteName )
377+
378+ // simulate that the internal service got a LoadBalancerIP
379+ // assigned
380+ th .SimulateLoadBalancerServiceIP (watcherTest .WatcherInternalServiceName )
381+
382+ th .ExpectCondition (
383+ watcherTest .WatcherAPI ,
384+ ConditionGetterFunc (WatcherAPIConditionGetter ),
385+ condition .ReadyCondition ,
386+ corev1 .ConditionTrue ,
387+ )
388+ })
389+ })
359390})
0 commit comments