Skip to content

Commit 263997e

Browse files
xekcursoragent
authored andcommitted
Add region_name support to Watcher config
- Add region_name to [keystone_authtoken] and [watcher_clients_auth] sections in 00-default.conf - Update watcherapi_controller.go, watcherapplier_controller.go, and watcherdecisionengine_controller.go to pass Region to templateParameters This ensures proper region selection in multi-region deployments for Keystone authentication. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent add353f commit 263997e

8 files changed

Lines changed: 149 additions & 42 deletions

File tree

internal/controller/watcherapi_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,12 @@ func (r *WatcherAPIReconciler) generateServiceConfigs(
411411
return err
412412
}
413413

414+
// Get region from KeystoneAPI, defaulting to "regionOne" if empty
415+
region := keystoneAPI.GetRegion()
416+
if region == "" {
417+
region = "regionOne"
418+
}
419+
414420
databaseAccount := string(secret.Data[DatabaseAccount])
415421
db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, helper, watcher.DatabaseCRName, databaseAccount, instance.Namespace)
416422
if err != nil {
@@ -454,6 +460,7 @@ func (r *WatcherAPIReconciler) generateServiceConfigs(
454460
watcher.DatabaseName,
455461
),
456462
"KeystoneAuthURL": keystoneInternalURL,
463+
"Region": region,
457464
"ServicePassword": string(secret.Data[*instance.Spec.PasswordSelectors.Service]),
458465
"ServiceUser": *instance.Spec.ServiceUser,
459466
"TransportURL": string(secret.Data[TransportURLSelector]),

internal/controller/watcherapplier_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ func (r *WatcherApplierReconciler) generateServiceConfigs(
387387
return err
388388
}
389389

390+
// Get region from KeystoneAPI, defaulting to "regionOne" if empty
391+
region := keystoneAPI.GetRegion()
392+
if region == "" {
393+
region = "regionOne"
394+
}
395+
390396
databaseAccount := string(secret.Data[DatabaseAccount])
391397
db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, helper, watcher.DatabaseCRName, databaseAccount, instance.Namespace)
392398
if err != nil {
@@ -420,6 +426,7 @@ func (r *WatcherApplierReconciler) generateServiceConfigs(
420426
watcher.DatabaseName,
421427
),
422428
"KeystoneAuthURL": keystoneInternalURL,
429+
"Region": region,
423430
"ServicePassword": string(secret.Data[*instance.Spec.PasswordSelectors.Service]),
424431
"ServiceUser": *instance.Spec.ServiceUser,
425432
"TransportURL": string(secret.Data[TransportURLSelector]),

internal/controller/watcherdecisionengine_controller.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ func (r *WatcherDecisionEngineReconciler) generateServiceConfigs(
526526
return err
527527
}
528528

529+
// Get region from KeystoneAPI, defaulting to "regionOne" if empty
530+
region := keystoneAPI.GetRegion()
531+
if region == "" {
532+
region = "regionOne"
533+
}
534+
529535
databaseAccount := string(secret.Data[DatabaseAccount])
530536
db, err := mariadbv1.GetDatabaseByNameAndAccount(ctx, helper, watcher.DatabaseCRName, databaseAccount, instance.Namespace)
531537
if err != nil {
@@ -568,6 +574,7 @@ func (r *WatcherDecisionEngineReconciler) generateServiceConfigs(
568574
watcher.DatabaseName,
569575
),
570576
"KeystoneAuthURL": keystoneInternalURL,
577+
"Region": region,
571578
"ServicePassword": string(secret.Data[*instance.Spec.PasswordSelectors.Service]),
572579
"ServiceUser": *instance.Spec.ServiceUser,
573580
"TransportURL": string(secret.Data[TransportURLSelector]),

templates/00-default.conf

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ username = {{ .ServiceUser }}
5656
auth_url = {{ .KeystoneAuthURL }}
5757
interface = internal
5858
auth_type = password
59+
region_name = {{ .Region }}
5960
{{ if .CaFilePath }}
6061
cafile = {{ .CaFilePath }}
6162
{{ end }}
@@ -113,26 +114,53 @@ cafile = {{ .PrometheusCaCertPath }}
113114
{{ end }}
114115
{{ end }}
115116

117+
[aetos_client]
118+
endpoint_type = internal
119+
{{- if (index . "Region") }}
120+
region_name = {{ .Region }}
121+
{{- end }}
122+
116123
[cinder_client]
117124
endpoint_type = internal
125+
{{- if (index . "Region") }}
126+
region_name = {{ .Region }}
127+
{{- end }}
118128

119129
[glance_client]
120130
endpoint_type = internal
131+
{{- if (index . "Region") }}
132+
region_name = {{ .Region }}
133+
{{- end }}
121134

122135
[ironic_client]
123136
endpoint_type = internal
137+
{{- if (index . "Region") }}
138+
region_name = {{ .Region }}
139+
{{- end }}
124140

125141
[keystone_client]
126142
interface = internal
143+
{{- if (index . "Region") }}
144+
region_name = {{ .Region }}
145+
{{- end }}
127146

128147
[neutron_client]
129148
endpoint_type = internal
149+
{{- if (index . "Region") }}
150+
region_name = {{ .Region }}
151+
{{- end }}
130152

131153
[nova_client]
132154
endpoint_type = internal
155+
{{- if (index . "Region") }}
156+
region_name = {{ .Region }}
157+
{{- end }}
133158

134159
[placement_client]
135160
interface = internal
161+
{{- if (index . "Region") }}
162+
region_name = {{ .Region }}
163+
{{- end }}
136164

137165
[watcher_cluster_data_model_collectors.compute]
138166
period = 900

test/functional/watcherapi_controller_test.go

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -273,19 +273,26 @@ var _ = Describe("WatcherAPI controller", func() {
273273

274274
expectedSections := []string{`
275275
[cinder_client]
276-
endpoint_type = internal`, `
276+
endpoint_type = internal
277+
region_name = regionOne`, `
277278
[glance_client]
278-
endpoint_type = internal`, `
279+
endpoint_type = internal
280+
region_name = regionOne`, `
279281
[ironic_client]
280-
endpoint_type = internal`, `
282+
endpoint_type = internal
283+
region_name = regionOne`, `
281284
[keystone_client]
282-
interface = internal`, `
285+
interface = internal
286+
region_name = regionOne`, `
283287
[neutron_client]
284-
endpoint_type = internal`, `
288+
endpoint_type = internal
289+
region_name = regionOne`, `
285290
[nova_client]
286-
endpoint_type = internal`, `
291+
endpoint_type = internal
292+
region_name = regionOne`, `
287293
[placement_client]
288-
interface = internal`, `
294+
interface = internal
295+
region_name = regionOne`, `
289296
[watcher_cluster_data_model_collectors.compute]
290297
period = 900`, `
291298
[watcher_cluster_data_model_collectors.baremetal]
@@ -1127,6 +1134,11 @@ transport_url =`
11271134
DeferCleanup(th.DeleteInstance, CreateWatcherAPI(watcherTest.WatcherAPI, GetDefaultWatcherAPISpec()))
11281135
keystoneAPIName = keystone.CreateKeystoneAPI(watcherTest.WatcherAPI.Namespace)
11291136
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
1137+
Eventually(func(g Gomega) {
1138+
ks := keystone.GetKeystoneAPI(keystoneAPIName)
1139+
ks.Status.Region = "regionTwo"
1140+
g.Expect(k8sClient.Status().Update(ctx, ks)).To(Succeed())
1141+
}, timeout, interval).Should(Succeed())
11301142
memcachedSpec := memcachedv1.MemcachedSpec{
11311143
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
11321144
Replicas: ptr.To(int32(1)),
@@ -1168,19 +1180,26 @@ transport_url =`
11681180

11691181
expectedSections := []string{`
11701182
[cinder_client]
1171-
endpoint_type = internal`, `
1183+
endpoint_type = internal
1184+
region_name = regionTwo`, `
11721185
[glance_client]
1173-
endpoint_type = internal`, `
1186+
endpoint_type = internal
1187+
region_name = regionTwo`, `
11741188
[ironic_client]
1175-
endpoint_type = internal`, `
1189+
endpoint_type = internal
1190+
region_name = regionTwo`, `
11761191
[keystone_client]
1177-
interface = internal`, `
1192+
interface = internal
1193+
region_name = regionTwo`, `
11781194
[neutron_client]
1179-
endpoint_type = internal`, `
1195+
endpoint_type = internal
1196+
region_name = regionTwo`, `
11801197
[nova_client]
1181-
endpoint_type = internal`, `
1198+
endpoint_type = internal
1199+
region_name = regionTwo`, `
11821200
[placement_client]
1183-
interface = internal`, `
1201+
interface = internal
1202+
region_name = regionTwo`, `
11841203
[watcher_cluster_data_model_collectors.compute]
11851204
period = 900`, `
11861205
[watcher_cluster_data_model_collectors.baremetal]

test/functional/watcherapplier_controller_test.go

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,26 @@ var _ = Describe("WatcherApplier controller", func() {
197197
// indentaion is forced by use of raw literal
198198
expectedSections := []string{`
199199
[cinder_client]
200-
endpoint_type = internal`, `
200+
endpoint_type = internal
201+
region_name = regionOne`, `
201202
[glance_client]
202-
endpoint_type = internal`, `
203+
endpoint_type = internal
204+
region_name = regionOne`, `
203205
[ironic_client]
204-
endpoint_type = internal`, `
206+
endpoint_type = internal
207+
region_name = regionOne`, `
205208
[keystone_client]
206-
interface = internal`, `
209+
interface = internal
210+
region_name = regionOne`, `
207211
[neutron_client]
208-
endpoint_type = internal`, `
212+
endpoint_type = internal
213+
region_name = regionOne`, `
209214
[nova_client]
210-
endpoint_type = internal`, `
215+
endpoint_type = internal
216+
region_name = regionOne`, `
211217
[placement_client]
212-
interface = internal`, `
218+
interface = internal
219+
region_name = regionOne`, `
213220
[oslo_messaging_notifications]
214221
215222
driver = noop`,
@@ -694,6 +701,11 @@ transport_url =`
694701
mariadb.SimulateMariaDBDatabaseCompleted(watcherTest.WatcherDatabaseName)
695702
keystoneAPIName = keystone.CreateKeystoneAPI(watcherTest.WatcherApplier.Namespace)
696703
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
704+
Eventually(func(g Gomega) {
705+
ks := keystone.GetKeystoneAPI(keystoneAPIName)
706+
ks.Status.Region = "regionTwo"
707+
g.Expect(k8sClient.Status().Update(ctx, ks)).To(Succeed())
708+
}, timeout, interval).Should(Succeed())
697709
memcachedSpec := memcachedv1.MemcachedSpec{
698710
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
699711
Replicas: ptr.To(int32(1)),
@@ -746,19 +758,26 @@ transport_url =`
746758
// indentaion is forced by use of raw literal
747759
expectedSections := []string{`
748760
[cinder_client]
749-
endpoint_type = internal`, `
761+
endpoint_type = internal
762+
region_name = regionTwo`, `
750763
[glance_client]
751-
endpoint_type = internal`, `
764+
endpoint_type = internal
765+
region_name = regionTwo`, `
752766
[ironic_client]
753-
endpoint_type = internal`, `
767+
endpoint_type = internal
768+
region_name = regionTwo`, `
754769
[keystone_client]
755-
interface = internal`, `
770+
interface = internal
771+
region_name = regionTwo`, `
756772
[neutron_client]
757-
endpoint_type = internal`, `
773+
endpoint_type = internal
774+
region_name = regionTwo`, `
758775
[nova_client]
759-
endpoint_type = internal`, `
776+
endpoint_type = internal
777+
region_name = regionTwo`, `
760778
[placement_client]
761-
interface = internal`, `
779+
interface = internal
780+
region_name = regionTwo`, `
762781
[oslo_messaging_notifications]
763782
764783
driver = messagingv2

test/functional/watcherdecisionengine_controller_test.go

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,26 @@ var _ = Describe("WatcherDecisionEngine controller", func() {
207207
// indentaion is forced by use of raw literal
208208
expectedSections := []string{`
209209
[cinder_client]
210-
endpoint_type = internal`, `
210+
endpoint_type = internal
211+
region_name = regionOne`, `
211212
[glance_client]
212-
endpoint_type = internal`, `
213+
endpoint_type = internal
214+
region_name = regionOne`, `
213215
[ironic_client]
214-
endpoint_type = internal`, `
216+
endpoint_type = internal
217+
region_name = regionOne`, `
215218
[keystone_client]
216-
interface = internal`, `
219+
interface = internal
220+
region_name = regionOne`, `
217221
[neutron_client]
218-
endpoint_type = internal`, `
222+
endpoint_type = internal
223+
region_name = regionOne`, `
219224
[nova_client]
220-
endpoint_type = internal`, `
225+
endpoint_type = internal
226+
region_name = regionOne`, `
221227
[placement_client]
222-
interface = internal`, `
228+
interface = internal
229+
region_name = regionOne`, `
223230
[watcher_cluster_data_model_collectors.compute]
224231
period = 900`, `
225232
[watcher_cluster_data_model_collectors.baremetal]
@@ -662,6 +669,11 @@ transport_url =`
662669
mariadb.SimulateMariaDBDatabaseCompleted(watcherTest.WatcherDatabaseName)
663670
keystoneAPIName = keystone.CreateKeystoneAPI(watcherTest.WatcherDecisionEngine.Namespace)
664671
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
672+
Eventually(func(g Gomega) {
673+
ks := keystone.GetKeystoneAPI(keystoneAPIName)
674+
ks.Status.Region = "regionTwo"
675+
g.Expect(k8sClient.Status().Update(ctx, ks)).To(Succeed())
676+
}, timeout, interval).Should(Succeed())
665677
memcachedSpec := memcachedv1.MemcachedSpec{
666678
MemcachedSpecCore: memcachedv1.MemcachedSpecCore{
667679
Replicas: ptr.To(int32(1)),
@@ -715,19 +727,26 @@ transport_url =`
715727
// indentaion is forced by use of raw literal
716728
expectedSections := []string{`
717729
[cinder_client]
718-
endpoint_type = internal`, `
730+
endpoint_type = internal
731+
region_name = regionTwo`, `
719732
[glance_client]
720-
endpoint_type = internal`, `
733+
endpoint_type = internal
734+
region_name = regionTwo`, `
721735
[ironic_client]
722-
endpoint_type = internal`, `
736+
endpoint_type = internal
737+
region_name = regionTwo`, `
723738
[keystone_client]
724-
interface = internal`, `
739+
interface = internal
740+
region_name = regionTwo`, `
725741
[neutron_client]
726-
endpoint_type = internal`, `
742+
endpoint_type = internal
743+
region_name = regionTwo`, `
727744
[nova_client]
728-
endpoint_type = internal`, `
745+
endpoint_type = internal
746+
region_name = regionTwo`, `
729747
[placement_client]
730-
interface = internal`, `
748+
interface = internal
749+
region_name = regionTwo`, `
731750
[watcher_cluster_data_model_collectors.compute]
732751
period = 900`, `
733752
[watcher_cluster_data_model_collectors.baremetal]

test/kuttl/test-suites/default/watcher/01-assert.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ commands:
510510
[ -n "$(oc get -n watcher-kuttl-default watcher watcher-kuttl -o jsonpath={.status.hash.dbsync})" ]
511511
[ "$(oc get -n watcher-kuttl-default secret watcher-kuttl-api-config-data -o jsonpath='{.data.my\.cnf}'|base64 -d|grep -c 'ssl=1')" == 1 ]
512512
[ "$(oc get -n watcher-kuttl-default secret watcher-kuttl-api-config-data -o jsonpath='{.data.00-default\.conf}'|base64 -d|grep -c 'cafile = /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem')" == 2 ]
513+
[ "$(oc get -n watcher-kuttl-default secret watcher-kuttl-api-config-data -o jsonpath='{.data.00-default\.conf}'|base64 -d|grep -c 'region_name = regionOne')" -ge 1 ]
513514
# If we are running the container locally, skip following test
514515
if [ "$(oc get pods -n openstack-operators -o name -l openstack.org/operator-name=watcher)" == "" ]; then
515516
exit 0

0 commit comments

Comments
 (0)