Skip to content

Commit

Permalink
Merge pull request #837 from wawa0210/refactor-executespace-event
Browse files Browse the repository at this point in the history
refactor execute space event
  • Loading branch information
karmada-bot authored Oct 20, 2021
2 parents a6011ec + 854cac6 commit e9f4bde
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 9 additions & 0 deletions pkg/apis/cluster/v1alpha1/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1alpha1

// Define events for execute space objects.
const (
// EventReasonCreateExecutionSpaceFailed indicates that create execution space failed.
EventReasonCreateExecutionSpaceFailed = "CreateExecutionSpaceFailed"
// EventReasonRemoveExecutionSpaceFailed indicates that remove execution space failed.
EventReasonRemoveExecutionSpaceFailed = "RemoveExecutionSpaceFailed"
)
8 changes: 3 additions & 5 deletions pkg/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ const (
// sleep between retrying cluster health updates.
MonitorRetrySleepTime = 20 * time.Millisecond
// HealthUpdateRetry controls the number of retries of writing cluster health update.
HealthUpdateRetry = 5
eventReasonCreateExecutionNamespaceFailed = "CreateExecutionNamespaceFailed"
eventReasonRemoveExecutionNamespaceFailed = "RemoveExecutionNamespaceFailed"
HealthUpdateRetry = 5
)

// Controller is to sync Cluster.
Expand Down Expand Up @@ -115,7 +113,7 @@ func (c *Controller) syncCluster(cluster *clusterv1alpha1.Cluster) (controllerru
// create execution space
err := c.createExecutionSpace(cluster)
if err != nil {
c.EventRecorder.Event(cluster, corev1.EventTypeWarning, fmt.Sprintf("Failed %s", eventReasonRemoveExecutionNamespaceFailed), err.Error())
c.EventRecorder.Event(cluster, corev1.EventTypeWarning, fmt.Sprintf("Failed %s", clusterv1alpha1.EventReasonRemoveExecutionSpaceFailed), err.Error())
return controllerruntime.Result{Requeue: true}, err
}

Expand All @@ -130,7 +128,7 @@ func (c *Controller) removeCluster(cluster *clusterv1alpha1.Cluster) (controller
}
if err != nil {
klog.Errorf("Failed to remove execution space %v, err is %v", cluster.Name, err)
c.EventRecorder.Event(cluster, corev1.EventTypeWarning, fmt.Sprintf("Failed %s", eventReasonCreateExecutionNamespaceFailed), err.Error())
c.EventRecorder.Event(cluster, corev1.EventTypeWarning, fmt.Sprintf("Failed %s", clusterv1alpha1.EventReasonCreateExecutionSpaceFailed), err.Error())
return controllerruntime.Result{Requeue: true}, err
}

Expand Down

0 comments on commit e9f4bde

Please sign in to comment.