@@ -1133,4 +1133,124 @@ heartbeat_in_pthread=false`,
11331133 }, timeout , interval ).Should (Succeed ())
11341134 })
11351135 })
1136+ When ("WatcherDecisionEngine is reconfigured" , func () {
1137+ cinderEndpoint := types.NamespacedName {}
1138+ BeforeEach (func () {
1139+ secret := CreateInternalTopLevelSecret ()
1140+ DeferCleanup (k8sClient .Delete , ctx , secret )
1141+ prometheusSecret := th .CreateSecret (
1142+ watcherTest .PrometheusSecretName ,
1143+ map [string ][]byte {
1144+ "host" : []byte ("prometheus.example.com" ),
1145+ "port" : []byte ("9090" ),
1146+ },
1147+ )
1148+ DeferCleanup (k8sClient .Delete , ctx , prometheusSecret )
1149+ DeferCleanup (
1150+ mariadb .DeleteDBService ,
1151+ mariadb .CreateDBService (
1152+ watcherTest .WatcherDecisionEngine .Namespace ,
1153+ "openstack" ,
1154+ corev1.ServiceSpec {
1155+ Ports : []corev1.ServicePort {{Port : 3306 }},
1156+ },
1157+ ),
1158+ )
1159+ mariadb .CreateMariaDBAccountAndSecret (
1160+ watcherTest .WatcherDatabaseAccount ,
1161+ mariadbv1.MariaDBAccountSpec {
1162+ UserName : "watcher" ,
1163+ },
1164+ )
1165+ mariadb .CreateMariaDBDatabase (
1166+ watcherTest .WatcherDecisionEngine .Namespace ,
1167+ "watcher" ,
1168+ mariadbv1.MariaDBDatabaseSpec {
1169+ Name : "watcher" ,
1170+ },
1171+ )
1172+ mariadb .SimulateMariaDBAccountCompleted (watcherTest .WatcherDatabaseAccount )
1173+ mariadb .SimulateMariaDBDatabaseCompleted (watcherTest .WatcherDatabaseName )
1174+
1175+ DeferCleanup (keystone .DeleteKeystoneAPI , keystone .CreateKeystoneAPI (watcherTest .WatcherDecisionEngine .Namespace ))
1176+
1177+ memcachedSpec := memcachedv1.MemcachedSpec {
1178+ MemcachedSpecCore : memcachedv1.MemcachedSpecCore {
1179+ Replicas : ptr .To (int32 (1 )),
1180+ },
1181+ }
1182+ DeferCleanup (infra .DeleteMemcached , infra .CreateMemcached (watcherTest .WatcherDecisionEngine .Namespace , MemcachedInstance , memcachedSpec ))
1183+ infra .SimulateMemcachedReady (watcherTest .MemcachedNamespace )
1184+
1185+ DeferCleanup (th .DeleteInstance , CreateWatcherDecisionEngine (watcherTest .WatcherDecisionEngine , GetDefaultWatcherDecisionEngineSpec ()))
1186+ // create watcher applier and watcher api to later check that their observed generation has not changed
1187+ DeferCleanup (th .DeleteInstance , CreateWatcherApplier (watcherTest .WatcherApplier , GetDefaultWatcherApplierSpec ()))
1188+ DeferCleanup (th .DeleteInstance , CreateWatcherAPI (watcherTest .WatcherAPI , GetDefaultWatcherAPISpec ()))
1189+
1190+ logger .Info ("Created cinder endpoint" )
1191+ cinderEndpoint = types.NamespacedName {Name : "cinder" , Namespace : watcherTest .WatcherDecisionEngine .Namespace }
1192+ DeferCleanup (keystone .DeleteKeystoneEndpoint , keystone .CreateKeystoneEndpoint (cinderEndpoint ))
1193+ keystone .SimulateKeystoneEndpointReady (cinderEndpoint )
1194+
1195+ th .SimulateStatefulSetReplicaReady (watcherTest .WatcherDecisionEngineStatefulSet )
1196+ th .SimulateStatefulSetReplicaReady (watcherTest .WatcherApplierStatefulSet )
1197+ th .SimulateStatefulSetReplicaReady (watcherTest .WatcherAPIStatefulSet )
1198+
1199+ th .ExpectCondition (
1200+ watcherTest .WatcherDecisionEngine ,
1201+ ConditionGetterFunc (WatcherDecisionEngineConditionGetter ),
1202+ condition .ReadyCondition ,
1203+ corev1 .ConditionTrue ,
1204+ )
1205+
1206+ })
1207+ It ("updates the deployment if cinder public endpoint gets deleted" , func () {
1208+ originalConfigHash := GetEnvVarValue (
1209+ th .GetStatefulSet (watcherTest .WatcherDecisionEngine ).Spec .Template .Spec .Containers [0 ].Env , "CONFIG_HASH" , "" )
1210+ Expect (originalConfigHash ).NotTo (Equal ("" ))
1211+ decisionEngineObservedOrig := th .GetStatefulSet (watcherTest .WatcherDecisionEngine ).Status .ObservedGeneration
1212+ applierObservedOrig := th .GetStatefulSet (watcherTest .WatcherApplier ).Status .ObservedGeneration
1213+ apiObservedOrig := th .GetStatefulSet (watcherTest .WatcherAPI ).Status .ObservedGeneration
1214+
1215+ keystone .DeleteKeystoneEndpoint (cinderEndpoint )
1216+ logger .Info ("Deleted cinder endpoint" )
1217+ // Assert that the CONFIG_HASH of the StateFulSet is changed due to this reconfiguration
1218+ Eventually (func (g Gomega ) {
1219+ currentConfigHash := GetEnvVarValue (
1220+ th .GetStatefulSet (watcherTest .WatcherDecisionEngine ).Spec .Template .Spec .Containers [0 ].Env , "CONFIG_HASH" , "" )
1221+ g .Expect (originalConfigHash ).NotTo (Equal (currentConfigHash ))
1222+
1223+ }, timeout , interval ).Should (Succeed ())
1224+
1225+ // Simulate the StatefulSet replicas to be ready after deleting cinder
1226+ th .SimulateStatefulSetReplicaReady (watcherTest .WatcherDecisionEngineStatefulSet )
1227+ th .SimulateStatefulSetReplicaReady (watcherTest .WatcherApplierStatefulSet )
1228+ th .SimulateStatefulSetReplicaReady (watcherTest .WatcherAPIStatefulSet )
1229+
1230+ // check that the StatefulSet replica watcher-decision-engine is updated while watcher-applier and watcher-api are not updated
1231+ applierObservedNew := th .GetStatefulSet (watcherTest .WatcherApplier ).Status .ObservedGeneration
1232+ Expect (applierObservedNew ).Should (Equal (applierObservedOrig ))
1233+ apiObservedNew := th .GetStatefulSet (watcherTest .WatcherAPI ).Status .ObservedGeneration
1234+ Expect (apiObservedNew ).Should (Equal (apiObservedOrig ))
1235+ decisionEngineObservedNew := th .GetStatefulSet (watcherTest .WatcherDecisionEngine ).Status .ObservedGeneration
1236+ Expect (decisionEngineObservedNew ).Should (Equal (decisionEngineObservedOrig + 1 ))
1237+
1238+ })
1239+ It ("updates the deployment if cinder internal endpoint is modified" , func () {
1240+ originalConfigHash := GetEnvVarValue (
1241+ th .GetStatefulSet (watcherTest .WatcherDecisionEngine ).Spec .Template .Spec .Containers [0 ].Env , "CONFIG_HASH" , "" )
1242+ Expect (originalConfigHash ).NotTo (Equal ("" ))
1243+
1244+ keystone .UpdateKeystoneEndpoint (cinderEndpoint , "internal" , "https://cinder-test-internal" )
1245+ logger .Info ("Reconfigured" )
1246+
1247+ // Assert that the CONFIG_HASH of the StateFulSet is changed due to this reconfiguration
1248+ Eventually (func (g Gomega ) {
1249+ currentConfigHash := GetEnvVarValue (
1250+ th .GetStatefulSet (watcherTest .WatcherDecisionEngine ).Spec .Template .Spec .Containers [0 ].Env , "CONFIG_HASH" , "" )
1251+ g .Expect (originalConfigHash ).NotTo (Equal (currentConfigHash ))
1252+
1253+ }, timeout , interval ).Should (Succeed ())
1254+ })
1255+ })
11361256})
0 commit comments