Skip to content

Commit c14431f

Browse files
Merge pull request #1591 from fmount/notif
Add NotificationsBusInstance API field
2 parents bc7b4e2 + 9b9ffa9 commit c14431f

File tree

14 files changed

+408
-61
lines changed

14 files changed

+408
-61
lines changed

apis/bases/core.openstack.org_openstackcontrolplanes.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9855,6 +9855,8 @@ spec:
98559855
additionalProperties:
98569856
type: string
98579857
type: object
9858+
notificationsBusInstance:
9859+
type: string
98589860
nova:
98599861
properties:
98609862
apiOverride:

apis/core/v1beta1/openstackcontrolplane_types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ type OpenStackControlPlaneSpec struct {
127127
// Rabbitmq - Parameters related to the Rabbitmq service
128128
Rabbitmq RabbitmqSection `json:"rabbitmq,omitempty"`
129129

130+
// +kubebuilder:validation:Optional
131+
// NotificationsBusInstance - the name of RabbitMQ Cluster CR to select a Messaging
132+
// Bus Service instance used by all services that produce or consume notifications.
133+
// Avoid colocating it with RabbitMQ services used for PRC.
134+
// That instance will be pushed down for services, unless overriden in templates.
135+
NotificationsBusInstance *string `json:"notificationsBusInstance,omitempty"`
136+
130137
// +kubebuilder:validation:Optional
131138
// +operator-sdk:csv:customresourcedefinitions:type=spec
132139
// Memcached - Parameters related to the Memcached service

apis/core/v1beta1/openstackcontrolplane_webhook.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ func (r *OpenStackControlPlane) ValidateCreate() (admission.Warnings, error) {
132132
allErrs = append(allErrs, err)
133133
}
134134

135+
if err := r.ValidateNotificationsBusInstance(basePath); err != nil {
136+
allErrs = append(allErrs, err)
137+
}
138+
135139
if len(allErrs) != 0 {
136140
return allWarn, apierrors.NewInvalid(
137141
schema.GroupKind{Group: "core.openstack.org", Kind: "OpenStackControlPlane"},
@@ -161,6 +165,10 @@ func (r *OpenStackControlPlane) ValidateUpdate(old runtime.Object) (admission.Wa
161165
allErrs = append(allErrs, err)
162166
}
163167

168+
if err := r.ValidateNotificationsBusInstance(basePath); err != nil {
169+
allErrs = append(allErrs, err)
170+
}
171+
164172
if len(allErrs) != 0 {
165173
return nil, apierrors.NewInvalid(
166174
schema.GroupKind{Group: "core.openstack.org", Kind: "OpenStackControlPlane"},
@@ -1138,3 +1146,28 @@ func (r *OpenStackControlPlane) ValidateTopology(basePath *field.Path) *field.Er
11381146
}
11391147
return nil
11401148
}
1149+
1150+
// ValidateNotificationsBusInstance - returns an error if the notificationsBusInstance
1151+
// parameter is not valid.
1152+
// - nil or empty string must be raised as an error
1153+
// - when notificationsBusInstance does not point to an existing RabbitMQ instance
1154+
func (r *OpenStackControlPlane) ValidateNotificationsBusInstance(basePath *field.Path) *field.Error {
1155+
notificationsField := basePath.Child("notificationsBusInstance")
1156+
// no notificationsBusInstance field set, nothing to validate here
1157+
if r.Spec.NotificationsBusInstance == nil {
1158+
return nil
1159+
}
1160+
// When NotificationsBusInstance is set, fail if it is an empty string
1161+
if *r.Spec.NotificationsBusInstance == "" {
1162+
return field.Invalid(notificationsField, *r.Spec.NotificationsBusInstance, "notificationsBusInstance is not a valid string")
1163+
}
1164+
// NotificationsBusInstance is set and must be equal to an existing
1165+
// deployed rabbitmq instance, otherwise we should fail because it
1166+
// does not represent a valid string
1167+
for k := range(*r.Spec.Rabbitmq.Templates) {
1168+
if *r.Spec.NotificationsBusInstance == k {
1169+
return nil
1170+
}
1171+
}
1172+
return field.Invalid(notificationsField, *r.Spec.NotificationsBusInstance, "notificationsBusInstance must match an existing RabbitMQ instance name")
1173+
}

apis/core/v1beta1/zz_generated.deepcopy.go

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

bindata/crds/crds.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10021,6 +10021,8 @@ spec:
1002110021
additionalProperties:
1002210022
type: string
1002310023
type: object
10024+
notificationsBusInstance:
10025+
type: string
1002410026
nova:
1002510027
properties:
1002610028
apiOverride:

config/crd/bases/core.openstack.org_openstackcontrolplanes.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9855,6 +9855,8 @@ spec:
98559855
additionalProperties:
98569856
type: string
98579857
type: object
9858+
notificationsBusInstance:
9859+
type: string
98589860
nova:
98599861
properties:
98609862
apiOverride:

pkg/openstack/cinder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ func ReconcileCinder(ctx context.Context, instance *corev1beta1.OpenStackControl
130130
instance.Spec.Cinder.Template.TopologyRef = instance.Spec.TopologyRef
131131
}
132132

133+
// When no NotificationsBusInstance is referenced in the subCR (override)
134+
// try to inject the top-level one if defined
135+
if instance.Spec.Cinder.Template.NotificationsBusInstance == nil {
136+
instance.Spec.Cinder.Template.NotificationsBusInstance = instance.Spec.NotificationsBusInstance
137+
}
138+
133139
Log.Info("Reconciling Cinder", "Cinder.Namespace", instance.Namespace, "Cinder.Name", cinderName)
134140
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), cinder, func() error {
135141
instance.Spec.Cinder.Template.CinderSpecBase.DeepCopyInto(&cinder.Spec.CinderSpecBase)

pkg/openstack/glance.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ func ReconcileGlance(ctx context.Context, instance *corev1beta1.OpenStackControl
7474
instance.Spec.Glance.Template.TopologyRef = instance.Spec.TopologyRef
7575
}
7676

77+
// When no NotificationsBusInstance is referenced in the subCR (override)
78+
// try to inject the top-level one if defined
79+
if instance.Spec.Glance.Template.NotificationBusInstance == nil {
80+
instance.Spec.Glance.Template.NotificationBusInstance = instance.Spec.NotificationsBusInstance
81+
}
82+
7783
// When component services got created check if there is the need to create a route
7884
if err := helper.GetClient().Get(ctx, types.NamespacedName{Name: glanceName, Namespace: instance.Namespace}, glance); err != nil {
7985
if !k8s_errors.IsNotFound(err) {

pkg/openstack/manila.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ func ReconcileManila(ctx context.Context, instance *corev1beta1.OpenStackControl
118118
instance.Spec.Manila.Template.TopologyRef = instance.Spec.TopologyRef
119119
}
120120

121+
// When no NotificationsBusInstance is referenced in the subCR (override)
122+
// try to inject the top-level one if defined
123+
if instance.Spec.Manila.Template.NotificationsBusInstance == nil {
124+
instance.Spec.Manila.Template.NotificationsBusInstance = instance.Spec.NotificationsBusInstance
125+
}
126+
121127
Log.Info("Reconciling Manila", "Manila.Namespace", instance.Namespace, "Manila.Name", "manila")
122128
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), manila, func() error {
123129
instance.Spec.Manila.Template.ManilaSpecBase.DeepCopyInto(&manila.Spec.ManilaSpecBase)

pkg/openstack/neutron.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,12 @@ func ReconcileNeutron(ctx context.Context, instance *corev1beta1.OpenStackContro
155155
instance.Spec.Neutron.Template.TopologyRef = instance.Spec.TopologyRef
156156
}
157157

158+
// When no NotificationsBusInstance is referenced in the subCR (override)
159+
// try to inject the top-level one if defined
160+
if instance.Spec.Neutron.Template.NotificationsBusInstance == nil {
161+
instance.Spec.Neutron.Template.NotificationsBusInstance = instance.Spec.NotificationsBusInstance
162+
}
163+
158164
Log.Info("Reconciling NeutronAPI", "NeutronAPI.Namespace", instance.Namespace, "NeutronAPI.Name", "neutron")
159165
op, err := controllerutil.CreateOrPatch(ctx, helper.GetClient(), neutronAPI, func() error {
160166
instance.Spec.Neutron.Template.DeepCopyInto(&neutronAPI.Spec.NeutronAPISpecCore)

0 commit comments

Comments
 (0)