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 11, 2023
1 parent c6501b5 commit 14a74f3
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions docs/book/src/reference/creating-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@ Following is an example of a code implementation that raises an Event.

</aside>

## How to be able to raise Events?

Following are the steps with examples to help you raise events in your controller's reconciliations.

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
### Passing the EventRecorder to the Controller

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. See that we will change the implementation scaffolded in `cmd/main.go`:

Expand All @@ -62,10 +55,17 @@ which can be created for a Controller by calling `GetRecorder(name string)` on a
}
```

c) You can check an example of the event being called in [here](https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4-with-deploy-image/controllers/memcached_controller.go#L299-L303)


### Granting the required permissions
You must also grant the RBAC rules permissions to allow your project to create Events. Therefore, ensure that you add the [RBAC][rbac-markers] into your controller:
```go
...
//+kubebuilder:rbac:groups=core,resources=events,verbs=create;patch
...
func (r *MyKindReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
```
And then, run `$ make manifests` to update the rules under `config/rbac/rule.yaml`.
</aside>
[Events]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#events

0 comments on commit 14a74f3

Please sign in to comment.