From 3ed472b278cfc10b5da2c58fab893d0d31cab66d Mon Sep 17 00:00:00 2001 From: Yuval Lifshitz Date: Wed, 15 Dec 2021 16:59:33 +0200 Subject: [PATCH] rgw: make notification CR events use string consts Signed-off-by: Yuval Lifshitz --- pkg/apis/ceph.rook.io/v1/types.go | 4 ++++ pkg/operator/ceph/object/notification/controller.go | 9 +++++---- pkg/operator/ceph/object/notification/controller_test.go | 8 ++++---- .../ceph/object/notification/obc_label_controller.go | 7 ++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/pkg/apis/ceph.rook.io/v1/types.go b/pkg/apis/ceph.rook.io/v1/types.go index 2080df09fef8b..dd4393c508ede 100755 --- a/pkg/apis/ceph.rook.io/v1/types.go +++ b/pkg/apis/ceph.rook.io/v1/types.go @@ -413,6 +413,10 @@ const ( ReconcileSucceeded ConditionReason = "ReconcileSucceeded" // ReconcileFailed represents when a resource reconciliation failed. ReconcileFailed ConditionReason = "ReconcileFailed" + // ReconcileStarted represents when a resource reconciliation started. + ReconcileStarted ConditionReason = "ReconcileStarted" + // Provisioned represents successfull resource allocation in Ceph + Provisioned ConditionReason = "Provisioned" // DeletingReason represents when Rook has detected a resource object should be deleted. DeletingReason ConditionReason = "Deleting" diff --git a/pkg/operator/ceph/object/notification/controller.go b/pkg/operator/ceph/object/notification/controller.go index 26ba4866a9b92..fad785c6bfd7a 100644 --- a/pkg/operator/ceph/object/notification/controller.go +++ b/pkg/operator/ceph/object/notification/controller.go @@ -32,6 +32,7 @@ import ( "github.com/rook/rook/pkg/operator/ceph/object" "github.com/rook/rook/pkg/operator/ceph/object/bucket" "github.com/rook/rook/pkg/operator/ceph/object/topic" + kapiv1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" @@ -134,7 +135,7 @@ func (r *ReconcileNotifications) reconcile(request reconcile.Request) (reconcile namespace := notification.Namespace bnName := types.NamespacedName{Namespace: namespace, Name: notification.Name} - r.recorder.Eventf(notification, "Normal", "Reconcile", "Start reconciling %q", bnName) + r.recorder.Eventf(notification, kapiv1.EventTypeNormal, string(cephv1.ReconcileStarted), "Start reconciling %q", bnName) // get the topic associated with the notification, and make sure it is provisioned topicName := types.NamespacedName{Namespace: notification.Namespace, Name: notification.Spec.Topic} bucketTopic, err := topic.GetProvisioned(r.client, r.opManagerContext, topicName) @@ -164,7 +165,7 @@ func (r *ReconcileNotifications) reconcile(request reconcile.Request) (reconcile } if len(obcList.Items) == 0 { logger.Debugf("no ObjectbucketClaim associated with CephBucketNotification %q", bnName) - r.recorder.Eventf(notification, "Normal", "Reconcile", "Finished reconciling %q", bnName) + r.recorder.Eventf(notification, kapiv1.EventTypeNormal, string(cephv1.ReconcileSucceeded), "Successfully reconciled %q", bnName) return reconcile.Result{}, nil } @@ -203,10 +204,10 @@ func (r *ReconcileNotifications) reconcile(request reconcile.Request) (reconcile if err != nil { return reconcile.Result{}, errors.Wrapf(err, "failed to provision CephBucketNotification %q for ObjectBucketClaims %q", bnName, bucketName) } - r.recorder.Eventf(notification, "Normal", "Reconcile", "Notification %q provisioned on bucket %q", bnName, bucketName) + r.recorder.Eventf(notification, kapiv1.EventTypeNormal, string(cephv1.Provisioned), "Notification %q provisioned on bucket %q", bnName, bucketName) } - r.recorder.Eventf(notification, "Normal", "Reconcile", "Finished reconciling %q", bnName) + r.recorder.Eventf(notification, kapiv1.EventTypeNormal, string(cephv1.ReconcileSucceeded), "Successfully reconciled %q", bnName) return reconcile.Result{}, nil } diff --git a/pkg/operator/ceph/object/notification/controller_test.go b/pkg/operator/ceph/object/notification/controller_test.go index 2f3ba3d1629c8..c1eca416c2627 100644 --- a/pkg/operator/ceph/object/notification/controller_test.go +++ b/pkg/operator/ceph/object/notification/controller_test.go @@ -54,10 +54,10 @@ var ( testBucketName = "my-bucket" testSCName = "my-storage-class" bnName = types.NamespacedName{Name: testNotificationName, Namespace: testNamespace} - startEvent = fmt.Sprintf("Normal Reconcile Start reconciling %q", bnName) - finishedEvent = fmt.Sprintf("Normal Reconcile Finished reconciling %q", bnName) - provisionedEvent = fmt.Sprintf("Normal Reconcile Notification %q provisioned on bucket %q", - bnName, types.NamespacedName{Namespace: testNamespace, Name: testBucketName}) + startEvent = fmt.Sprintf("%s %s Start reconciling %q", v1.EventTypeNormal, string(cephv1.ReconcileStarted), bnName) + finishedEvent = fmt.Sprintf("%s %s Successfully reconciled %q", v1.EventTypeNormal, string(cephv1.ReconcileSucceeded), bnName) + provisionedEvent = fmt.Sprintf("%s %s Notification %q provisioned on bucket %q", + v1.EventTypeNormal, string(cephv1.Provisioned), bnName, types.NamespacedName{Namespace: testNamespace, Name: testBucketName}) ) // global variables used inside mockSetup diff --git a/pkg/operator/ceph/object/notification/obc_label_controller.go b/pkg/operator/ceph/object/notification/obc_label_controller.go index 16c4c55060abf..a84fe2731884b 100644 --- a/pkg/operator/ceph/object/notification/obc_label_controller.go +++ b/pkg/operator/ceph/object/notification/obc_label_controller.go @@ -28,6 +28,7 @@ import ( opcontroller "github.com/rook/rook/pkg/operator/ceph/controller" "github.com/rook/rook/pkg/operator/ceph/object/bucket" "github.com/rook/rook/pkg/operator/ceph/object/topic" + kapiv1 "k8s.io/api/core/v1" kerrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" @@ -163,7 +164,7 @@ func (r *ReconcileOBCLabels) reconcile(request reconcile.Request) (reconcile.Res return reconcile.Result{}, errors.Wrapf(err, "failed to retrieve CephBucketNotification %q", bnName) } - r.recorder.Eventf(notification, "Normal", "Reconcile", "Start reconciling %q", bnName) + r.recorder.Eventf(notification, kapiv1.EventTypeNormal, string(cephv1.ReconcileStarted), "Start reconciling %q", bnName) // get the topic associated with the notification, and make sure it is provisioned topicName := types.NamespacedName{Namespace: notification.Namespace, Name: notification.Spec.Topic} @@ -183,8 +184,8 @@ func (r *ReconcileOBCLabels) reconcile(request reconcile.Request) (reconcile.Res return reconcile.Result{}, errors.Wrapf(err, "failed to provision CephBucketNotification %q", bnName) } logger.Infof("provisioned CephBucketNotification %q", bnName) - r.recorder.Eventf(notification, "Normal", "Reconcile", "Notification %q provisioned on bucket %q", bnName, bucketName) - r.recorder.Eventf(notification, "Normal", "Reconcile", "Finished reconciling %q", bnName) + r.recorder.Eventf(notification, kapiv1.EventTypeNormal, string(cephv1.Provisioned), "Notification %q provisioned on bucket %q", bnName, bucketName) + r.recorder.Eventf(notification, kapiv1.EventTypeNormal, string(cephv1.ReconcileSucceeded), "Successfully reconciled %q", bnName) } }