Skip to content

Commit

Permalink
rgw: make notification CR events use string consts
Browse files Browse the repository at this point in the history
Signed-off-by: Yuval Lifshitz <ylifshit@redhat.com>
  • Loading branch information
yuvalif committed Dec 15, 2021
1 parent 5d069c3 commit 570f09e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/ceph.rook.io/v1/types.go
Expand Up @@ -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 successful resource allocation in Ceph
Provisioned ConditionReason = "Provisioned"

// DeletingReason represents when Rook has detected a resource object should be deleted.
DeletingReason ConditionReason = "Deleting"
Expand Down
9 changes: 5 additions & 4 deletions pkg/operator/ceph/object/notification/controller.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/operator/ceph/object/notification/controller_test.go
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions pkg/operator/ceph/object/notification/obc_label_controller.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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}
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 570f09e

Please sign in to comment.