Skip to content

Commit 0015cb1

Browse files
vakwetuCursor AI
authored andcommitted
Add region_name support to Placement API config
- Add region_name to [keystone_authtoken] section in placement.conf - Update placementapi_controller.go to pass Region to templateParameters This ensures proper region selection in multi-region deployments for Keystone authentication. Co-Authored-By: Cursor AI <cursor@cursor.com>
1 parent 693e978 commit 0015cb1

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

internal/controller/placementapi_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,7 @@ func (r *PlacementAPIReconciler) generateServiceConfigMaps(
13701370
"KeystonePublicURL": keystonePublicURL,
13711371
"PlacementPassword": string(ospSecret.Data[instance.Spec.PasswordSelectors.Service]),
13721372
"log_file": "/var/log/placement/placement-api.log",
1373+
"Region": keystoneAPI.GetRegion(),
13731374
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
13741375
databaseAccount.Spec.UserName,
13751376
string(dbSecret.Data[mariadbv1.DatabasePasswordSelector]),

templates/placementapi/config/placement.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ user_domain_name = Default
2020
project_name = service
2121
username = {{ .ServiceUser }}
2222
password = {{ .PlacementPassword }}
23+
{{ if (index . "Region") -}}
24+
region_name = {{ .Region }}
25+
{{ end -}}
2326
www_authenticate_uri = {{ .KeystonePublicURL }}
2427
auth_url = {{ .KeystoneInternalURL }}
2528
auth_type = password

test/functional/placementapi_controller_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ var _ = Describe("PlacementAPI controller", func() {
256256
k8sClient.Delete, ctx, CreatePlacementAPISecret(namespace, SecretName))
257257
keystoneAPIName := keystone.CreateKeystoneAPI(namespace)
258258
keystoneAPI = keystone.GetKeystoneAPI(keystoneAPIName)
259+
// Set region on KeystoneAPI to ensure GetRegion() returns a value
260+
Eventually(func(g Gomega) {
261+
ks := keystone.GetKeystoneAPI(keystoneAPIName)
262+
ks.Spec.Region = "RegionOne"
263+
g.Expect(k8sClient.Update(ctx, ks)).To(Succeed())
264+
ks.Status.Region = "RegionOne"
265+
g.Expect(k8sClient.Status().Update(ctx, ks)).To(Succeed())
266+
}, timeout, interval).Should(Succeed())
267+
// Refresh keystoneAPI after setting region
268+
keystoneAPI = keystone.GetKeystoneAPI(keystoneAPIName)
259269
DeferCleanup(keystone.DeleteKeystoneAPI, keystoneAPIName)
260270
})
261271

@@ -349,6 +359,28 @@ var _ = Describe("PlacementAPI controller", func() {
349359
ContainSubstring("TimeOut 60"))
350360
})
351361

362+
It("should set region_name in keystone_authtoken section", func() {
363+
serviceSpec := corev1.ServiceSpec{Ports: []corev1.ServicePort{{Port: 3306}}}
364+
DeferCleanup(
365+
mariadb.DeleteDBService,
366+
mariadb.CreateDBService(namespace, "openstack", serviceSpec),
367+
)
368+
mariadb.SimulateMariaDBDatabaseCompleted(names.MariaDBDatabaseName)
369+
mariadb.SimulateMariaDBAccountCompleted(names.MariaDBAccount)
370+
371+
cm := th.GetSecret(names.ConfigMapName)
372+
conf := string(cm.Data["placement.conf"])
373+
374+
// Verify region_name is set in [keystone_authtoken] section
375+
// GetRegion() returns Status.Region, so check that
376+
Expect(keystoneAPI.Status.Region).ToNot(BeEmpty(), "KeystoneAPI should have a region set in status")
377+
// The region_name should appear in the [keystone_authtoken] section
378+
// It's conditionally rendered, so check it appears between password and www_authenticate_uri
379+
Expect(conf).Should(
380+
MatchRegexp(fmt.Sprintf(
381+
"password = .*\\nregion_name = %s\\n", keystoneAPI.Status.Region)))
382+
})
383+
352384
It("creates service account, role and rolebindig", func() {
353385
serviceSpec := corev1.ServiceSpec{Ports: []corev1.ServicePort{{Port: 3306}}}
354386
DeferCleanup(

0 commit comments

Comments
 (0)