Skip to content

Commit

Permalink
Add event for cluster controller
Browse files Browse the repository at this point in the history
Signed-off-by: pigletfly <[email protected]>
  • Loading branch information
pigletfly committed Oct 9, 2021
1 parent b961a7e commit 810b2ba
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pkg/controllers/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ const (
// sleep between retrying cluster health updates.
MonitorRetrySleepTime = 20 * time.Millisecond
// HealthUpdateRetry controls the number of retries of writing cluster health update.
HealthUpdateRetry = 5
HealthUpdateRetry = 5
eventTypeCreateExecutionNamespace = "CreateExecutionNamespace"
eventTypeRemoveExecutionNamespace = "RemoveExecutionNamespace"
)

// Controller is to sync Cluster.
Expand Down Expand Up @@ -113,6 +115,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", eventTypeCreateExecutionNamespace), err.Error())
return controllerruntime.Result{Requeue: true}, err
}

Expand All @@ -127,6 +130,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", eventTypeRemoveExecutionNamespace), err.Error())
return controllerruntime.Result{Requeue: true}, err
}

Expand Down Expand Up @@ -175,7 +179,7 @@ func (c *Controller) ensureRemoveExecutionSpace(cluster *clusterv1alpha1.Cluster
}

executionSpaceObj := &corev1.Namespace{}
err = c.Client.Get(context.TODO(), types.NamespacedName{Name: executionSpaceName}, executionSpaceObj)
err = c.Get(context.TODO(), types.NamespacedName{Name: executionSpaceName}, executionSpaceObj)
if apierrors.IsNotFound(err) {
klog.V(2).Infof("Removed execution space(%s)", executionSpaceName)
return false, nil
Expand Down

0 comments on commit 810b2ba

Please sign in to comment.