diff --git a/Makefile b/Makefile index 72153f294..e9f2619f1 100644 --- a/Makefile +++ b/Makefile @@ -116,7 +116,7 @@ tidy: ## Run go mod tidy on every mod file in the repo .PHONY: test test: manifests generate fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... ./api/... -coverprofile cover.out ##@ Build diff --git a/api/bases/telemetry.openstack.org_autoscalings.yaml b/api/bases/telemetry.openstack.org_autoscalings.yaml index 0a4627cfc..33f7fd366 100644 --- a/api/bases/telemetry.openstack.org_autoscalings.yaml +++ b/api/bases/telemetry.openstack.org_autoscalings.yaml @@ -130,6 +130,23 @@ spec: description: NodeSelector to target subset of worker nodes running this service type: object + notificationsBus: + description: NotificationsBus configuration (username, vhost, + and cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object notifierImage: type: string override: @@ -319,10 +336,10 @@ spec: e.g. to check logs type: boolean rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Aodh + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -510,6 +527,10 @@ spec: items: type: string type: array + notificationsURLSecret: + description: NotificationsURLSecret - Secret containing RabbitMQ notification + transportURL + type: string observedGeneration: description: |- ObservedGeneration - the most recent generation observed for this diff --git a/api/bases/telemetry.openstack.org_ceilometers.yaml b/api/bases/telemetry.openstack.org_ceilometers.yaml index a1bd6e565..9cdc781e4 100644 --- a/api/bases/telemetry.openstack.org_ceilometers.yaml +++ b/api/bases/telemetry.openstack.org_ceilometers.yaml @@ -207,6 +207,23 @@ spec: type: object notificationImage: type: string + notificationsBus: + description: NotificationsBus configuration (username, vhost, and + cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object passwordSelector: default: ceilometerService: CeilometerPassword @@ -232,10 +249,10 @@ spec: proxyImage: type: string rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Telemetry + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -381,6 +398,10 @@ spec: items: type: string type: array + notificationsURLSecret: + description: NotificationsURLSecret - Secret containing RabbitMQ notification + transportURL + type: string observedGeneration: description: |- ObservedGeneration - the most recent generation observed for this diff --git a/api/bases/telemetry.openstack.org_cloudkitties.yaml b/api/bases/telemetry.openstack.org_cloudkitties.yaml index 32506979f..40b51bb26 100644 --- a/api/bases/telemetry.openstack.org_cloudkitties.yaml +++ b/api/bases/telemetry.openstack.org_cloudkitties.yaml @@ -558,6 +558,22 @@ spec: default: memcached description: Memcached instance name. type: string + messagingBus: + description: MessagingBus configuration (username, vhost, and cluster) + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object nodeSelector: additionalProperties: type: string @@ -633,10 +649,10 @@ spec: type: object x-kubernetes-map-type: atomic rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in CloudKitty + Deprecated: Use MessagingBus.Cluster instead type: string s3StorageConfig: default: diff --git a/api/bases/telemetry.openstack.org_telemetries.yaml b/api/bases/telemetry.openstack.org_telemetries.yaml index 4817f61d0..0cf9c6c6f 100644 --- a/api/bases/telemetry.openstack.org_telemetries.yaml +++ b/api/bases/telemetry.openstack.org_telemetries.yaml @@ -133,6 +133,23 @@ spec: description: NodeSelector to target subset of worker nodes running this service type: object + notificationsBus: + description: NotificationsBus configuration (username, vhost, + and cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object notifierImage: type: string override: @@ -322,10 +339,10 @@ spec: finished e.g. to check logs type: boolean rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Aodh + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -543,6 +560,23 @@ spec: type: object notificationImage: type: string + notificationsBus: + description: NotificationsBus configuration (username, vhost, + and cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object passwordSelector: default: ceilometerService: CeilometerPassword @@ -568,10 +602,10 @@ spec: proxyImage: type: string rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Telemetry + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -1142,6 +1176,23 @@ spec: default: memcached description: Memcached instance name. type: string + messagingBus: + description: MessagingBus configuration (username, vhost, and + cluster) + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object nodeSelector: additionalProperties: type: string @@ -1218,10 +1269,10 @@ spec: type: object x-kubernetes-map-type: atomic rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in CloudKitty + Deprecated: Use MessagingBus.Cluster instead type: string s3StorageConfig: default: diff --git a/api/go.mod b/api/go.mod index 850e3f313..9f3f4d241 100644 --- a/api/go.mod +++ b/api/go.mod @@ -3,8 +3,9 @@ module github.com/openstack-k8s-operators/telemetry-operator/api go 1.24.4 require ( - github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260108154501-11e5091cddf1 - github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35 + github.com/onsi/gomega v1.39.0 + github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260126091827-7758173fbb09 + github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260126081203-efc2df9207eb github.com/rhobs/observability-operator v0.3.1 k8s.io/api v0.31.14 k8s.io/apimachinery v0.31.14 @@ -16,7 +17,6 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect github.com/emicklei/go-restful/v3 v3.12.2 // indirect - github.com/evanphx/json-patch v5.9.11+incompatible // indirect github.com/evanphx/json-patch/v5 v5.9.11 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/fxamacker/cbor/v2 v2.9.0 // indirect @@ -38,12 +38,13 @@ require ( github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect - github.com/onsi/gomega v1.39.0 // indirect + github.com/onsi/ginkgo/v2 v2.27.4 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/prometheus/client_golang v1.22.0 // indirect github.com/prometheus/client_model v0.6.2 // indirect github.com/prometheus/common v0.65.0 // indirect github.com/prometheus/procfs v0.16.1 // indirect + github.com/rabbitmq/cluster-operator/v2 v2.16.0 // indirect github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring v0.71.0-rhobs1 // indirect github.com/spf13/pflag v1.0.7 // indirect github.com/x448/float16 v0.8.4 // indirect diff --git a/api/go.sum b/api/go.sum index 00a3d93b8..82f4d02b7 100644 --- a/api/go.sum +++ b/api/go.sum @@ -1,3 +1,4 @@ +github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0= github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -74,14 +75,16 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee h1:W5t00kpgFd github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.27.3 h1:ICsZJ8JoYafeXFFlFAG75a7CxMsJHwgKwtO+82SE9L8= -github.com/onsi/ginkgo/v2 v2.27.3/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo= +github.com/onsi/ginkgo/v2 v2.27.4 h1:fcEcQW/A++6aZAZQNUmNjvA9PSOzefMJBerHJ4t8v8Y= +github.com/onsi/ginkgo/v2 v2.27.4/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo= github.com/onsi/gomega v1.39.0 h1:y2ROC3hKFmQZJNFeGAMeHZKkjBL65mIZcvrLQBF9k6Q= github.com/onsi/gomega v1.39.0/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260108154501-11e5091cddf1 h1:zAbZVtpldi1TU/CO9aU2ZByzcsi+N3aIv6snpSjBVLY= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260108154501-11e5091cddf1/go.mod h1:ZXwFlspJCdZEUjMbmaf61t5AMB4u2vMyAMMoe/vJroE= -github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35 h1:pF3mJ3nwq6r4qwom+rEWZNquZpcQW/iftHlJ1KPIDsk= -github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35/go.mod h1:kycZyoe7OZdW1HUghr2nI3N7wSJtNahXf6b/ypD14f4= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260126091827-7758173fbb09 h1:vhAGLKZitJIffj7ONiPpKmOX7Tmt/LGJpaY0Z2LeyfQ= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260126091827-7758173fbb09/go.mod h1:ZXwFlspJCdZEUjMbmaf61t5AMB4u2vMyAMMoe/vJroE= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260126081203-efc2df9207eb h1:S7tnYO/E1f1KQfcp7N5bam8+ax/ExDTOhZ1WqG4Bfu0= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260126081203-efc2df9207eb/go.mod h1:ndqfy1KbVorHH6+zlUFPIrCRhMSxO3ImYJUGaooE0x0= +github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec h1:saovr368HPAKHN0aRPh8h8n9s9dn3d8Frmfua0UYRlc= +github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec/go.mod h1:Nh2NEePLjovUQof2krTAg4JaAoLacqtPTZQXK6izNfg= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/api/v1beta1/autoscaling_types.go b/api/v1beta1/autoscaling_types.go index 3c21c089b..e1d2a2396 100644 --- a/api/v1beta1/autoscaling_types.go +++ b/api/v1beta1/autoscaling_types.go @@ -17,6 +17,7 @@ limitations under the License. package v1beta1 import ( + rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/tls" @@ -63,9 +64,13 @@ type AodhCore struct { // APITimeout for Route and Apache APITimeout int `json:"apiTimeout"` + // +kubebuilder:validation:Optional + // NotificationsBus configuration (username, vhost, and cluster) for notifications + NotificationsBus *rabbitmqv1.RabbitMqConfig `json:"notificationsBus,omitempty"` + // RabbitMQ instance name // Needed to request a transportURL that is created and used in Aodh - // +kubebuilder:default=rabbitmq + // Deprecated: Use NotificationsBus.Cluster instead RabbitMqClusterName string `json:"rabbitMqClusterName,omitempty"` // +kubebuilder:validation:Required @@ -206,6 +211,9 @@ type AutoscalingStatus struct { // TransportURLSecret - Secret containing RabbitMQ transportURL TransportURLSecret string `json:"transportURLSecret,omitempty"` + // NotificationsURLSecret - Secret containing RabbitMQ notification transportURL + NotificationsURLSecret *string `json:"notificationsURLSecret,omitempty"` + // DatabaseHostname - Hostname for the database DatabaseHostname string `json:"databaseHostname,omitempty"` diff --git a/api/v1beta1/autoscaling_webhook.go b/api/v1beta1/autoscaling_webhook.go index 78948dbf7..14e37abf9 100644 --- a/api/v1beta1/autoscaling_webhook.go +++ b/api/v1beta1/autoscaling_webhook.go @@ -19,7 +19,11 @@ package v1beta1 import ( "fmt" + common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook" + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" @@ -73,6 +77,10 @@ func (spec *AutoscalingSpec) Default() { // Default - note only *Core* versions like this will have validations that are called from the // Controlplane webhook func (spec *AodhCore) Default() { + // NotificationsBus.Cluster is not defaulted - it must be explicitly set if NotificationsBus is configured + // Migration from deprecated fields is handled by openstack-operator + // This ensures users make a conscious choice about which cluster to use for notifications + if spec.MemcachedInstance == "" { spec.MemcachedInstance = "memcached" } @@ -80,6 +88,51 @@ func (spec *AodhCore) Default() { // AppCred is opt-in: only used when explicitly configured by the user. } +// getDeprecatedFields returns the centralized list of deprecated fields for AodhCore +func (spec *AodhCore) getDeprecatedFields(old *AodhCore) []common_webhook.DeprecatedFieldUpdate { + deprecatedFields := []common_webhook.DeprecatedFieldUpdate{ + { + DeprecatedFieldName: "rabbitMqClusterName", + NewFieldPath: []string{"notificationsBus", "cluster"}, + NewDeprecatedValue: &spec.RabbitMqClusterName, + NewValue: &spec.NotificationsBus.Cluster, + }, + } + + // If old spec is provided (UPDATE operation), add old values + if old != nil { + deprecatedFields[0].OldDeprecatedValue = &old.RabbitMqClusterName + } + + return deprecatedFields +} + +// validateDeprecatedFieldsCreate validates deprecated fields during CREATE operations +func (spec *AodhCore) validateDeprecatedFieldsCreate(basePath *field.Path) ([]string, field.ErrorList) { + // Get deprecated fields list (without old values for CREATE) + deprecatedFieldsUpdate := spec.getDeprecatedFields(nil) + + // Convert to DeprecatedField list for CREATE validation + deprecatedFields := make([]common_webhook.DeprecatedField, len(deprecatedFieldsUpdate)) + for i, df := range deprecatedFieldsUpdate { + deprecatedFields[i] = common_webhook.DeprecatedField{ + DeprecatedFieldName: df.DeprecatedFieldName, + NewFieldPath: df.NewFieldPath, + DeprecatedValue: df.NewDeprecatedValue, + NewValue: df.NewValue, + } + } + + return common_webhook.ValidateDeprecatedFieldsCreate(deprecatedFields, basePath), nil +} + +// validateDeprecatedFieldsUpdate validates deprecated fields during UPDATE operations +func (spec *AodhCore) validateDeprecatedFieldsUpdate(old AodhCore, basePath *field.Path) ([]string, field.ErrorList) { + // Get deprecated fields list with old values + deprecatedFields := spec.getDeprecatedFields(&old) + return common_webhook.ValidateDeprecatedFieldsUpdate(deprecatedFields, basePath) +} + // SetDefaultRouteAnnotations sets HAProxy timeout values of the route // NOTE: it is used by ctlplane webhook on openstack-operator func (spec *AutoscalingSpecCore) SetDefaultRouteAnnotations(annotations map[string]string) { @@ -113,22 +166,88 @@ var _ webhook.Validator = &Autoscaling{} func (r *Autoscaling) ValidateCreate() (admission.Warnings, error) { autoscalinglog.Info("validate create", "name", r.Name) - // TODO(user): fill in your validation logic upon object creation. - return nil, nil + var allErrs field.ErrorList + var allWarns []string + basePath := field.NewPath("spec") + + warns, err := r.Spec.Aodh.ValidateCreate(basePath.Child("aodh"), r.Namespace) + allWarns = append(allWarns, warns...) + if err != nil { + allErrs = append(allErrs, err...) + } + + if len(allErrs) != 0 { + return allWarns, apierrors.NewInvalid( + schema.GroupKind{Group: "telemetry.openstack.org", Kind: "Autoscaling"}, + r.Name, allErrs) + } + + return allWarns, nil } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type func (r *Autoscaling) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { autoscalinglog.Info("validate update", "name", r.Name) - // TODO(user): fill in your validation logic upon object update. - return nil, nil + oldAutoscaling, ok := old.(*Autoscaling) + if !ok || oldAutoscaling == nil { + return nil, apierrors.NewInternalError(nil) + } + + var allErrs field.ErrorList + var allWarns []string + basePath := field.NewPath("spec") + + warns, err := r.Spec.Aodh.ValidateUpdate(oldAutoscaling.Spec.Aodh.AodhCore, basePath.Child("aodh"), r.Namespace) + allWarns = append(allWarns, warns...) + if err != nil { + allErrs = append(allErrs, err...) + } + + if len(allErrs) != 0 { + return allWarns, apierrors.NewInvalid( + schema.GroupKind{Group: "telemetry.openstack.org", Kind: "Autoscaling"}, + r.Name, allErrs) + } + + return allWarns, nil } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type func (r *Autoscaling) ValidateDelete() (admission.Warnings, error) { autoscalinglog.Info("validate delete", "name", r.Name) - // TODO(user): fill in your validation logic upon object deletion. return nil, nil } + +// ValidateCreate - Exported function wrapping non-exported validate functions, +// this function can be called externally to validate an aodh spec. +func (spec *AodhCore) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) { + var allErrs field.ErrorList + var allWarns []string + + // Validate deprecated fields using shared helper + warns, errs := spec.validateDeprecatedFieldsCreate(basePath) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) + + allErrs = append(allErrs, spec.ValidateTopology(basePath, namespace)...) + + return allWarns, allErrs +} + +// ValidateUpdate - Exported function wrapping non-exported validate functions, +// this function can be called externally to validate an aodh spec. +func (spec *AodhCore) ValidateUpdate(old AodhCore, basePath *field.Path, namespace string) ([]string, field.ErrorList) { + var allErrs field.ErrorList + var allWarns []string + + // Validate deprecated fields using shared helper + warns, errs := spec.validateDeprecatedFieldsUpdate(old, basePath) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) + + allErrs = append(allErrs, spec.ValidateTopology(basePath, namespace)...) + + return allWarns, allErrs +} diff --git a/api/v1beta1/ceilometer_types.go b/api/v1beta1/ceilometer_types.go index 35530a96e..b1f9a87ae 100644 --- a/api/v1beta1/ceilometer_types.go +++ b/api/v1beta1/ceilometer_types.go @@ -17,6 +17,7 @@ limitations under the License. package v1beta1 import ( + rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1" condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/tls" @@ -81,9 +82,14 @@ type CeilometerSpecCore struct { // APITimeout for Apache APITimeout int `json:"apiTimeout"` + // +kubebuilder:validation:Optional + // NotificationsBus configuration (username, vhost, and cluster) for notifications + NotificationsBus *rabbitmqv1.RabbitMqConfig `json:"notificationsBus,omitempty"` + + // +kubebuilder:validation:Optional // RabbitMQ instance name // Needed to request a transportURL that is created and used in Telemetry - // +kubebuilder:default=rabbitmq + // Deprecated: Use NotificationsBus.Cluster instead RabbitMqClusterName string `json:"rabbitMqClusterName,omitempty"` // PasswordSelectors - Selectors to identify the service from the Secret @@ -182,6 +188,9 @@ type CeilometerStatus struct { // TransportURLSecret - Secret containing RabbitMQ transportURL TransportURLSecret string `json:"transportURLSecret,omitempty"` + // NotificationsURLSecret - Secret containing RabbitMQ notification transportURL + NotificationsURLSecret *string `json:"notificationsURLSecret,omitempty"` + // Networks in addtion to the cluster network, the service is attached to Networks []string `json:"networks,omitempty"` diff --git a/api/v1beta1/ceilometer_webhook.go b/api/v1beta1/ceilometer_webhook.go index 71ec2daf0..ff708da0f 100644 --- a/api/v1beta1/ceilometer_webhook.go +++ b/api/v1beta1/ceilometer_webhook.go @@ -17,10 +17,14 @@ limitations under the License. package v1beta1 import ( + apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/apimachinery/pkg/util/validation/field" logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook" ) // CeilometerDefaults - @@ -81,11 +85,60 @@ func (spec *CeilometerSpec) Default() { if spec.MysqldExporterImage == "" { spec.MysqldExporterImage = ceilometerDefaults.MysqldExporterContainerImageURL } + + spec.CeilometerSpecCore.Default() } +// Default - set defaults for this CeilometerSpecCore. NOTE: this version is used by the OpenStackControlplane webhook func (spec *CeilometerSpecCore) Default() { - // NOTE: ApplicationCredentialSecret is NOT defaulted here. - // AppCred is opt-in: only used when explicitly configured by the user. + // NotificationsBus.Cluster is not defaulted - it must be explicitly set if NotificationsBus is configured + // Migration from deprecated fields is handled by openstack-operator + // This ensures users make a conscious choice about which cluster to use for notifications +} + +// getDeprecatedFields returns the centralized list of deprecated fields for CeilometerSpecCore +func (spec *CeilometerSpecCore) getDeprecatedFields(old *CeilometerSpecCore) []common_webhook.DeprecatedFieldUpdate { + deprecatedFields := []common_webhook.DeprecatedFieldUpdate{ + { + DeprecatedFieldName: "rabbitMqClusterName", + NewFieldPath: []string{"notificationsBus", "cluster"}, + NewDeprecatedValue: &spec.RabbitMqClusterName, + NewValue: &spec.NotificationsBus.Cluster, + }, + } + + // If old spec is provided (UPDATE operation), add old values + if old != nil { + deprecatedFields[0].OldDeprecatedValue = &old.RabbitMqClusterName + } + + return deprecatedFields +} + +// validateDeprecatedFieldsCreate validates deprecated fields during CREATE operations +func (spec *CeilometerSpecCore) validateDeprecatedFieldsCreate(basePath *field.Path) ([]string, field.ErrorList) { + // Get deprecated fields list (without old values for CREATE) + deprecatedFieldsUpdate := spec.getDeprecatedFields(nil) + + // Convert to DeprecatedField list for CREATE validation + deprecatedFields := make([]common_webhook.DeprecatedField, len(deprecatedFieldsUpdate)) + for i, df := range deprecatedFieldsUpdate { + deprecatedFields[i] = common_webhook.DeprecatedField{ + DeprecatedFieldName: df.DeprecatedFieldName, + NewFieldPath: df.NewFieldPath, + DeprecatedValue: df.NewDeprecatedValue, + NewValue: df.NewValue, + } + } + + return common_webhook.ValidateDeprecatedFieldsCreate(deprecatedFields, basePath), nil +} + +// validateDeprecatedFieldsUpdate validates deprecated fields during UPDATE operations +func (spec *CeilometerSpecCore) validateDeprecatedFieldsUpdate(old CeilometerSpecCore, basePath *field.Path) ([]string, field.ErrorList) { + // Get deprecated fields list with old values + deprecatedFields := spec.getDeprecatedFields(&old) + return common_webhook.ValidateDeprecatedFieldsUpdate(deprecatedFields, basePath) } var _ webhook.Validator = &Ceilometer{} @@ -94,22 +147,88 @@ var _ webhook.Validator = &Ceilometer{} func (r *Ceilometer) ValidateCreate() (admission.Warnings, error) { ceilometerlog.Info("validate create", "name", r.Name) - // TODO(user): fill in your validation logic upon object creation. - return nil, nil + var allErrs field.ErrorList + var allWarns []string + basePath := field.NewPath("spec") + + warns, err := r.Spec.CeilometerSpecCore.ValidateCreate(basePath, r.Namespace) + allWarns = append(allWarns, warns...) + if err != nil { + allErrs = append(allErrs, err...) + } + + if len(allErrs) != 0 { + return allWarns, apierrors.NewInvalid( + schema.GroupKind{Group: "telemetry.openstack.org", Kind: "Ceilometer"}, + r.Name, allErrs) + } + + return allWarns, nil } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type func (r *Ceilometer) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { ceilometerlog.Info("validate update", "name", r.Name) - // TODO(user): fill in your validation logic upon object update. - return nil, nil + oldCeilometer, ok := old.(*Ceilometer) + if !ok || oldCeilometer == nil { + return nil, apierrors.NewInternalError(nil) + } + + var allErrs field.ErrorList + var allWarns []string + basePath := field.NewPath("spec") + + warns, err := r.Spec.CeilometerSpecCore.ValidateUpdate(oldCeilometer.Spec.CeilometerSpecCore, basePath, r.Namespace) + allWarns = append(allWarns, warns...) + if err != nil { + allErrs = append(allErrs, err...) + } + + if len(allErrs) != 0 { + return allWarns, apierrors.NewInvalid( + schema.GroupKind{Group: "telemetry.openstack.org", Kind: "Ceilometer"}, + r.Name, allErrs) + } + + return allWarns, nil } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type func (r *Ceilometer) ValidateDelete() (admission.Warnings, error) { ceilometerlog.Info("validate delete", "name", r.Name) - // TODO(user): fill in your validation logic upon object deletion. return nil, nil } + +// ValidateCreate - Exported function wrapping non-exported validate functions, +// this function can be called externally to validate a ceilometer spec. +func (spec *CeilometerSpecCore) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) { + var allErrs field.ErrorList + var allWarns []string + + // Validate deprecated fields using shared helper + warns, errs := spec.validateDeprecatedFieldsCreate(basePath) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) + + allErrs = append(allErrs, spec.ValidateTopology(basePath, namespace)...) + + return allWarns, allErrs +} + +// ValidateUpdate - Exported function wrapping non-exported validate functions, +// this function can be called externally to validate a ceilometer spec. +func (spec *CeilometerSpecCore) ValidateUpdate(old CeilometerSpecCore, basePath *field.Path, namespace string) ([]string, field.ErrorList) { + var allErrs field.ErrorList + var allWarns []string + + // Validate deprecated fields using shared helper + warns, errs := spec.validateDeprecatedFieldsUpdate(old, basePath) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) + + allErrs = append(allErrs, spec.ValidateTopology(basePath, namespace)...) + + return allWarns, allErrs +} diff --git a/api/v1beta1/cloudkitty_types.go b/api/v1beta1/cloudkitty_types.go index 431a9266a..631568ed7 100644 --- a/api/v1beta1/cloudkitty_types.go +++ b/api/v1beta1/cloudkitty_types.go @@ -17,6 +17,7 @@ limitations under the License. package v1beta1 import ( + rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" topologyv1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1" "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/util" @@ -134,10 +135,14 @@ type CloudKittySpecBase struct { DatabaseInstance string `json:"databaseInstance"` // +kubebuilder:validation:Optional - // +kubebuilder:default=rabbitmq + // MessagingBus configuration (username, vhost, and cluster) + MessagingBus rabbitmqv1.RabbitMqConfig `json:"messagingBus,omitempty"` + + // +kubebuilder:validation:Optional // RabbitMQ instance name // Needed to request a transportURL that is created and used in CloudKitty - RabbitMqClusterName string `json:"rabbitMqClusterName"` + // Deprecated: Use MessagingBus.Cluster instead + RabbitMqClusterName string `json:"rabbitMqClusterName,omitempty"` // +kubebuilder:validation:Optional // +kubebuilder:default=memcached diff --git a/api/v1beta1/cloudkitty_webhook.go b/api/v1beta1/cloudkitty_webhook.go index f12914f08..38f2fc3aa 100644 --- a/api/v1beta1/cloudkitty_webhook.go +++ b/api/v1beta1/cloudkitty_webhook.go @@ -27,6 +27,7 @@ import ( logf "sigs.k8s.io/controller-runtime/pkg/log" "sigs.k8s.io/controller-runtime/pkg/webhook" "sigs.k8s.io/controller-runtime/pkg/webhook/admission" + common_webhook "github.com/openstack-k8s-operators/lib-common/modules/common/webhook" ) // CloudKittyDefaults - @@ -63,6 +64,8 @@ func (spec *CloudKittySpec) Default() { if spec.CloudKittyProc.ContainerImage == "" { spec.CloudKittyProc.ContainerImage = cloudKittyDefaults.ProcContainerImageURL } + + spec.CloudKittySpecBase.Default() } // Default - note only *Template* versions like this will have validations that are called from the @@ -72,6 +75,65 @@ func (spec *CloudKittyTemplate) Default() { // AppCred is opt-in: only used when explicitly configured by the user. } +// Default - set defaults for this CloudKittySpecCore. NOTE: this version is used by the OpenStackControlplane webhook +func (spec *CloudKittySpecCore) Default() { + spec.CloudKittySpecBase.Default() +} + +// Default - set defaults for this CloudKittySpecBase +func (spec *CloudKittySpecBase) Default() { + // Default MessagingBus.Cluster if not set + // Migration from deprecated fields is handled by openstack-operator + if spec.MessagingBus.Cluster == "" { + spec.MessagingBus.Cluster = "rabbitmq" + } +} + +// getDeprecatedFields returns the centralized list of deprecated fields for CloudKittySpecBase +func (spec *CloudKittySpecBase) getDeprecatedFields(old *CloudKittySpecBase) []common_webhook.DeprecatedFieldUpdate { + deprecatedFields := []common_webhook.DeprecatedFieldUpdate{ + { + DeprecatedFieldName: "rabbitMqClusterName", + NewFieldPath: []string{"messagingBus", "cluster"}, + NewDeprecatedValue: &spec.RabbitMqClusterName, + NewValue: &spec.MessagingBus.Cluster, + }, + } + + // If old spec is provided (UPDATE operation), add old values + if old != nil { + deprecatedFields[0].OldDeprecatedValue = &old.RabbitMqClusterName + } + + return deprecatedFields +} + +// validateDeprecatedFieldsCreate validates deprecated fields during CREATE operations +func (spec *CloudKittySpecBase) validateDeprecatedFieldsCreate(basePath *field.Path) ([]string, field.ErrorList) { + // Get deprecated fields list (without old values for CREATE) + deprecatedFieldsUpdate := spec.getDeprecatedFields(nil) + + // Convert to DeprecatedField list for CREATE validation + deprecatedFields := make([]common_webhook.DeprecatedField, len(deprecatedFieldsUpdate)) + for i, df := range deprecatedFieldsUpdate { + deprecatedFields[i] = common_webhook.DeprecatedField{ + DeprecatedFieldName: df.DeprecatedFieldName, + NewFieldPath: df.NewFieldPath, + DeprecatedValue: df.NewDeprecatedValue, + NewValue: df.NewValue, + } + } + + return common_webhook.ValidateDeprecatedFieldsCreate(deprecatedFields, basePath), nil +} + +// validateDeprecatedFieldsUpdate validates deprecated fields during UPDATE operations +func (spec *CloudKittySpecBase) validateDeprecatedFieldsUpdate(old CloudKittySpecBase, basePath *field.Path) ([]string, field.ErrorList) { + // Get deprecated fields list with old values + deprecatedFields := spec.getDeprecatedFields(&old) + return common_webhook.ValidateDeprecatedFieldsUpdate(deprecatedFields, basePath) +} + var _ webhook.Validator = &CloudKitty{} func (r *ObjectStorageSpec) Validate(basePath *field.Path) field.ErrorList { @@ -133,37 +195,43 @@ func (r *ObjectStorageSpec) Validate(basePath *field.Path) field.ErrorList { func (r *CloudKitty) ValidateCreate() (admission.Warnings, error) { cloudKittyLog.Info("validate create", "name", r.Name) - allErrs := r.Spec.ValidateCreate(field.NewPath("spec"), r.Namespace) + allWarns, allErrs := r.Spec.ValidateCreate(field.NewPath("spec"), r.Namespace) if len(allErrs) != 0 { - return nil, apierrors.NewInvalid( + return allWarns, apierrors.NewInvalid( schema.GroupKind{Group: "cloudkitties.telemetry.openstack.org", Kind: "CloudKitty"}, r.Name, allErrs) } - return nil, nil + return allWarns, nil } // ValidateCreate validates the CloudKittySpec during the webhook invocation. -func (r *CloudKittySpec) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList { +func (r *CloudKittySpec) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) { return r.CloudKittySpecBase.ValidateCreate(basePath, namespace) } // ValidateCreate validates the CloudKittySpecCore during the webhook invocation. It is // expected to be called by the validation webhook in the higher level telemetry webhook -func (r *CloudKittySpecCore) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList { +func (r *CloudKittySpecCore) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) { return r.CloudKittySpecBase.ValidateCreate(basePath, namespace) } // ValidateCreate validates the CloudKittySpecBase during the webhook invocation. -func (r *CloudKittySpecBase) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList { +func (r *CloudKittySpecBase) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) { var allErrs field.ErrorList + var allWarns []string + + // Validate deprecated fields using shared helper + warns, errs := r.validateDeprecatedFieldsCreate(basePath) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) allErrs = append(allErrs, r.S3StorageConfig.Validate(basePath.Child("s3StorageConfig"))...) // TODO: Add other CK spec field validations as needed - return allErrs + return allWarns, allErrs } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type @@ -175,38 +243,44 @@ func (r *CloudKitty) ValidateUpdate(old runtime.Object) (admission.Warnings, err return nil, apierrors.NewInternalError(fmt.Errorf("unable to convert existing object")) } - allErrs := r.Spec.ValidateUpdate(oldCloudKitty.Spec, field.NewPath("spec"), r.Namespace) + allWarns, allErrs := r.Spec.ValidateUpdate(oldCloudKitty.Spec, field.NewPath("spec"), r.Namespace) if len(allErrs) != 0 { - return nil, apierrors.NewInvalid( + return allWarns, apierrors.NewInvalid( schema.GroupKind{Group: "cloudkitties.telemetry.openstack.org", Kind: "CloudKitty"}, r.Name, allErrs) } - return nil, nil + return allWarns, nil } -// ValidateCreate validates the CloudKittySpec during the webhook invocation. -func (r *CloudKittySpec) ValidateUpdate(old CloudKittySpec, basePath *field.Path, namespace string) field.ErrorList { +// ValidateUpdate validates the CloudKittySpec during the webhook invocation. +func (r *CloudKittySpec) ValidateUpdate(old CloudKittySpec, basePath *field.Path, namespace string) ([]string, field.ErrorList) { return r.CloudKittySpecBase.ValidateUpdate(old.CloudKittySpecBase, basePath, namespace) } // ValidateUpdate validates the CloudKittySpecCore during the webhook invocation. It is // expected to be called by the validation webhook in the higher level telemetry webhook -func (r *CloudKittySpecCore) ValidateUpdate(old CloudKittySpecCore, basePath *field.Path, namespace string) field.ErrorList { +func (r *CloudKittySpecCore) ValidateUpdate(old CloudKittySpecCore, basePath *field.Path, namespace string) ([]string, field.ErrorList) { return r.CloudKittySpecBase.ValidateUpdate(old.CloudKittySpecBase, basePath, namespace) } -// ValidateCreate validates the CloudKittySpecBase during the webhook invocation. -func (r *CloudKittySpecBase) ValidateUpdate(old CloudKittySpecBase, basePath *field.Path, namespace string) field.ErrorList { +// ValidateUpdate validates the CloudKittySpecBase during the webhook invocation. +func (r *CloudKittySpecBase) ValidateUpdate(old CloudKittySpecBase, basePath *field.Path, namespace string) ([]string, field.ErrorList) { var allErrs field.ErrorList + var allWarns []string + + // Validate deprecated fields using shared helper + warns, errs := r.validateDeprecatedFieldsUpdate(old, basePath) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) allErrs = append(allErrs, r.S3StorageConfig.Validate(basePath.Child("s3StorageConfig"))...) // TODO: Add other CK spec field validations as needed - return allErrs + return allWarns, allErrs } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type diff --git a/api/v1beta1/telemetry_webhook.go b/api/v1beta1/telemetry_webhook.go index 2bd919f2d..3012b0546 100644 --- a/api/v1beta1/telemetry_webhook.go +++ b/api/v1beta1/telemetry_webhook.go @@ -114,12 +114,20 @@ func (spec *TelemetrySpec) Default() { if spec.CloudKitty.CloudKittyProc.ContainerImage == "" { spec.CloudKitty.CloudKittyProc.ContainerImage = telemetryDefaults.CloudKittyProcContainerImageURL } + + // Call nested Default() methods to set rabbitmq cluster defaults + spec.Autoscaling.AutoscalingSpec.Default() + spec.Autoscaling.Aodh.Default() + spec.Ceilometer.CeilometerSpec.Default() + spec.CloudKitty.CloudKittySpec.Default() } // Default - set defaults for this Telemetry spec core // NOTE: only this version gets called by the Controlplane Webhook func (spec *TelemetrySpecCore) Default() { spec.Autoscaling.Aodh.Default() + spec.Ceilometer.Default() + spec.CloudKitty.Default() } var _ webhook.Validator = &Telemetry{} @@ -127,41 +135,53 @@ var _ webhook.Validator = &Telemetry{} // ValidateCreate implements webhook.Validator so a webhook will be registered for the type func (r *Telemetry) ValidateCreate() (admission.Warnings, error) { telemetrylog.Info("validate create", "name", r.Name) + var allWarns []string var allErrs field.ErrorList basePath := field.NewPath("spec") - allErrs = r.Spec.ValidateCreate(basePath, r.Namespace) + warns, errs := r.Spec.ValidateCreate(basePath, r.Namespace) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) + if len(allErrs) != 0 { - return nil, apierrors.NewInvalid( + return allWarns, apierrors.NewInvalid( schema.GroupKind{Group: "telemetry.openstack.org", Kind: "Telemetry"}, r.Name, allErrs) } - return nil, nil + return allWarns, nil } -func (r TelemetrySpec) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList { +func (r TelemetrySpec) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) { var allErrs field.ErrorList + var allWarns []string allErrs = append(allErrs, r.ValidateTelemetryTopology(basePath, namespace)...) if r.CloudKitty.Enabled != nil && *r.CloudKitty.Enabled { - allErrs = append(allErrs, r.CloudKitty.CloudKittySpec.ValidateCreate(basePath.Child("cloudkitty"), namespace)...) + warns, errs := r.CloudKitty.CloudKittySpec.ValidateCreate(basePath.Child("cloudkitty"), namespace) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) } - return allErrs + return allWarns, allErrs } -func (r TelemetrySpecCore) ValidateCreate(basePath *field.Path, namespace string) field.ErrorList { +func (r TelemetrySpecCore) ValidateCreate(basePath *field.Path, namespace string) ([]string, field.ErrorList) { var allErrs field.ErrorList + var allWarns []string + allErrs = append(allErrs, r.ValidateTelemetryTopology(basePath, namespace)...) if r.CloudKitty.Enabled != nil && *r.CloudKitty.Enabled { - allErrs = append(allErrs, r.CloudKitty.CloudKittySpecCore.ValidateCreate(basePath.Child("cloudkitty"), namespace)...) + warns, errs := r.CloudKitty.CloudKittySpecCore.ValidateCreate(basePath.Child("cloudkitty"), namespace) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) } - return allErrs + return allWarns, allErrs } // ValidateUpdate implements webhook.Validator so a webhook will be registered for the type func (r *Telemetry) ValidateUpdate(old runtime.Object) (admission.Warnings, error) { telemetrylog.Info("validate update", "name", r.Name) + var allWarns []string var allErrs field.ErrorList basePath := field.NewPath("spec") @@ -170,33 +190,43 @@ func (r *Telemetry) ValidateUpdate(old runtime.Object) (admission.Warnings, erro return nil, apierrors.NewInternalError(fmt.Errorf("unable to convert existing object")) } - allErrs = r.Spec.ValidateUpdate(oldTelemetry.Spec, basePath, r.Namespace) + warns, errs := r.Spec.ValidateUpdate(oldTelemetry.Spec, basePath, r.Namespace) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) + if len(allErrs) != 0 { - return nil, apierrors.NewInvalid( + return allWarns, apierrors.NewInvalid( schema.GroupKind{Group: "telemetry.openstack.org", Kind: "Telemetry"}, r.Name, allErrs) } - return nil, nil + return allWarns, nil } -func (r TelemetrySpec) ValidateUpdate(old TelemetrySpec, basePath *field.Path, namespace string) field.ErrorList { +func (r TelemetrySpec) ValidateUpdate(old TelemetrySpec, basePath *field.Path, namespace string) ([]string, field.ErrorList) { var allErrs field.ErrorList + var allWarns []string allErrs = append(allErrs, r.ValidateTelemetryTopology(basePath, namespace)...) if r.CloudKitty.Enabled != nil && *r.CloudKitty.Enabled { - allErrs = append(allErrs, r.CloudKitty.CloudKittySpec.ValidateUpdate(old.CloudKitty.CloudKittySpec, basePath.Child("cloudkitty"), namespace)...) + warns, errs := r.CloudKitty.CloudKittySpec.ValidateUpdate(old.CloudKitty.CloudKittySpec, basePath.Child("cloudkitty"), namespace) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) } - return allErrs + return allWarns, allErrs } -func (r TelemetrySpecCore) ValidateUpdate(old TelemetrySpecCore, basePath *field.Path, namespace string) field.ErrorList { +func (r TelemetrySpecCore) ValidateUpdate(old TelemetrySpecCore, basePath *field.Path, namespace string) ([]string, field.ErrorList) { var allErrs field.ErrorList + var allWarns []string + allErrs = append(allErrs, r.ValidateTelemetryTopology(basePath, namespace)...) if r.CloudKitty.Enabled != nil && *r.CloudKitty.Enabled { - allErrs = append(allErrs, r.CloudKitty.CloudKittySpecCore.ValidateUpdate(old.CloudKitty.CloudKittySpecCore, basePath.Child("cloudkitty"), namespace)...) + warns, errs := r.CloudKitty.CloudKittySpecCore.ValidateUpdate(old.CloudKitty.CloudKittySpecCore, basePath.Child("cloudkitty"), namespace) + allWarns = append(allWarns, warns...) + allErrs = append(allErrs, errs...) } - return allErrs + return allWarns, allErrs } // ValidateDelete implements webhook.Validator so a webhook will be registered for the type diff --git a/api/v1beta1/telemetry_webhook_test.go b/api/v1beta1/telemetry_webhook_test.go new file mode 100644 index 000000000..931009028 --- /dev/null +++ b/api/v1beta1/telemetry_webhook_test.go @@ -0,0 +1,95 @@ +package v1beta1 + +import ( + "testing" + + . "github.com/onsi/gomega" + rabbitmqv1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" +) + +func TestTelemetrySpecCoreDefault(t *testing.T) { + g := NewWithT(t) + + spec := &TelemetrySpecCore{} + // Set NotificationsBus and MessagingBus without Cluster + spec.Ceilometer.NotificationsBus = &rabbitmqv1.RabbitMqConfig{} + spec.CloudKitty.MessagingBus = rabbitmqv1.RabbitMqConfig{} + + // Call Default() + spec.Default() + + // Verify Ceilometer NotificationsBus.Cluster is NOT defaulted (must be explicitly set) + g.Expect(spec.Ceilometer.NotificationsBus.Cluster).To(Equal(""), + "Ceilometer notificationsBus.cluster should not be defaulted - it must be explicitly set") + + // Verify CloudKitty MessagingBus.Cluster was defaulted + g.Expect(spec.CloudKitty.MessagingBus.Cluster).To(Equal("rabbitmq"), + "CloudKitty messagingBus.cluster should be defaulted to rabbitmq") +} + +func TestCeilometerSpecCoreDefault(t *testing.T) { + g := NewWithT(t) + + spec := &CeilometerSpecCore{} + // Set NotificationsBus without Cluster + spec.NotificationsBus = &rabbitmqv1.RabbitMqConfig{} + + // Call Default() + spec.Default() + + // Verify NotificationsBus.Cluster is NOT defaulted (must be explicitly set) + g.Expect(spec.NotificationsBus.Cluster).To(Equal(""), + "Ceilometer notificationsBus.cluster should not be defaulted - it must be explicitly set") +} + +func TestCeilometerSpecCoreDefaultWithExistingNotificationsBus(t *testing.T) { + g := NewWithT(t) + + spec := &CeilometerSpecCore{} + // User explicitly sets notificationsBus with all fields + spec.NotificationsBus = &rabbitmqv1.RabbitMqConfig{ + Cluster: "custom-notifications-rabbitmq", + User: "custom-user", + Vhost: "custom-vhost", + } + + // Call Default() + spec.Default() + + // Verify NotificationsBus preserves explicit values + g.Expect(spec.NotificationsBus.Cluster).To(Equal("custom-notifications-rabbitmq"), + "Ceilometer notificationsBus.cluster should preserve user-specified value") + g.Expect(spec.NotificationsBus.User).To(Equal("custom-user"), + "Ceilometer notificationsBus.user should preserve user-specified value") + g.Expect(spec.NotificationsBus.Vhost).To(Equal("custom-vhost"), + "Ceilometer notificationsBus.vhost should preserve user-specified value") +} + +func TestAodhCoreDefault(t *testing.T) { + g := NewWithT(t) + + spec := &AodhCore{} + // Set NotificationsBus without Cluster + spec.NotificationsBus = &rabbitmqv1.RabbitMqConfig{} + + // Call Default() + spec.Default() + + // Verify NotificationsBus.Cluster is NOT defaulted (must be explicitly set) + g.Expect(spec.NotificationsBus.Cluster).To(Equal(""), + "Aodh notificationsBus.cluster should not be defaulted - it must be explicitly set") +} + +func TestCloudKittySpecBaseDefault(t *testing.T) { + g := NewWithT(t) + + spec := &CloudKittySpecBase{} + // MessagingBus.Cluster is empty, should be defaulted + + // Call Default() + spec.Default() + + // Verify MessagingBus.Cluster is defaulted + g.Expect(spec.MessagingBus.Cluster).To(Equal("rabbitmq"), + "CloudKitty messagingBus.cluster should be defaulted to rabbitmq") +} diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 59312fcd7..467fe3676 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -22,6 +22,7 @@ package v1beta1 import ( networkv1beta1 "github.com/openstack-k8s-operators/infra-operator/apis/network/v1beta1" + rabbitmqv1beta1 "github.com/openstack-k8s-operators/infra-operator/apis/rabbitmq/v1beta1" topologyv1beta1 "github.com/openstack-k8s-operators/infra-operator/apis/topology/v1beta1" "github.com/openstack-k8s-operators/lib-common/modules/common/condition" "github.com/openstack-k8s-operators/lib-common/modules/common/service" @@ -71,6 +72,11 @@ func (in *Aodh) DeepCopy() *Aodh { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *AodhCore) DeepCopyInto(out *AodhCore) { *out = *in + if in.NotificationsBus != nil { + in, out := &in.NotificationsBus, &out.NotificationsBus + *out = new(rabbitmqv1beta1.RabbitMqConfig) + **out = **in + } out.PasswordSelectors = in.PasswordSelectors if in.DefaultConfigOverwrite != nil { in, out := &in.DefaultConfigOverwrite, &out.DefaultConfigOverwrite @@ -322,6 +328,11 @@ func (in *AutoscalingStatus) DeepCopyInto(out *AutoscalingStatus) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.NotificationsURLSecret != nil { + in, out := &in.NotificationsURLSecret, &out.NotificationsURLSecret + *out = new(string) + **out = **in + } if in.APIEndpoints != nil { in, out := &in.APIEndpoints, &out.APIEndpoints *out = make(map[string]string, len(*in)) @@ -497,6 +508,11 @@ func (in *CeilometerSpec) DeepCopy() *CeilometerSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *CeilometerSpecCore) DeepCopyInto(out *CeilometerSpecCore) { *out = *in + if in.NotificationsBus != nil { + in, out := &in.NotificationsBus, &out.NotificationsBus + *out = new(rabbitmqv1beta1.RabbitMqConfig) + **out = **in + } out.PasswordSelectors = in.PasswordSelectors if in.DefaultConfigOverwrite != nil { in, out := &in.DefaultConfigOverwrite, &out.DefaultConfigOverwrite @@ -569,6 +585,11 @@ func (in *CeilometerStatus) DeepCopyInto(out *CeilometerStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.NotificationsURLSecret != nil { + in, out := &in.NotificationsURLSecret, &out.NotificationsURLSecret + *out = new(string) + **out = **in + } if in.Networks != nil { in, out := &in.Networks, &out.Networks *out = make([]string, len(*in)) @@ -1144,6 +1165,7 @@ func (in *CloudKittySpec) DeepCopy() *CloudKittySpec { func (in *CloudKittySpecBase) DeepCopyInto(out *CloudKittySpecBase) { *out = *in out.CloudKittyTemplate = in.CloudKittyTemplate + out.MessagingBus = in.MessagingBus if in.NodeSelector != nil { in, out := &in.NodeSelector, &out.NodeSelector *out = new(map[string]string) diff --git a/config/crd/bases/telemetry.openstack.org_autoscalings.yaml b/config/crd/bases/telemetry.openstack.org_autoscalings.yaml index 0a4627cfc..33f7fd366 100644 --- a/config/crd/bases/telemetry.openstack.org_autoscalings.yaml +++ b/config/crd/bases/telemetry.openstack.org_autoscalings.yaml @@ -130,6 +130,23 @@ spec: description: NodeSelector to target subset of worker nodes running this service type: object + notificationsBus: + description: NotificationsBus configuration (username, vhost, + and cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object notifierImage: type: string override: @@ -319,10 +336,10 @@ spec: e.g. to check logs type: boolean rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Aodh + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -510,6 +527,10 @@ spec: items: type: string type: array + notificationsURLSecret: + description: NotificationsURLSecret - Secret containing RabbitMQ notification + transportURL + type: string observedGeneration: description: |- ObservedGeneration - the most recent generation observed for this diff --git a/config/crd/bases/telemetry.openstack.org_ceilometers.yaml b/config/crd/bases/telemetry.openstack.org_ceilometers.yaml index a1bd6e565..9cdc781e4 100644 --- a/config/crd/bases/telemetry.openstack.org_ceilometers.yaml +++ b/config/crd/bases/telemetry.openstack.org_ceilometers.yaml @@ -207,6 +207,23 @@ spec: type: object notificationImage: type: string + notificationsBus: + description: NotificationsBus configuration (username, vhost, and + cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object passwordSelector: default: ceilometerService: CeilometerPassword @@ -232,10 +249,10 @@ spec: proxyImage: type: string rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Telemetry + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -381,6 +398,10 @@ spec: items: type: string type: array + notificationsURLSecret: + description: NotificationsURLSecret - Secret containing RabbitMQ notification + transportURL + type: string observedGeneration: description: |- ObservedGeneration - the most recent generation observed for this diff --git a/config/crd/bases/telemetry.openstack.org_cloudkitties.yaml b/config/crd/bases/telemetry.openstack.org_cloudkitties.yaml index 32506979f..40b51bb26 100644 --- a/config/crd/bases/telemetry.openstack.org_cloudkitties.yaml +++ b/config/crd/bases/telemetry.openstack.org_cloudkitties.yaml @@ -558,6 +558,22 @@ spec: default: memcached description: Memcached instance name. type: string + messagingBus: + description: MessagingBus configuration (username, vhost, and cluster) + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object nodeSelector: additionalProperties: type: string @@ -633,10 +649,10 @@ spec: type: object x-kubernetes-map-type: atomic rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in CloudKitty + Deprecated: Use MessagingBus.Cluster instead type: string s3StorageConfig: default: diff --git a/config/crd/bases/telemetry.openstack.org_telemetries.yaml b/config/crd/bases/telemetry.openstack.org_telemetries.yaml index 4817f61d0..0cf9c6c6f 100644 --- a/config/crd/bases/telemetry.openstack.org_telemetries.yaml +++ b/config/crd/bases/telemetry.openstack.org_telemetries.yaml @@ -133,6 +133,23 @@ spec: description: NodeSelector to target subset of worker nodes running this service type: object + notificationsBus: + description: NotificationsBus configuration (username, vhost, + and cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object notifierImage: type: string override: @@ -322,10 +339,10 @@ spec: finished e.g. to check logs type: boolean rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Aodh + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -543,6 +560,23 @@ spec: type: object notificationImage: type: string + notificationsBus: + description: NotificationsBus configuration (username, vhost, + and cluster) for notifications + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object passwordSelector: default: ceilometerService: CeilometerPassword @@ -568,10 +602,10 @@ spec: proxyImage: type: string rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in Telemetry + Deprecated: Use NotificationsBus.Cluster instead type: string secret: default: osp-secret @@ -1142,6 +1176,23 @@ spec: default: memcached description: Memcached instance name. type: string + messagingBus: + description: MessagingBus configuration (username, vhost, and + cluster) + properties: + cluster: + description: Name of the cluster + minLength: 1 + type: string + user: + description: User - RabbitMQ username + type: string + vhost: + description: Vhost - RabbitMQ vhost name + type: string + required: + - cluster + type: object nodeSelector: additionalProperties: type: string @@ -1218,10 +1269,10 @@ spec: type: object x-kubernetes-map-type: atomic rabbitMqClusterName: - default: rabbitmq description: |- RabbitMQ instance name Needed to request a transportURL that is created and used in CloudKitty + Deprecated: Use MessagingBus.Cluster instead type: string s3StorageConfig: default: diff --git a/config/manifests/bases/telemetry-operator.clusterserviceversion.yaml b/config/manifests/bases/telemetry-operator.clusterserviceversion.yaml index 48e8b55d9..8a0201ecf 100644 --- a/config/manifests/bases/telemetry-operator.clusterserviceversion.yaml +++ b/config/manifests/bases/telemetry-operator.clusterserviceversion.yaml @@ -25,6 +25,12 @@ spec: kind: Autoscaling name: autoscalings.telemetry.openstack.org specDescriptors: + - description: Auth - authentication settings for keystone integration + displayName: Auth + path: aodh.auth + - description: ApplicationCredentialSecret - secret name for application credential + displayName: Application Credential Secret + path: aodh.auth.applicationCredentialSecret - description: TLS - Parameters related to the TLS displayName: TLS path: aodh.tls @@ -34,6 +40,12 @@ spec: kind: Ceilometer name: ceilometers.telemetry.openstack.org specDescriptors: + - description: Auth - authentication settings for keystone integration + displayName: Auth + path: auth + - description: ApplicationCredentialSecret - secret name for application credential + displayName: Application Credential Secret + path: auth.applicationCredentialSecret - description: KSMTLS - Parameters related to the TLS for kube-state-metrics displayName: KSMTLS path: ksmTls @@ -49,6 +61,12 @@ spec: kind: CloudKitty name: cloudkitties.telemetry.openstack.org specDescriptors: + - description: Auth - authentication settings for keystone integration + displayName: Auth + path: auth + - description: ApplicationCredentialSecret - secret name for application credential + displayName: Application Credential Secret + path: auth.applicationCredentialSecret - description: TLS - Parameters related to the TLS displayName: TLS path: cloudKittyAPI.tls @@ -61,6 +79,12 @@ spec: kind: CloudKittyProc name: cloudkittyprocs.telemetry.openstack.org specDescriptors: + - description: Auth - authentication settings for keystone integration + displayName: Auth + path: auth + - description: ApplicationCredentialSecret - secret name for application credential + displayName: Application Credential Secret + path: auth.applicationCredentialSecret - description: TLS - Parameters related to the TLS displayName: TLS path: tls @@ -84,6 +108,12 @@ spec: kind: Telemetry name: telemetries.telemetry.openstack.org specDescriptors: + - description: Auth - authentication settings for keystone integration + displayName: Auth + path: autoscaling.aodh.auth + - description: ApplicationCredentialSecret - secret name for application credential + displayName: Application Credential Secret + path: autoscaling.aodh.auth.applicationCredentialSecret - description: TLS - Parameters related to the TLS displayName: TLS path: autoscaling.aodh.tls @@ -93,6 +123,12 @@ spec: path: autoscaling.enabled x-descriptors: - urn:alm:descriptor:com.tectonic.ui:booleanSwitch + - description: Auth - authentication settings for keystone integration + displayName: Auth + path: ceilometer.auth + - description: ApplicationCredentialSecret - secret name for application credential + displayName: Application Credential Secret + path: ceilometer.auth.applicationCredentialSecret - description: Enabled - Whether OpenStack Ceilometer service should be deployed and managed displayName: Enabled @@ -108,6 +144,12 @@ spec: - description: TLS - Parameters related to the TLS displayName: TLS path: ceilometer.tls + - description: Auth - authentication settings for keystone integration + displayName: Auth + path: cloudkitty.auth + - description: ApplicationCredentialSecret - secret name for application credential + displayName: Application Credential Secret + path: cloudkitty.auth.applicationCredentialSecret - description: TLS - Parameters related to the TLS displayName: TLS path: cloudkitty.cloudKittyAPI.tls diff --git a/config/samples/telemetry_v1beta1_autoscaling.yaml b/config/samples/telemetry_v1beta1_autoscaling.yaml index 4d51cf6be..bb5501762 100644 --- a/config/samples/telemetry_v1beta1_autoscaling.yaml +++ b/config/samples/telemetry_v1beta1_autoscaling.yaml @@ -15,3 +15,5 @@ spec: databaseAccount: aodh databaseInstance: openstack memcachedInstance: memcached + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services diff --git a/config/samples/telemetry_v1beta1_autoscaling_tls.yaml b/config/samples/telemetry_v1beta1_autoscaling_tls.yaml index fd176421e..e404c1cf2 100644 --- a/config/samples/telemetry_v1beta1_autoscaling_tls.yaml +++ b/config/samples/telemetry_v1beta1_autoscaling_tls.yaml @@ -15,6 +15,8 @@ spec: databaseAccount: aodh databaseInstance: openstack memcachedInstance: memcached + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services tls: api: internal: diff --git a/config/samples/telemetry_v1beta1_ceilometer.yaml b/config/samples/telemetry_v1beta1_ceilometer.yaml index fc1b573db..9ff8d37ca 100644 --- a/config/samples/telemetry_v1beta1_ceilometer.yaml +++ b/config/samples/telemetry_v1beta1_ceilometer.yaml @@ -5,3 +5,5 @@ metadata: namespace: openstack spec: secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services diff --git a/config/samples/telemetry_v1beta1_ceilometer_tls.yaml b/config/samples/telemetry_v1beta1_ceilometer_tls.yaml index 75629ff2b..53fb40e15 100644 --- a/config/samples/telemetry_v1beta1_ceilometer_tls.yaml +++ b/config/samples/telemetry_v1beta1_ceilometer_tls.yaml @@ -5,6 +5,8 @@ metadata: namespace: openstack spec: secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services tls: caBundleSecretName: combined-ca-bundle secretName: cert-ceilometer-internal-svc diff --git a/config/samples/telemetry_v1beta1_telemetry.yaml b/config/samples/telemetry_v1beta1_telemetry.yaml index b67789d8c..55a0a9ec5 100644 --- a/config/samples/telemetry_v1beta1_telemetry.yaml +++ b/config/samples/telemetry_v1beta1_telemetry.yaml @@ -21,10 +21,14 @@ spec: databaseInstance: openstack memcachedInstance: memcached secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services heatInstance: heat ceilometer: enabled: true secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services logging: enabled: false port: 10514 diff --git a/config/samples/telemetry_v1beta1_telemetry_tls.yaml b/config/samples/telemetry_v1beta1_telemetry_tls.yaml index 6722aacaa..3553e2c2f 100644 --- a/config/samples/telemetry_v1beta1_telemetry_tls.yaml +++ b/config/samples/telemetry_v1beta1_telemetry_tls.yaml @@ -24,6 +24,8 @@ spec: databaseInstance: openstack memcachedInstance: memcached secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services tls: api: internal: @@ -35,6 +37,8 @@ spec: ceilometer: enabled: true secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services tls: caBundleSecretName: combined-ca-bundle secretName: cert-ceilometer-internal-svc diff --git a/config/samples/telemetry_v1beta1_telemetry_topology.yaml b/config/samples/telemetry_v1beta1_telemetry_topology.yaml index acdb3c95c..6375db675 100644 --- a/config/samples/telemetry_v1beta1_telemetry_topology.yaml +++ b/config/samples/telemetry_v1beta1_telemetry_topology.yaml @@ -23,10 +23,14 @@ spec: databaseInstance: openstack memcachedInstance: memcached secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services heatInstance: heat ceilometer: enabled: true secret: osp-secret + notificationsBus: + cluster: rabbitmq # Required for receiving notifications from OpenStack services logging: enabled: false port: 10514 diff --git a/go.mod b/go.mod index a1f1ae984..b81eae477 100644 --- a/go.mod +++ b/go.mod @@ -9,14 +9,14 @@ require ( github.com/go-logr/logr v1.4.3 github.com/grafana/loki/operator/api/loki v0.0.0-20250910094332-a082b8a061ba github.com/k8snetworkplumbingwg/network-attachment-definition-client v1.7.7 - github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20260105161809-cf030b344d79 - github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260108154501-11e5091cddf1 - github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20260120112029-cd452f0497ba - github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20251230215914-6ba873b49a35 - github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20251230215914-6ba873b49a35 - github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35 - github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20260105160121-f7a8ef85ce8d - github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20260105171105-7cdc83d0bcd1 + github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20260126095359-39e97ca5471e + github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260126091827-7758173fbb09 + github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20260126094240-81b572e8f653 + github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20260126081203-efc2df9207eb + github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20260126081203-efc2df9207eb + github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260126081203-efc2df9207eb + github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20260124124804-c82210f7a636 + github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20260126095359-1dcdd4734763 github.com/openstack-k8s-operators/telemetry-operator/api v0.3.1-0.20240529090522-c780bd90b147 github.com/rabbitmq/cluster-operator v1.14.0 github.com/rhobs/obo-prometheus-operator/pkg/apis/monitoring v0.71.0-rhobs1 diff --git a/go.sum b/go.sum index cfb31b45c..8cffc5630 100644 --- a/go.sum +++ b/go.sum @@ -105,32 +105,32 @@ github.com/modern-go/reflect2 v1.0.3-0.20250322232337-35a7c28c31ee/go.mod h1:yWu github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo/v2 v2.27.3 h1:ICsZJ8JoYafeXFFlFAG75a7CxMsJHwgKwtO+82SE9L8= -github.com/onsi/ginkgo/v2 v2.27.3/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo= +github.com/onsi/ginkgo/v2 v2.27.4 h1:fcEcQW/A++6aZAZQNUmNjvA9PSOzefMJBerHJ4t8v8Y= +github.com/onsi/ginkgo/v2 v2.27.4/go.mod h1:ArE1D/XhNXBXCBkKOLkbsb2c81dQHCRcF5zwn/ykDRo= github.com/onsi/gomega v1.39.0 h1:y2ROC3hKFmQZJNFeGAMeHZKkjBL65mIZcvrLQBF9k6Q= github.com/onsi/gomega v1.39.0/go.mod h1:ZCU1pkQcXDO5Sl9/VVEGlDyp+zm0m1cmeG5TOzLgdh4= github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e h1:E1OdwSpqWuDPCedyUt0GEdoAE+r5TXy7YS21yNEo+2U= github.com/openshift/api v0.0.0-20250711200046-c86d80652a9e/go.mod h1:Shkl4HanLwDiiBzakv+con/aMGnVE2MAGvoKp5oyYUo= -github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20260105161809-cf030b344d79 h1:KxkelBuKUkKWfa37nQsTNcmGvJ7Jfl51LIYHlDeKh3Y= -github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20260105161809-cf030b344d79/go.mod h1:LM4ZO7tDrBZQWTQlyUAOSaDEaIRWVtWwcGMFWHYDlFQ= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260108154501-11e5091cddf1 h1:zAbZVtpldi1TU/CO9aU2ZByzcsi+N3aIv6snpSjBVLY= -github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260108154501-11e5091cddf1/go.mod h1:ZXwFlspJCdZEUjMbmaf61t5AMB4u2vMyAMMoe/vJroE= -github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20260120112029-cd452f0497ba h1:4VaDkZFawGCkzwvfijnFLz0Gduxh17buj9fIwk0WULo= -github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20260120112029-cd452f0497ba/go.mod h1:xqvebn9DqLavxp2z8Rz/7i1S6M9MJhxmZVHC+S1uHX0= -github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20251230215914-6ba873b49a35 h1:TNEUTF0Yj8qmIRgUppbzH0MuYtVcgT4+EdMdTYP/kI0= -github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20251230215914-6ba873b49a35/go.mod h1:tXxVkkk8HlATwTmDA5RTP3b+c8apfuMM15mZ2wW5iNs= -github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20251230215914-6ba873b49a35 h1:087A4QSgeXtTLrAkI5lRZhyrOxp9bRM0ivjhcwSQUUg= -github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20251230215914-6ba873b49a35/go.mod h1:DXZa8jn1R4GNDNBvKJhOFEFjg/6v8TRu9J1AHKj5TJc= -github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35 h1:pF3mJ3nwq6r4qwom+rEWZNquZpcQW/iftHlJ1KPIDsk= -github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20251230215914-6ba873b49a35/go.mod h1:kycZyoe7OZdW1HUghr2nI3N7wSJtNahXf6b/ypD14f4= +github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20260126095359-39e97ca5471e h1:0bCc5n4IBF2vkb7bh+xU+eXHFLYlyrzGBDQYjzwhm0g= +github.com/openstack-k8s-operators/heat-operator/api v0.6.1-0.20260126095359-39e97ca5471e/go.mod h1:NQxR8xE2FtkWS5rY4cZ0rLGWqme6p7UCg8MCrSiv1C0= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260126091827-7758173fbb09 h1:vhAGLKZitJIffj7ONiPpKmOX7Tmt/LGJpaY0Z2LeyfQ= +github.com/openstack-k8s-operators/infra-operator/apis v0.6.1-0.20260126091827-7758173fbb09/go.mod h1:ZXwFlspJCdZEUjMbmaf61t5AMB4u2vMyAMMoe/vJroE= +github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20260126094240-81b572e8f653 h1:WZgTxkUrXMquCJbT9ckkHwg0qwEQXR8vZb3NBz6r314= +github.com/openstack-k8s-operators/keystone-operator/api v0.6.1-0.20260126094240-81b572e8f653/go.mod h1:PDOQwlNVjHCygfqUw3k8OY1VcV/Fo6r1Fsjrdm8IhGk= +github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20260126081203-efc2df9207eb h1:35v30c6nI9WtnNnkfh4nRnC/lU9O6rM2Y8onhEAl45g= +github.com/openstack-k8s-operators/lib-common/modules/ansible v0.6.1-0.20260126081203-efc2df9207eb/go.mod h1:tXxVkkk8HlATwTmDA5RTP3b+c8apfuMM15mZ2wW5iNs= +github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20260126081203-efc2df9207eb h1:pCyizgwvB2tgFGhGtAV5rXV0kSu9l5RoR2XA+Gd5BuY= +github.com/openstack-k8s-operators/lib-common/modules/certmanager v0.6.1-0.20260126081203-efc2df9207eb/go.mod h1:chsg6x4P7376/8MlmsC3OiasuDatbOLwC5D5KRD9fbo= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260126081203-efc2df9207eb h1:S7tnYO/E1f1KQfcp7N5bam8+ax/ExDTOhZ1WqG4Bfu0= +github.com/openstack-k8s-operators/lib-common/modules/common v0.6.1-0.20260126081203-efc2df9207eb/go.mod h1:ndqfy1KbVorHH6+zlUFPIrCRhMSxO3ImYJUGaooE0x0= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20251230215914-6ba873b49a35 h1:IdcI8DFvW8rXtchONSzbDmhhRp1YyO2YaBJDBXr44Gk= github.com/openstack-k8s-operators/lib-common/modules/openstack v0.6.1-0.20251230215914-6ba873b49a35/go.mod h1:zOX7Y05keiSppIvLabuyh42QHBMhCcoskAtxFRbwXKo= github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251230215914-6ba873b49a35 h1:8WZYfCt1VJHa5sJRX0UhpmoXud/fn8LHQhXsakdYXuQ= github.com/openstack-k8s-operators/lib-common/modules/storage v0.6.1-0.20251230215914-6ba873b49a35/go.mod h1:H0aQANk8iJPRhS2Bg9n6cYb/IHF0Cks9g7+uZG04Rhk= -github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20260105160121-f7a8ef85ce8d h1:cbQpEHW404M+QBrevqh+MyrtPRUFlHTLmSAHflEth6U= -github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20260105160121-f7a8ef85ce8d/go.mod h1:X6W8pIULiWUc6smaTqiNocjxoXaRLgXediwpI/dxD9s= -github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20260105171105-7cdc83d0bcd1 h1:Fya3LwE9d1d4m4J05fJraiq442+7db/KZjY1wvA248c= -github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20260105171105-7cdc83d0bcd1/go.mod h1:LTrCp/cf4HFozb0ZhblhQKO0jUmmBnvD8zFocOsasAM= +github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20260124124804-c82210f7a636 h1:Mtjy0cc2pBdyP44/5K6TB/VxIDvtjU2EHer17JKUaLg= +github.com/openstack-k8s-operators/mariadb-operator/api v0.6.1-0.20260124124804-c82210f7a636/go.mod h1:X6W8pIULiWUc6smaTqiNocjxoXaRLgXediwpI/dxD9s= +github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20260126095359-1dcdd4734763 h1:soWH8HSuyp+ltiaeqRwD7ttPJGny/nwDRC6eu6Qt+lE= +github.com/openstack-k8s-operators/ovn-operator/api v0.6.1-0.20260126095359-1dcdd4734763/go.mod h1:ZXb5ElK2MpUScWpwHW/xx5TXkaUA3Ol8oQitslyYso8= github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec h1:saovr368HPAKHN0aRPh8h8n9s9dn3d8Frmfua0UYRlc= github.com/openstack-k8s-operators/rabbitmq-cluster-operator/v2 v2.6.1-0.20250929174222-a0d328fa4dec/go.mod h1:Nh2NEePLjovUQof2krTAg4JaAoLacqtPTZQXK6izNfg= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= diff --git a/internal/controller/autoscaling_controller.go b/internal/controller/autoscaling_controller.go index 285ac1736..d76540512 100644 --- a/internal/controller/autoscaling_controller.go +++ b/internal/controller/autoscaling_controller.go @@ -18,6 +18,7 @@ package controller import ( "context" + "errors" "fmt" "maps" "strconv" @@ -67,6 +68,9 @@ import ( autoscaling "github.com/openstack-k8s-operators/telemetry-operator/internal/autoscaling" ) +// ErrNotificationsURLSecretNotSet is returned when NotificationsURLSecret is not set in the instance status +var ErrNotificationsURLSecretNotSet = errors.New("NotificationsURLSecret is not set") + // AutoscalingReconciler reconciles a Autoscaling object type AutoscalingReconciler struct { client.Client @@ -185,7 +189,8 @@ func (r *AutoscalingReconciler) Reconcile(ctx context.Context, req ctrl.Request) condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage), condition.UnknownCondition(condition.DBReadyCondition, condition.InitReason, condition.DBReadyInitMessage), condition.UnknownCondition(condition.DBSyncReadyCondition, condition.InitReason, condition.DBSyncReadyInitMessage), - condition.UnknownCondition(condition.RabbitMqTransportURLReadyCondition, condition.InitReason, condition.RabbitMqTransportURLReadyInitMessage), + // Note: Aodh only uses NotificationsBus (no MessagingBus/RPC), so RabbitMqTransportURLReady is not needed + // NotificationBusInstanceReadyCondition handles the NotificationsBus TransportURL condition.UnknownCondition(condition.DeploymentReadyCondition, condition.InitReason, condition.DeploymentReadyInitMessage), // right now we have no dedicated KeystoneServiceReadyInitMessage condition.UnknownCondition(condition.KeystoneServiceReadyCondition, condition.InitReason, ""), @@ -325,38 +330,37 @@ func (r *AutoscalingReconciler) reconcileNormal( } // - // create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created + // create NotificationsBus TransportURL - Aodh only uses Notifications // - transportURL, op, err := r.transportURLCreateOrUpdate(instance) + notificationBusInstanceURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, instance.Spec.Aodh.NotificationsBus) if err != nil { - Log.Info("Error getting transportURL. Setting error condition on status and returning") instance.Status.Conditions.Set(condition.FalseCondition( - condition.RabbitMqTransportURLReadyCondition, + condition.NotificationBusInstanceReadyCondition, condition.ErrorReason, condition.SeverityWarning, - condition.RabbitMqTransportURLReadyErrorMessage, + condition.NotificationBusInstanceReadyErrorMessage, err.Error())) return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) + Log.Info(fmt.Sprintf("NotificationBusInstanceURL %s successfully reconciled - operation: %s", notificationBusInstanceURL.Name, string(op))) } - instance.Status.TransportURLSecret = transportURL.Status.SecretName + instance.Status.NotificationsURLSecret = ¬ificationBusInstanceURL.Status.SecretName - if instance.Status.TransportURLSecret == "" { - Log.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name)) + if instance.Status.NotificationsURLSecret == nil || *instance.Status.NotificationsURLSecret == "" { + Log.Info(fmt.Sprintf("Waiting for NotificationBusInstanceURL %s secret to be created", notificationBusInstanceURL.Name)) instance.Status.Conditions.Set(condition.FalseCondition( - condition.RabbitMqTransportURLReadyCondition, + condition.NotificationBusInstanceReadyCondition, condition.RequestedReason, condition.SeverityInfo, - condition.RabbitMqTransportURLReadyRunningMessage)) + condition.NotificationBusInstanceReadyRunningMessage)) return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } - instance.Status.Conditions.MarkTrue(condition.RabbitMqTransportURLReadyCondition, condition.RabbitMqTransportURLReadyMessage) - // end transportURL + instance.Status.Conditions.MarkTrue(condition.NotificationBusInstanceReadyCondition, condition.NotificationBusInstanceReadyMessage) + // end notificationsBus configMapVars := make(map[string]env.Setter) @@ -454,9 +458,20 @@ func (r *AutoscalingReconciler) reconcileNormal( // run check heat - end // - // check for required TransportURL secret holding transport URL string + // check for required NotificationsBus TransportURL secret holding transport URL string + // Aodh only uses NotificationsBus, not MessagingBus // - ctrlResult, err = r.getSecret(ctx, helper, instance, instance.Status.TransportURLSecret, "transport_url", &configMapVars) + if instance.Status.NotificationsURLSecret == nil || *instance.Status.NotificationsURLSecret == "" { + Log.Info("NotificationsURLSecret not yet available") + instance.Status.Conditions.Set(condition.FalseCondition( + condition.NotificationBusInstanceReadyCondition, + condition.RequestedReason, + condition.SeverityInfo, + condition.NotificationBusInstanceReadyRunningMessage)) + return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil + } + + ctrlResult, err = r.getSecret(ctx, helper, instance, *instance.Status.NotificationsURLSecret, "transport_url", &configMapVars) if err != nil { return ctrlResult, err } @@ -717,7 +732,12 @@ func (r *AutoscalingReconciler) generateServiceConfig( return err } - transportURLSecret, _, err := secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace) + // Ensure NotificationsURLSecret is not nil before dereferencing + if instance.Status.NotificationsURLSecret == nil { + return ErrNotificationsURLSecretNotSet + } + + transportURLSecret, _, err := secret.GetSecret(ctx, h, *instance.Status.NotificationsURLSecret, instance.Namespace) if err != nil { return err } @@ -799,6 +819,16 @@ func (r *AutoscalingReconciler) generateServiceConfig( // Quorum Queues templateParameters["QuorumQueues"] = string(transportURLSecret.Data["quorumqueues"]) == "true" + // Add NotificationsURL if configured + // Always get the separate notification secret since we always create separate TransportURLs + if instance.Status.NotificationsURLSecret != nil && *instance.Status.NotificationsURLSecret != "" { + notificationInstanceURLSecret, _, err := secret.GetSecret(ctx, h, *instance.Status.NotificationsURLSecret, instance.Namespace) + if err != nil { + return err + } + templateParameters["NotificationsURL"] = string(notificationInstanceURLSecret.Data["transport_url"]) + } + cms := []util.Template{ // ScriptsSecret { @@ -865,18 +895,45 @@ func (r *AutoscalingReconciler) getSecret(ctx context.Context, h *helper.Helper, return ctrl.Result{}, nil } -func (r *AutoscalingReconciler) transportURLCreateOrUpdate(instance *telemetryv1.Autoscaling) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) { +func (r *AutoscalingReconciler) transportURLCreateOrUpdate( + ctx context.Context, + instance *telemetryv1.Autoscaling, + serviceLabels map[string]string, + rabbitmqConfig *rabbitmqv1.RabbitMqConfig, +) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) { + // Aodh only uses NotificationsBus TransportURL + rmqName := fmt.Sprintf("%s-notifications-transport", autoscaling.ServiceName) + config := rabbitmqConfig + + // Prepare the spec values before CreateOrUpdate so webhooks see them during CREATE + clusterName := config.Cluster + username := config.User + vhost := config.Vhost + transportURL := &rabbitmqv1.TransportURL{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-transport", autoscaling.ServiceName), + Name: rmqName, Namespace: instance.Namespace, + Labels: serviceLabels, + }, + Spec: rabbitmqv1.TransportURLSpec{ + RabbitmqClusterName: clusterName, + Username: username, + Vhost: vhost, }, } - op, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, transportURL, func() error { - transportURL.Spec.RabbitmqClusterName = instance.Spec.Aodh.RabbitMqClusterName - err := controllerutil.SetControllerReference(instance, transportURL, r.Scheme) - return err + + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, transportURL, func() error { + transportURL.Spec.RabbitmqClusterName = clusterName + // Always set Username and Vhost to allow clearing/resetting them + // The infra-operator TransportURL controller handles empty values: + // - Empty Username: uses default cluster admin credentials + // - Empty Vhost: defaults to "/" vhost + transportURL.Spec.Username = username + transportURL.Spec.Vhost = vhost + return controllerutil.SetControllerReference(instance, transportURL, r.Scheme) }) + return transportURL, op, err } diff --git a/internal/controller/ceilometer_controller.go b/internal/controller/ceilometer_controller.go index 62593cf33..c35c2e7c8 100644 --- a/internal/controller/ceilometer_controller.go +++ b/internal/controller/ceilometer_controller.go @@ -530,39 +530,43 @@ func (r *CeilometerReconciler) reconcileCeilometer( Log := r.GetLogger(ctx) Log.Info(fmt.Sprintf(msgReconcileStart, ceilometer.ServiceName)) + serviceLabels := map[string]string{ + common.AppSelector: ceilometer.ServiceName, + common.OwnerSelector: instance.Name, + } + // - // create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created + // create NotificationsBus TransportURL - Ceilometer only uses Notifications // - transportURL, op, err := r.transportURLCreateOrUpdate(instance) + notificationBusInstanceURL, op, err := r.transportURLCreateOrUpdate(ctx, instance, serviceLabels, instance.Spec.NotificationsBus) if err != nil { - Log.Info("Error getting transportURL. Setting error condition on status and returning") instance.Status.Conditions.Set(condition.FalseCondition( - condition.RabbitMqTransportURLReadyCondition, + condition.NotificationBusInstanceReadyCondition, condition.ErrorReason, condition.SeverityWarning, - condition.RabbitMqTransportURLReadyErrorMessage, + condition.NotificationBusInstanceReadyErrorMessage, err.Error())) return ctrl.Result{}, err } if op != controllerutil.OperationResultNone { - Log.Info(fmt.Sprintf("TransportURL %s successfully reconciled - operation: %s", transportURL.Name, string(op))) + Log.Info(fmt.Sprintf("NotificationBusInstanceURL %s successfully reconciled - operation: %s", notificationBusInstanceURL.Name, string(op))) } - instance.Status.TransportURLSecret = transportURL.Status.SecretName + instance.Status.NotificationsURLSecret = ¬ificationBusInstanceURL.Status.SecretName - if instance.Status.TransportURLSecret == "" { - Log.Info(fmt.Sprintf("Waiting for TransportURL %s secret to be created", transportURL.Name)) + if instance.Status.NotificationsURLSecret == nil || *instance.Status.NotificationsURLSecret == "" { + Log.Info(fmt.Sprintf("Waiting for NotificationBusInstanceURL %s secret to be created", notificationBusInstanceURL.Name)) instance.Status.Conditions.Set(condition.FalseCondition( - condition.RabbitMqTransportURLReadyCondition, + condition.NotificationBusInstanceReadyCondition, condition.RequestedReason, condition.SeverityInfo, - condition.RabbitMqTransportURLReadyRunningMessage)) + condition.NotificationBusInstanceReadyRunningMessage)) return ctrl.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } - instance.Status.Conditions.MarkTrue(condition.RabbitMqTransportURLReadyCondition, condition.RabbitMqTransportURLReadyMessage) - // end transportURL + instance.Status.Conditions.MarkTrue(condition.NotificationBusInstanceReadyCondition, condition.NotificationBusInstanceReadyMessage) + // end notificationsBus // // check for required OpenStack secret holding passwords for service/admin user and add hash to the vars map @@ -573,15 +577,6 @@ func (r *CeilometerReconciler) reconcileCeilometer( } // run check OpenStack secret - end - // - // check for required TransportURL secret holding transport URL string - // - ctrlResult, err = r.getSecret(ctx, helper, instance, instance.Status.TransportURLSecret, "transport_url", &configMapVars) - if err != nil { - return ctrlResult, err - } - // run check TransportURL secret - end - // // check for custom configs secret secret holding custom configuration files // @@ -741,11 +736,6 @@ func (r *CeilometerReconciler) reconcileCeilometer( instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage) - serviceLabels := map[string]string{ - common.AppSelector: ceilometer.ServiceName, - common.OwnerSelector: instance.Name, - } - topology, err := ensureTopology( ctx, helper, @@ -1260,7 +1250,12 @@ func (r *CeilometerReconciler) generateServiceConfig( return err } - transportURLSecret, _, err := secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace) + // Ensure NotificationsURLSecret is not nil before dereferencing + if instance.Status.NotificationsURLSecret == nil { + return ErrNotificationsURLSecretNotSet + } + + transportURLSecret, _, err := secret.GetSecret(ctx, h, *instance.Status.NotificationsURLSecret, instance.Namespace) if err != nil { return err } @@ -1321,6 +1316,16 @@ func (r *CeilometerReconciler) generateServiceConfig( templateParameters["SwiftRole"] = true } + // Add NotificationsURL if configured + // Always get the separate notification secret since we always create separate TransportURLs + if instance.Status.NotificationsURLSecret != nil && *instance.Status.NotificationsURLSecret != "" { + notificationInstanceURLSecret, _, err := secret.GetSecret(ctx, h, *instance.Status.NotificationsURLSecret, instance.Namespace) + if err != nil { + return err + } + templateParameters["NotificationsURL"] = string(notificationInstanceURLSecret.Data["transport_url"]) + } + cms := []util.Template{ // ScriptsSecrets { @@ -1370,7 +1375,12 @@ func (r *CeilometerReconciler) generateComputeServiceConfig( return err } - transportURLSecret, _, err := secret.GetSecret(ctx, h, instance.Status.TransportURLSecret, instance.Namespace) + // Ensure NotificationsURLSecret is not nil before dereferencing + if instance.Status.NotificationsURLSecret == nil { + return ErrNotificationsURLSecretNotSet + } + + transportURLSecret, _, err := secret.GetSecret(ctx, h, *instance.Status.NotificationsURLSecret, instance.Namespace) if err != nil { return err } @@ -1682,18 +1692,52 @@ func (r *CeilometerReconciler) createHashOfInputHashes( return hash, changed, nil } -func (r *CeilometerReconciler) transportURLCreateOrUpdate(instance *telemetryv1.Ceilometer) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) { +func (r *CeilometerReconciler) transportURLCreateOrUpdate( + ctx context.Context, + instance *telemetryv1.Ceilometer, + serviceLabels map[string]string, + rabbitmqConfig *rabbitmqv1.RabbitMqConfig, +) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) { + // Ceilometer only uses NotificationsBus TransportURL + rmqName := fmt.Sprintf("%s-notifications-transport", ceilometer.ServiceName) + + // Initialize config if nil (webhook only defaults Cluster if NotificationsBus exists) + config := rabbitmqConfig + if config == nil { + config = &rabbitmqv1.RabbitMqConfig{ + Cluster: "rabbitmq", + } + } + + // Prepare the spec values before CreateOrUpdate so webhooks see them during CREATE + clusterName := config.Cluster + username := config.User + vhost := config.Vhost + transportURL := &rabbitmqv1.TransportURL{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-transport", ceilometer.ServiceName), + Name: rmqName, Namespace: instance.Namespace, + Labels: serviceLabels, + }, + Spec: rabbitmqv1.TransportURLSpec{ + RabbitmqClusterName: clusterName, + Username: username, + Vhost: vhost, }, } - op, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, transportURL, func() error { - transportURL.Spec.RabbitmqClusterName = instance.Spec.RabbitMqClusterName - err := controllerutil.SetControllerReference(instance, transportURL, r.Scheme) - return err + + op, err := controllerutil.CreateOrUpdate(ctx, r.Client, transportURL, func() error { + transportURL.Spec.RabbitmqClusterName = clusterName + // Always set Username and Vhost to allow clearing/resetting them + // The infra-operator TransportURL controller handles empty values: + // - Empty Username: uses default cluster admin credentials + // - Empty Vhost: defaults to "/" vhost + transportURL.Spec.Username = username + transportURL.Spec.Vhost = vhost + return controllerutil.SetControllerReference(instance, transportURL, r.Scheme) }) + return transportURL, op, err } diff --git a/internal/controller/cloudkitty_controller.go b/internal/controller/cloudkitty_controller.go index 8514ed250..8f183da22 100644 --- a/internal/controller/cloudkitty_controller.go +++ b/internal/controller/cloudkitty_controller.go @@ -884,8 +884,7 @@ func (r *CloudKittyReconciler) reconcileNormal(ctx context.Context, instance *te } instance.Status.Conditions.MarkTrue(condition.RabbitMqTransportURLReadyCondition, condition.RabbitMqTransportURLReadyMessage) - - // end transportURL + // end transportURL - CloudKitty only uses RPC Messaging Bus, not notifications // // Check for required memcached used for caching @@ -1375,19 +1374,37 @@ func (r *CloudKittyReconciler) transportURLCreateOrUpdate( instance *telemetryv1.CloudKitty, serviceLabels map[string]string, ) (*rabbitmqv1.TransportURL, controllerutil.OperationResult, error) { + // CloudKitty only uses messagingBus for RPC communication, not notifications + rmqName := fmt.Sprintf("%s-transport", instance.Name) + config := &instance.Spec.MessagingBus + + // Prepare the spec values before CreateOrUpdate so webhooks see them during CREATE + clusterName := config.Cluster + username := config.User + vhost := config.Vhost + transportURL := &rabbitmqv1.TransportURL{ ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-transport", instance.Name), + Name: rmqName, Namespace: instance.Namespace, Labels: serviceLabels, }, + Spec: rabbitmqv1.TransportURLSpec{ + RabbitmqClusterName: clusterName, + Username: username, + Vhost: vhost, + }, } op, err := controllerutil.CreateOrUpdate(ctx, r.Client, transportURL, func() error { - transportURL.Spec.RabbitmqClusterName = instance.Spec.RabbitMqClusterName - - err := controllerutil.SetControllerReference(instance, transportURL, r.Scheme) - return err + transportURL.Spec.RabbitmqClusterName = clusterName + // Always set Username and Vhost to allow clearing/resetting them + // The infra-operator TransportURL controller handles empty values: + // - Empty Username: uses default cluster admin credentials + // - Empty Vhost: defaults to "/" vhost + transportURL.Spec.Username = username + transportURL.Spec.Vhost = vhost + return controllerutil.SetControllerReference(instance, transportURL, r.Scheme) }) return transportURL, op, err diff --git a/templates/autoscaling/config/aodh.conf b/templates/autoscaling/config/aodh.conf index 52631f068..8c7c0ee07 100644 --- a/templates/autoscaling/config/aodh.conf +++ b/templates/autoscaling/config/aodh.conf @@ -1,6 +1,7 @@ [DEFAULT] debug=True -transport_url = {{ .TransportURL }} +# Aodh only uses Notifications, not RPC messaging +# transport_url = {{ .TransportURL }} [database] alarm_history_time_to_live=86400 @@ -25,8 +26,8 @@ enable_proxy_headers_parsing=True policy_file=/etc/aodh/policy.yaml [oslo_messaging_notifications] -driver=noop -transport_url = {{ .TransportURL }} +driver=messagingv2 +transport_url={{ .NotificationsURL }} {{ if (index . "QuorumQueues") }} [oslo_messaging_rabbit] rabbit_quorum_queue=true diff --git a/templates/ceilometercentral/config/ceilometer.conf b/templates/ceilometercentral/config/ceilometer.conf index 035664acd..accd4a536 100644 --- a/templates/ceilometercentral/config/ceilometer.conf +++ b/templates/ceilometercentral/config/ceilometer.conf @@ -5,7 +5,8 @@ debug=True log_dir=/var/log/ceilometer rpc_response_timeout=60 polling_namespaces=central -transport_url={{ .TransportURL }} +# Ceilometer only uses Notifications, not RPC messaging +# transport_url={{ .TransportURL }} [service_credentials] {{ if (index . "ACID") }} @@ -48,7 +49,7 @@ notify_address_prefix= [oslo_messaging_notifications] driver=messagingv2 topics=notifications -transport_url={{ .TransportURL }} +transport_url={{ .NotificationsURL }} {{ if (index . "QuorumQueues") }} [oslo_messaging_rabbit] rabbit_quorum_queue=true diff --git a/templates/cloudkitty/config/cloudkitty.conf b/templates/cloudkitty/config/cloudkitty.conf index 76700234d..8a68bd1d6 100644 --- a/templates/cloudkitty/config/cloudkitty.conf +++ b/templates/cloudkitty/config/cloudkitty.conf @@ -4,9 +4,14 @@ policy_file = policy.yaml [DEFAULT] auth_strategy = keystone debug = True -notification_topics = notifications +# CloudKitty uses RPC Messaging Bus, not notifications +# notification_topics = notifications transport_url = {{ .TransportURL }} +[oslo_messaging_notifications] +# CloudKitty uses the RPC Messaging Bus and never sends Notifications +driver = noop + [authinfos] debug = True {{ if (index . "ACID") }} diff --git a/test/kuttl/tests/autoscaling/01-deploy.yaml b/test/kuttl/tests/autoscaling/01-deploy.yaml index 26580dfe6..e25efe5e0 100644 --- a/test/kuttl/tests/autoscaling/01-deploy.yaml +++ b/test/kuttl/tests/autoscaling/01-deploy.yaml @@ -9,4 +9,6 @@ spec: databaseAccount: aodh databaseInstance: openstack memcachedInstance: memcached + notificationsBus: + cluster: rabbitmq heatInstance: heat diff --git a/test/kuttl/tests/autoscaling/02-custom-config-secret.yaml b/test/kuttl/tests/autoscaling/02-custom-config-secret.yaml index e94eb2c51..52a58c7ea 100644 --- a/test/kuttl/tests/autoscaling/02-custom-config-secret.yaml +++ b/test/kuttl/tests/autoscaling/02-custom-config-secret.yaml @@ -20,4 +20,6 @@ spec: databaseAccount: aodh databaseInstance: openstack memcachedInstance: memcached + notificationsBus: + cluster: rabbitmq heatInstance: heat diff --git a/test/kuttl/tests/autoscaling/deps/OpenStackControlPlane.yaml b/test/kuttl/tests/autoscaling/deps/OpenStackControlPlane.yaml index 6210b48b1..b768a695a 100644 --- a/test/kuttl/tests/autoscaling/deps/OpenStackControlPlane.yaml +++ b/test/kuttl/tests/autoscaling/deps/OpenStackControlPlane.yaml @@ -33,3 +33,5 @@ spec: heatEngine: replicas: 1 secret: osp-secret + notificationsBus: + cluster: rabbitmq diff --git a/test/kuttl/tests/ceilometer/00-deploy.yaml b/test/kuttl/tests/ceilometer/00-deploy.yaml index bd8e16524..8c12e82b7 100644 --- a/test/kuttl/tests/ceilometer/00-deploy.yaml +++ b/test/kuttl/tests/ceilometer/00-deploy.yaml @@ -6,3 +6,5 @@ spec: secret: osp-secret mysqldExporterEnabled: true ksmEnabled: true + notificationsBus: + cluster: rabbitmq diff --git a/test/kuttl/tests/ceilometer/01-custom-config-secret.yaml b/test/kuttl/tests/ceilometer/01-custom-config-secret.yaml index 913719ef6..1460dc6e9 100644 --- a/test/kuttl/tests/ceilometer/01-custom-config-secret.yaml +++ b/test/kuttl/tests/ceilometer/01-custom-config-secret.yaml @@ -15,3 +15,5 @@ metadata: spec: customConfigsSecretName: custom-config secret: osp-secret + notificationsBus: + cluster: rabbitmq diff --git a/test/kuttl/tests/cloudkitty/02-deploy.yaml b/test/kuttl/tests/cloudkitty/02-deploy.yaml index 52f2ac0d9..57d7ba095 100644 --- a/test/kuttl/tests/cloudkitty/02-deploy.yaml +++ b/test/kuttl/tests/cloudkitty/02-deploy.yaml @@ -38,7 +38,8 @@ spec: cloudKittyService: CloudKittyPassword period: 300 preserveJobs: false - rabbitMqClusterName: rabbitmq + messagingBus: + cluster: rabbitmq s3StorageConfig: schemas: - effectiveDate: "2024-11-18" diff --git a/test/kuttl/tests/cloudkitty/03-custom-config-secret.yaml b/test/kuttl/tests/cloudkitty/03-custom-config-secret.yaml index 050cb2b87..0672145b9 100644 --- a/test/kuttl/tests/cloudkitty/03-custom-config-secret.yaml +++ b/test/kuttl/tests/cloudkitty/03-custom-config-secret.yaml @@ -50,7 +50,8 @@ spec: cloudKittyService: CloudKittyPassword period: 300 preserveJobs: false - rabbitMqClusterName: rabbitmq + messagingBus: + cluster: rabbitmq s3StorageConfig: schemas: - effectiveDate: "2024-11-18" diff --git a/test/kuttl/tests/default/01-deploy.yaml b/test/kuttl/tests/default/01-deploy.yaml index 18e35fb34..4d07a804e 100644 --- a/test/kuttl/tests/default/01-deploy.yaml +++ b/test/kuttl/tests/default/01-deploy.yaml @@ -21,10 +21,14 @@ spec: databaseAccount: aodh databaseInstance: openstack memcachedInstance: memcached + notificationsBus: + cluster: rabbitmq heatInstance: heat ceilometer: enabled: true secret: osp-secret + notificationsBus: + cluster: rabbitmq cloudkitty: enabled: true s3StorageConfig: diff --git a/test/kuttl/tests/default/deps/OpenStackControlPlane.yaml b/test/kuttl/tests/default/deps/OpenStackControlPlane.yaml index 6210b48b1..b768a695a 100644 --- a/test/kuttl/tests/default/deps/OpenStackControlPlane.yaml +++ b/test/kuttl/tests/default/deps/OpenStackControlPlane.yaml @@ -33,3 +33,5 @@ spec: heatEngine: replicas: 1 secret: osp-secret + notificationsBus: + cluster: rabbitmq diff --git a/test/kuttl/tests/metricstorage/01-deploy.yaml b/test/kuttl/tests/metricstorage/01-deploy.yaml index f16d5a42f..11d2f67fa 100644 --- a/test/kuttl/tests/metricstorage/01-deploy.yaml +++ b/test/kuttl/tests/metricstorage/01-deploy.yaml @@ -22,3 +22,5 @@ metadata: spec: secret: osp-secret mysqldExporterEnabled: true + notificationsBus: + cluster: rabbitmq diff --git a/test/kuttl/tests/tls/02-deploy.yaml b/test/kuttl/tests/tls/02-deploy.yaml index 89c94a656..3cdf2180a 100644 --- a/test/kuttl/tests/tls/02-deploy.yaml +++ b/test/kuttl/tests/tls/02-deploy.yaml @@ -13,6 +13,8 @@ spec: databaseAccount: aodh databaseInstance: openstack memcachedInstance: memcached + notificationsBus: + cluster: rabbitmq tls: api: internal: @@ -28,6 +30,8 @@ metadata: name: telemetry-kuttl-ceilometer spec: secret: osp-secret + notificationsBus: + cluster: rabbitmq tls: caBundleSecretName: combined-ca-bundle secretName: cert-ceilometer-internal-svc diff --git a/test/kuttl/tests/tls/deps/OpenStackControlPlane.yaml b/test/kuttl/tests/tls/deps/OpenStackControlPlane.yaml index 6210b48b1..b768a695a 100644 --- a/test/kuttl/tests/tls/deps/OpenStackControlPlane.yaml +++ b/test/kuttl/tests/tls/deps/OpenStackControlPlane.yaml @@ -33,3 +33,5 @@ spec: heatEngine: replicas: 1 secret: osp-secret + notificationsBus: + cluster: rabbitmq diff --git a/test/kuttl/tests/topology/01-deploy.yaml b/test/kuttl/tests/topology/01-deploy.yaml index 0178f9342..94239f4e2 100644 --- a/test/kuttl/tests/topology/01-deploy.yaml +++ b/test/kuttl/tests/topology/01-deploy.yaml @@ -23,12 +23,16 @@ spec: databaseAccount: aodh databaseInstance: openstack memcachedInstance: memcached + notificationsBus: + cluster: rabbitmq heatInstance: heat ceilometer: enabled: true secret: osp-secret mysqldExporterEnabled: true ksmEnabled: true + notificationsBus: + cluster: rabbitmq cloudkitty: enabled: true s3StorageConfig: diff --git a/test/kuttl/tests/topology/deps/OpenStackControlPlane.yaml b/test/kuttl/tests/topology/deps/OpenStackControlPlane.yaml index 6210b48b1..b768a695a 100644 --- a/test/kuttl/tests/topology/deps/OpenStackControlPlane.yaml +++ b/test/kuttl/tests/topology/deps/OpenStackControlPlane.yaml @@ -33,3 +33,5 @@ spec: heatEngine: replicas: 1 secret: osp-secret + notificationsBus: + cluster: rabbitmq