Skip to content

Commit

Permalink
Update creating-events.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajiyah-Salat committed May 7, 2023
1 parent 5f61b4b commit cadcc42
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions docs/book/src/reference/creating-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,20 @@ It is often useful to publish *Event* objects from the controller Reconcile func

Events allow users to see what is going on with a particular object, and allow automated processes to see and respond to them.

{% panel style="success", title="Getting Events" %}
Recent Events for an object can be viewed by running `kubectl describe`
{% endpanel %}

{% method %}

###how to implement the solution to raise an event:
Recent Events for an object can be viewed by running `kubectl describe`

### how to implement the solution to raise an event:

a) You need to pass the recorder when you set up the recorder for the controller when the event will be raised see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4-with-deploy-image/main.go#L103
b) You need to add the makers to add the RBAC permissions to allow your Operator/controller to raise the event see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4-with-deploy-image/controllers/memcached_controller.go#L66 and run make manifests
c) You can check an example of the event being called in: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4-with-deploy-image/controllers/memcached_controller.go#L299-L303

Events are published from a Controller using an [EventRecorder](https://github.com/kubernetes/client-go/blob/master/tools/record/event.go#L56),
Events are published from a Controller using an [EventRecorder]`type CorrelatorOptions struct`,
which can be created for a Controller by calling `GetRecorder(name string)` on a Manager.

`Name` should be identifiable and descriptive as it will appear in the `From` column of `kubectl describe` command.

{% sample lang="go" %}
```go
// Annotation for generating RBAC role for writing Events
// +kubebuilder:rbac:groups="",resources=events,verbs=create;patch
Expand All @@ -45,9 +41,9 @@ func newReconciler(mgr manager.Manager) reconcile.Reconciler {
}
}
```
{% endmethod %}

{% method %}

## Writing Events

Expand All @@ -65,7 +61,7 @@ Event(object runtime.Object, eventtype, reason, message string)

Building on the example introduced in [Controller Example](../basics/simple_controller.md), we can add Events to our reconcile logic using `recorder` as our `EventRecorder`

{% sample lang="go" %}
```go
//Reconcile logic up here...

Expand Down Expand Up @@ -104,6 +100,7 @@ Building on the example introduced in [Controller Example](../basics/simple_cont
return reconcile.Result{}, nil
}
```
Events should be raised in certain circumstances only and following this guideline acctually is not a good practice. See what the Kubernetes APIs convention describes when using them [here](https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#events)
Events should be raised in certain circumstances only and following this guideline acctually is not a good practice. See what the Kubernetes APIs convention describes when using them [here][Events]
Note that is NOT recommended to emit events for all Operations. If authors raise too many events it brings bad UX experiences for those that are consuming the solutions on the cluster and they will not have attention to what they actually must be notified.
{% endmethod %}

[Events]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#events

0 comments on commit cadcc42

Please sign in to comment.