Skip to content

Commit 02f38e6

Browse files
committed
Rabbitmq vhost and user support
Add new notificationsBus interface to hold cluster, user and vhost names for optional usage. The controller adds these values to the TransportURL create request when present. Additionally, we migrate RabbitMQ cluster name to RabbitMq config struct using DefaultRabbitMqConfig from infra-operator to automatically populate the new Cluster field from legacy RabbitMqClusterName. Example usage: spec: notificationsBus: cluster: rabbitmq user: custom-user vhost: custom-vhost Jira: https://issues.redhat.com/browse/OSPRH-23739
1 parent de34ba4 commit 02f38e6

10 files changed

Lines changed: 333 additions & 33 deletions

File tree

‎api/bases/glance.openstack.org_glances.yaml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,25 @@ spec:
16301630
RabbitMQ instance name
16311631
Needed to request a transportURL that is created and used for notification
16321632
purposes
1633+
deprecated: Use NotificationsBus.Cluster instead
16331634
type: string
1635+
notificationsBus:
1636+
description: NotificationsBus configuration (username, vhost, and
1637+
cluster) for notifications
1638+
properties:
1639+
cluster:
1640+
description: Name of the cluster
1641+
minLength: 1
1642+
type: string
1643+
user:
1644+
description: User - RabbitMQ username
1645+
type: string
1646+
vhost:
1647+
description: Vhost - RabbitMQ vhost name
1648+
type: string
1649+
required:
1650+
- cluster
1651+
type: object
16341652
passwordSelectors:
16351653
default:
16361654
service: GlancePassword

‎api/go.mod‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ require (
1717
github.com/cespare/xxhash/v2 v2.3.0 // indirect
1818
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
1919
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
20-
github.com/evanphx/json-patch v5.9.11+incompatible // indirect
2120
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
2221
github.com/fsnotify/fsnotify v1.9.0 // indirect
2322
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
@@ -46,6 +45,7 @@ require (
4645
github.com/prometheus/client_model v0.6.2 // indirect
4746
github.com/prometheus/common v0.65.0 // indirect
4847
github.com/prometheus/procfs v0.16.1 // indirect
48+
github.com/rabbitmq/cluster-operator/v2 v2.16.0 // indirect
4949
github.com/spf13/pflag v1.0.7 // indirect
5050
github.com/stretchr/testify v1.11.1 // indirect
5151
github.com/x448/float16 v0.8.4 // indirect

‎api/go.sum‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
12
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
23
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
34
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
@@ -86,6 +87,8 @@ github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.2026012814
8687
github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260128142552-e2c25eccae5a/go.mod h1:ndqfy1KbVorHH6+zlUFPIrCRhMSxO3ImYJUGaooE0x0=
8788
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20260128142552-e2c25eccae5a h1:teKxfVLDxJD9ahjeh29GlKHiXNUFDkVRmkpJdeKAvGE=
8889
github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20260128142552-e2c25eccae5a/go.mod h1:jofj+VqDszxLCZSBYo794KGkCjMo01xzhQ/gffYzf3I=
90+
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec h1:saovr368HPAKHN0aRPh8h8n9s9dn3d8Frmfua0UYRlc=
91+
github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec/go.mod h1:Nh2NEePLjovUQof2krTAg4JaAoLacqtPTZQXK6izNfg=
8992
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
9093
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9194
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=

‎api/v1beta1/glance_types.go‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1"
21+
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2022
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2123
"github.com/openstack-k8s-operators/lib-common/modules/storage"
22-
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2425
)
2526

@@ -138,7 +139,12 @@ type GlanceSpecCore struct {
138139
// RabbitMQ instance name
139140
// Needed to request a transportURL that is created and used for notification
140141
// purposes
141-
NotificationBusInstance *string `json:"notificationBusInstance,omitempty"`
142+
// deprecated: Use NotificationsBus.Cluster instead
143+
NotificationBusInstance *string `json:"notificationBusInstance,omitempty" deprecated:"NotificationsBus.Cluster"`
144+
145+
// +kubebuilder:validation:Optional
146+
// NotificationsBus configuration (username, vhost, and cluster) for notifications
147+
NotificationsBus *rabbitmqv1.RabbitMqConfig `json:"notificationsBus,omitempty"`
142148
}
143149

144150
// GlanceSpec defines the desired state of Glance

‎api/v1beta1/glance_webhook.go‎

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1"
2525
"github.com/openstack-k8s-operators/lib-common/modules/common/service"
26+
common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
2627
apierrors "k8s.io/apimachinery/pkg/api/errors"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
"k8s.io/apimachinery/pkg/runtime/schema"
2930
"k8s.io/apimachinery/pkg/util/validation/field"
3031
logf "sigs.k8s.io/controller-runtime/pkg/log"
3132
"sigs.k8s.io/controller-runtime/pkg/webhook"
3233
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
33-
34-
common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook"
3534
)
3635

3736
// GlanceDefaults -
@@ -114,6 +113,10 @@ func (r *GlanceSpecCore) Default() {
114113
if r.DBPurge.Schedule == "" {
115114
r.DBPurge.Schedule = glanceDefaults.DBPurgeSchedule
116115
}
116+
117+
// NotificationsBus.Cluster is not defaulted - it must be explicitly set if NotificationsBus is configured
118+
// Migration from deprecated fields is handled by openstack-operator
119+
// This ensures users make a conscious choice about which cluster to use for notifications
117120
// When no glanceAPI(s) are specified in the top-level CR
118121
// we build one by default, but we set replicas=0 and we
119122
// build a "CustomServiceConfig" template that should be
@@ -202,12 +205,64 @@ func (r *GlanceSpecCore) isInvalidBackend(glanceAPI GlanceAPITemplate, topLevel
202205
return false, ""
203206
}
204207

208+
// getDeprecatedFields returns the centralized list of deprecated fields for GlanceSpecCore
209+
func (spec *GlanceSpecCore) getDeprecatedFields(old *GlanceSpecCore) []common_webhook.DeprecatedFieldUpdate {
210+
// Get new field value (handle nil NotificationsBus)
211+
var newNotifBusCluster *string
212+
if spec.NotificationsBus != nil {
213+
newNotifBusCluster = &spec.NotificationsBus.Cluster
214+
}
215+
216+
deprecatedFields := []common_webhook.DeprecatedFieldUpdate{
217+
{
218+
DeprecatedFieldName: "notificationBusInstance",
219+
NewFieldPath: []string{"notificationsBus", "cluster"},
220+
NewDeprecatedValue: spec.NotificationBusInstance,
221+
NewValue: newNotifBusCluster,
222+
},
223+
}
224+
225+
// If old spec is provided (UPDATE operation), add old values
226+
if old != nil {
227+
deprecatedFields[0].OldDeprecatedValue = old.NotificationBusInstance
228+
}
229+
230+
return deprecatedFields
231+
}
232+
233+
// validateDeprecatedFieldsCreate validates deprecated fields during CREATE operations
234+
func (spec *GlanceSpecCore) validateDeprecatedFieldsCreate(basePath *field.Path) ([]string, field.ErrorList) {
235+
// Get deprecated fields list (without old values for CREATE)
236+
deprecatedFieldsUpdate := spec.getDeprecatedFields(nil)
237+
238+
// Convert to DeprecatedField list for CREATE validation
239+
deprecatedFields := make([]common_webhook.DeprecatedField, len(deprecatedFieldsUpdate))
240+
for i, df := range deprecatedFieldsUpdate {
241+
deprecatedFields[i] = common_webhook.DeprecatedField{
242+
DeprecatedFieldName: df.DeprecatedFieldName,
243+
NewFieldPath: df.NewFieldPath,
244+
DeprecatedValue: df.NewDeprecatedValue,
245+
NewValue: df.NewValue,
246+
}
247+
}
248+
249+
return common_webhook.ValidateDeprecatedFieldsCreate(deprecatedFields, basePath), nil
250+
}
251+
252+
// validateDeprecatedFieldsUpdate validates deprecated fields during UPDATE operations
253+
func (spec *GlanceSpecCore) validateDeprecatedFieldsUpdate(old GlanceSpecCore, basePath *field.Path) ([]string, field.ErrorList) {
254+
// Get deprecated fields list with old values
255+
deprecatedFields := spec.getDeprecatedFields(&old)
256+
return common_webhook.ValidateDeprecatedFieldsUpdate(deprecatedFields, basePath)
257+
}
258+
205259
var _ webhook.Validator = &Glance{}
206260

207261
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
208262
func (r *Glance) ValidateCreate() (admission.Warnings, error) {
209263
glancelog.Info("validate create", "name", r.Name)
210264
var allErrs field.ErrorList
265+
var allWarns []string
211266
basePath := field.NewPath("spec")
212267

213268
for key, glanceAPI := range r.Spec.GlanceAPIs {
@@ -229,28 +284,34 @@ func (r *Glance) ValidateCreate() (admission.Warnings, error) {
229284
allErrs = append(allErrs, err...)
230285
}
231286

232-
if err := r.Spec.ValidateCreate(basePath, r.Namespace); err != nil {
233-
allErrs = append(allErrs, err...)
234-
}
287+
warns, errs := r.Spec.ValidateCreate(basePath, r.Namespace)
288+
allWarns = append(allWarns, warns...)
289+
allErrs = append(allErrs, errs...)
235290

236291
if len(allErrs) != 0 {
237-
return nil, apierrors.NewInvalid(
292+
return allWarns, apierrors.NewInvalid(
238293
schema.GroupKind{Group: "glance.openstack.org", Kind: "Glance"},
239294
r.Name, allErrs)
240295
}
241296

242-
return nil, nil
297+
return allWarns, nil
243298
}
244299

245300
// ValidateCreate - Exported function wrapping non-exported validate functions,
246301
// this function can be called externally to validate an ironic spec.
247-
func (r *GlanceSpec) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList {
302+
func (r *GlanceSpec) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) {
248303
return r.GlanceSpecCore.ValidateCreate(basePath, namespace)
249304
}
250305

251306
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
252-
func (r *GlanceSpecCore) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList {
307+
func (r *GlanceSpecCore) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) {
253308
var allErrs field.ErrorList
309+
var allWarns []string
310+
311+
// Validate deprecated fields using shared helper
312+
warns, errs := r.validateDeprecatedFieldsCreate(basePath)
313+
allWarns = append(allWarns, warns...)
314+
allErrs = append(allErrs, errs...)
254315

255316
// Check if the top-level CR has a "customServiceConfig" with an explicit
256317
// "backend:file || empty string" and save the result into topLevel var.
@@ -293,7 +354,7 @@ func (r *GlanceSpecCore) ValidateCreate(basePath *field.Path, namespace string)
293354
path, r.KeystoneEndpoint, KeystoneEndpointErrorMessage))
294355
}
295356

296-
return allErrs
357+
return allWarns, allErrs
297358
}
298359

299360
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
@@ -305,6 +366,7 @@ func (r *Glance) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
305366
glancelog.Info("validate update", "diff", cmp.Diff(old, r))
306367

307368
var allErrs field.ErrorList
369+
var allWarns []string
308370
basePath := field.NewPath("spec")
309371

310372
for key, glanceAPI := range r.Spec.GlanceAPIs {
@@ -326,28 +388,34 @@ func (r *Glance) ValidateUpdate(old runtime.Object) (admission.Warnings, error)
326388
allErrs = append(allErrs, err...)
327389
}
328390

329-
if err := r.Spec.ValidateUpdate(o.Spec, basePath, r.Namespace); err != nil {
330-
allErrs = append(allErrs, err...)
331-
}
391+
warns, errs := r.Spec.ValidateUpdate(o.Spec, basePath, r.Namespace)
392+
allWarns = append(allWarns, warns...)
393+
allErrs = append(allErrs, errs...)
332394

333395
if len(allErrs) != 0 {
334-
return nil, apierrors.NewInvalid(
396+
return allWarns, apierrors.NewInvalid(
335397
schema.GroupKind{Group: "glance.openstack.org", Kind: "Glance"},
336398
r.Name, allErrs)
337399
}
338400

339-
return nil, nil
401+
return allWarns, nil
340402
}
341403

342404
// ValidateUpdate - Exported function wrapping non-exported validate functions,
343405
// this function can be called externally to validate an glance spec.
344-
func (r *GlanceSpec) ValidateUpdate(old GlanceSpec, basePath *field.Path, namespace string) field.ErrorList {
406+
func (r *GlanceSpec) ValidateUpdate(old GlanceSpec, basePath *field.Path, namespace string) ([]string, field.ErrorList) {
345407
return r.GlanceSpecCore.ValidateUpdate(old.GlanceSpecCore, basePath, namespace)
346408
}
347409

348410
// ValidateUpdate -
349-
func (r *GlanceSpecCore) ValidateUpdate(old GlanceSpecCore, basePath *field.Path, namespace string) field.ErrorList {
411+
func (r *GlanceSpecCore) ValidateUpdate(old GlanceSpecCore, basePath *field.Path, namespace string) ([]string, field.ErrorList) {
350412
var allErrs field.ErrorList
413+
var allWarns []string
414+
415+
// Validate deprecated fields using shared helper
416+
warns, errs := r.validateDeprecatedFieldsUpdate(old, basePath)
417+
allWarns = append(allWarns, warns...)
418+
allErrs = append(allErrs, errs...)
351419

352420
// fail if a wrong topology is referenced
353421
allErrs = append(allErrs, topologyv1.ValidateTopologyRef(
@@ -399,7 +467,7 @@ func (r *GlanceSpecCore) ValidateUpdate(old GlanceSpecCore, basePath *field.Path
399467
path, r.KeystoneEndpoint, KeystoneEndpointErrorMessage))
400468
}
401469

402-
return allErrs
470+
return allWarns, allErrs
403471
}
404472

405473
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type

‎api/v1beta1/zz_generated.deepcopy.go‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎config/crd/bases/glance.openstack.org_glances.yaml‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,25 @@ spec:
16301630
RabbitMQ instance name
16311631
Needed to request a transportURL that is created and used for notification
16321632
purposes
1633+
deprecated: Use NotificationsBus.Cluster instead
16331634
type: string
1635+
notificationsBus:
1636+
description: NotificationsBus configuration (username, vhost, and
1637+
cluster) for notifications
1638+
properties:
1639+
cluster:
1640+
description: Name of the cluster
1641+
minLength: 1
1642+
type: string
1643+
user:
1644+
description: User - RabbitMQ username
1645+
type: string
1646+
vhost:
1647+
description: Vhost - RabbitMQ vhost name
1648+
type: string
1649+
required:
1650+
- cluster
1651+
type: object
16341652
passwordSelectors:
16351653
default:
16361654
service: GlancePassword

0 commit comments

Comments
 (0)