diff --git a/pkg/apis/work/v1alpha1/events.go b/pkg/apis/work/v1alpha1/events.go index e7c987829..89cb14a78 100644 --- a/pkg/apis/work/v1alpha1/events.go +++ b/pkg/apis/work/v1alpha1/events.go @@ -7,4 +7,16 @@ const ( // EventReasonSyncWorkSucceed indicates that Sync work succeed. EventReasonSyncWorkSucceed = "SyncSucceed" + + // EventReasonReflectStatusSucceed indicates that reflect status to work succeed. + EventReasonReflectStatusSucceed = "ReflectStatusSucceed" + + // EventReasonReflectStatusFailed indicates that reflect status to work failed. + EventReasonReflectStatusFailed = "ReflectStatusFailed" + + // EventReasonInterpretHealthSucceed indicates that interpret health succeed. + EventReasonInterpretHealthSucceed = "InterpretHealthSucceed" + + // EventReasonInterpretHealthFailed indicates that interpret health failed. + EventReasonInterpretHealthFailed = "InterpretHealthFailed" ) diff --git a/pkg/controllers/status/workstatus_controller.go b/pkg/controllers/status/workstatus_controller.go index 7de4f6af4..cdce88de5 100644 --- a/pkg/controllers/status/workstatus_controller.go +++ b/pkg/controllers/status/workstatus_controller.go @@ -5,6 +5,7 @@ import ( "fmt" "reflect" + corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -288,8 +289,10 @@ func (c *WorkStatusController) reflectStatus(work *workv1alpha1.Work, clusterObj if err != nil { klog.Errorf("Failed to reflect status for object(%s/%s/%s) with resourceInterpreter.", clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName(), err) + c.EventRecorder.Eventf(work, corev1.EventTypeWarning, workv1alpha1.EventReasonReflectStatusFailed, "Reflect status for object(%s/%s/%s) failed, err: %s.", clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName(), err.Error()) return err } + c.EventRecorder.Eventf(work, corev1.EventTypeNormal, workv1alpha1.EventReasonReflectStatusSucceed, "Reflect status for object(%s/%s/%s) succeed.", clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName()) if statusRaw == nil { return nil @@ -301,10 +304,13 @@ func (c *WorkStatusController) reflectStatus(work *workv1alpha1.Work, clusterObj healthy, err := c.ResourceInterpreter.InterpretHealth(clusterObj) if err != nil { resourceHealth = workv1alpha1.ResourceUnknown + c.EventRecorder.Eventf(work, corev1.EventTypeWarning, workv1alpha1.EventReasonInterpretHealthFailed, "Interpret health of object(%s/%s/%s) failed, err: %s.", clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName(), err.Error()) } else if healthy { resourceHealth = workv1alpha1.ResourceHealthy + c.EventRecorder.Eventf(work, corev1.EventTypeNormal, workv1alpha1.EventReasonInterpretHealthSucceed, "Interpret health of object(%s/%s/%s) as healthy.", clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName()) } else { resourceHealth = workv1alpha1.ResourceUnhealthy + c.EventRecorder.Eventf(work, corev1.EventTypeNormal, workv1alpha1.EventReasonInterpretHealthSucceed, "Interpret health of object(%s/%s/%s) as unhealthy.", clusterObj.GetKind(), clusterObj.GetNamespace(), clusterObj.GetName()) } identifier, err := c.buildStatusIdentifier(work, clusterObj)