Skip to content

Commit 4701df0

Browse files
committed
Watch for keystone-overrides
This patch implements a watcher over keystone-overrides secrets based on a particular labelSelector. By doing this it is possible to extract and process keystone parameters (auth_url, www_authenticate_uri, region) and override the default information. Signed-off-by: Francesco Pantano <[email protected]>
1 parent d469e6b commit 4701df0

File tree

7 files changed

+80
-10
lines changed

7 files changed

+80
-10
lines changed

api/go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ require (
7171
// mschuppert: map to latest commit from release-4.16 tag
7272
// must consistent within modules and service operators
7373
replace github.com/openshift/api => github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 //allow-merging
74+
75+
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/fmount/keystone-operator/api v0.0.0-20250911131155-943583d54a0f
76+
77+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20250911113320-38e70af6eeb4

api/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
1212
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
1313
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
1414
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
15+
github.com/fmount/lib-common/modules/common v0.0.0-20250911113320-38e70af6eeb4 h1:QwZdXf9dAuvvN1eOGnzPtUtROv4R0pfuWxZOtdqBDQE=
16+
github.com/fmount/lib-common/modules/common v0.0.0-20250911113320-38e70af6eeb4/go.mod h1:Z+rmtn3qhuPZfx2EDVmloUh2MkYbvDMgcpJneRYerS0=
1517
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1618
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
1719
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
@@ -77,8 +79,6 @@ github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094 h1:J1wuGhVxpsHykZBa6
7779
github.com/openshift/api v0.0.0-20240830023148-b7d0481c9094/go.mod h1:CxgbWAlvu2iQB0UmKTtRu1YfepRg1/vJ64n2DlIEVz4=
7880
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250909143828-e33d35ffd64f h1:chuu4iBT5sXHYw8aPeP/pWC+S3yGo6hdy39foP7c5vs=
7981
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250909143828-e33d35ffd64f/go.mod h1:Dv8qpmBIQy3Jv/EyQnOyc0w61X8vyfxpjcIQONP5CwY=
80-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03 h1:9VanDdvg1APf9B1nzGElLvWr6dM5GsSayMLSV/nJZnE=
81-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03/go.mod h1:Z+rmtn3qhuPZfx2EDVmloUh2MkYbvDMgcpJneRYerS0=
8282
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250823121217-7e1cd2e3dd03 h1:DrKbzsweRx8VBNb5ur+/XcHSi+MR3VdzCsIEXYGc5SM=
8383
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250823121217-7e1cd2e3dd03/go.mod h1:U3LQ4Nz2+syTPfW66bSLv6OzefLpsqxWLdX9AFotRPA=
8484
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=

controllers/glance_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (r *GlanceReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manage
269269
// TransportURL created and used by Glance CRs.
270270
transportURLSecretFn := func(_ context.Context, o client.Object) []reconcile.Request {
271271
result := []reconcile.Request{}
272-
// get all Manila CRs
272+
// get all Glance CRs
273273
glances := &glancev1.GlanceList{}
274274
listOpts := []client.ListOption{
275275
client.InNamespace(o.GetNamespace()),

controllers/glanceapi_controller.go

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,39 @@ func (r *GlanceAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
377377
return nil
378378
}
379379

380+
keystoneOverrideSecretFn := func(_ context.Context, o client.Object) []reconcile.Request {
381+
secret := o.(*corev1.Secret)
382+
result := []reconcile.Request{}
383+
// get all GlanceAPI CRs
384+
glances := &glancev1.GlanceAPIList{}
385+
listOpts := []client.ListOption{
386+
client.InNamespace(o.GetNamespace()),
387+
}
388+
if err := r.Client.List(context.Background(), glances, listOpts...); err != nil {
389+
Log.Error(err, "Unable to retrieve GlanceAPI CRs %v")
390+
return nil
391+
}
392+
// Check if the secret has a specific label
393+
if ls := secret.GetLabels(); ls != nil {
394+
lSelector := labels.GetLabelSelector(ls)
395+
kSelector := labels.GetLabelSelector(keystonev1.KeystoneOverridesLabelSelector)
396+
if labels.EqualLabelSelectors(lSelector, kSelector) {
397+
for _, cr := range glances.Items {
398+
name := client.ObjectKey{
399+
Namespace: o.GetNamespace(),
400+
Name: cr.Name,
401+
}
402+
// append the request for this particular glance instance
403+
result = append(result, reconcile.Request{NamespacedName: name})
404+
}
405+
}
406+
}
407+
if len(result) > 0 {
408+
return result
409+
}
410+
return nil
411+
}
412+
380413
return ctrl.NewControllerManagedBy(mgr).
381414
For(&glancev1.GlanceAPI{}).
382415
Owns(&keystonev1.KeystoneEndpoint{}).
@@ -385,6 +418,8 @@ func (r *GlanceAPIReconciler) SetupWithManager(ctx context.Context, mgr ctrl.Man
385418
Owns(&appsv1.StatefulSet{}).
386419
Watches(&corev1.Secret{},
387420
handler.EnqueueRequestsFromMapFunc(svcSecretFn)).
421+
Watches(&corev1.Secret{},
422+
handler.EnqueueRequestsFromMapFunc(keystoneOverrideSecretFn)).
388423
Watches(&networkv1.NetworkAttachmentDefinition{},
389424
handler.EnqueueRequestsFromMapFunc(nadFn)).
390425
Watches(
@@ -1188,6 +1223,30 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
11881223
return err
11891224
}
11901225

1226+
// Collect all keystone information required to render the config templates
1227+
// in a dedicated structure.
1228+
keystoneData := map[string]string{
1229+
"www_authenticate_uri": keystonePublicURL,
1230+
"auth_url": keystoneInternalURL,
1231+
"region": keystoneAPI.GetRegion(),
1232+
}
1233+
1234+
// Get keystoneOverrides
1235+
keystoneOverrides, err := keystonev1.GetKeystoneOverrides(
1236+
ctx,
1237+
h,
1238+
instance.Namespace,
1239+
keystonev1.KeystoneOverridesLabelSelector,
1240+
)
1241+
if err != nil {
1242+
return err
1243+
}
1244+
1245+
// Merge overrides into keystoneData
1246+
for k, v := range keystoneOverrides {
1247+
keystoneData[k] = v
1248+
}
1249+
11911250
ospSecret, _, err := secret.GetSecret(ctx, h, instance.Spec.Secret, instance.Namespace)
11921251
if err != nil {
11931252
return err
@@ -1224,8 +1283,9 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
12241283
templateParameters := map[string]interface{}{
12251284
"ServiceUser": instance.Spec.ServiceUser,
12261285
"ServicePassword": string(ospSecret.Data[instance.Spec.PasswordSelectors.Service]),
1227-
"KeystoneInternalURL": keystoneInternalURL,
1228-
"KeystonePublicURL": keystonePublicURL,
1286+
"KeystoneInternalURL": keystoneData["auth_url"],
1287+
"KeystonePublicURL": keystoneData["www_authenticate_uri"],
1288+
"Region": keystoneData["region"],
12291289
"DatabaseConnection": fmt.Sprintf("mysql+pymysql://%s:%s@%s/%s?read_default_file=/etc/my.cnf",
12301290
databaseAccount.Spec.UserName,
12311291
string(dbSecret.Data[mariadbv1.DatabasePasswordSelector]),
@@ -1247,7 +1307,6 @@ func (r *GlanceAPIReconciler) generateServiceConfig(
12471307
// .Status.
12481308
if len(endpointID) > 0 {
12491309
templateParameters["EndpointID"] = endpointID
1250-
templateParameters["Region"] = keystoneAPI.GetRegion()
12511310
}
12521311

12531312
// Configure the internal GlanceAPI to provide image location data, and the

go.mod

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,7 @@ replace github.com/openshift/api => github.com/openshift/api v0.0.0-202408300231
9494

9595
// custom RabbitmqClusterSpecCore for OpenStackControlplane (v2.6.0_patches_tag)
9696
replace github.com/rabbitmq/cluster-operator/v2 => github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250717122149-12f70b7f3d8d //allow-merging
97+
98+
replace github.com/openstack-k8s-operators/keystone-operator/api => github.com/fmount/keystone-operator/api v0.0.0-20250911131155-943583d54a0f
99+
100+
replace github.com/openstack-k8s-operators/lib-common/modules/common => github.com/fmount/lib-common/modules/common v0.0.0-20250911113320-38e70af6eeb4

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ github.com/evanphx/json-patch v5.7.0+incompatible h1:vgGkfT/9f8zE6tvSCe74nfpAVDQ
1212
github.com/evanphx/json-patch v5.7.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
1313
github.com/evanphx/json-patch/v5 v5.9.0 h1:kcBlZQbplgElYIlo/n1hJbls2z/1awpXxpRi0/FOJfg=
1414
github.com/evanphx/json-patch/v5 v5.9.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
15+
github.com/fmount/keystone-operator/api v0.0.0-20250911131155-943583d54a0f h1:sKYnDezUOIJUPXSsF8zhqZDQbRBucW4fBMeY504v+0w=
16+
github.com/fmount/keystone-operator/api v0.0.0-20250911131155-943583d54a0f/go.mod h1:G6BkoPfgALryMlOZwIH036iSWUMiDJQAYL1lXuLyPZ0=
17+
github.com/fmount/lib-common/modules/common v0.0.0-20250911113320-38e70af6eeb4 h1:QwZdXf9dAuvvN1eOGnzPtUtROv4R0pfuWxZOtdqBDQE=
18+
github.com/fmount/lib-common/modules/common v0.0.0-20250911113320-38e70af6eeb4/go.mod h1:Z+rmtn3qhuPZfx2EDVmloUh2MkYbvDMgcpJneRYerS0=
1519
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
1620
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
1721
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
@@ -84,10 +88,6 @@ github.com/openstack-k8s-operators/horizon-operator/api v0.6.1-0.20250902143657-
8488
github.com/openstack-k8s-operators/horizon-operator/api v0.6.1-0.20250902143657-1a0c8d38827e/go.mod h1:j9yGw80eA38kEvHEkx/BONqIhLnKFmpjAtyAB8S817E=
8589
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250909143828-e33d35ffd64f h1:chuu4iBT5sXHYw8aPeP/pWC+S3yGo6hdy39foP7c5vs=
8690
github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20250909143828-e33d35ffd64f/go.mod h1:Dv8qpmBIQy3Jv/EyQnOyc0w61X8vyfxpjcIQONP5CwY=
87-
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250905083405-40d18a7ca650 h1:n1s6jr8GJ6cn/1tjLVGPkTURb4ooHwjdS5YeppKdB0g=
88-
github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20250905083405-40d18a7ca650/go.mod h1:G6BkoPfgALryMlOZwIH036iSWUMiDJQAYL1lXuLyPZ0=
89-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03 h1:9VanDdvg1APf9B1nzGElLvWr6dM5GsSayMLSV/nJZnE=
90-
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20250823121217-7e1cd2e3dd03/go.mod h1:Z+rmtn3qhuPZfx2EDVmloUh2MkYbvDMgcpJneRYerS0=
9191
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250823121217-7e1cd2e3dd03 h1:tSMLVApQ4j4YJ56TGIYzaNo2Zh/ruDAY0wCcOEVKoIQ=
9292
github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20250823121217-7e1cd2e3dd03/go.mod h1:nachFP0Yicw/e8ZlqZzvnBN6w9kjMcnqrhaDw36PGjw=
9393
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20250823121217-7e1cd2e3dd03 h1:DrKbzsweRx8VBNb5ur+/XcHSi+MR3VdzCsIEXYGc5SM=

templates/common/config/00-config.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ memcache_tls_enabled = true
5858
project_domain_name=Default
5959
user_domain_name=Default
6060
project_name=service
61+
{{ if (index . "Region") -}}
62+
region_name = {{ .Region }}
63+
{{ end -}}
6164

6265
[service_user]
6366
password = {{ .ServicePassword }}

0 commit comments

Comments
 (0)