kubebuilder icon indicating copy to clipboard operation
kubebuilder copied to clipboard

[Docs] Document how to record events

Open AlmogBaku opened this issue 2 years ago • 4 comments

What do you want to happen?

Following up on: https://github.com/kubernetes-sigs/kubebuilder/issues/2684#issuecomment-1227503698

As discussed in the meeting, we think it might be a good idea to add a section about event recording to the documentation, similar to what we had in v1.

Extra Labels

No response

AlmogBaku avatar Aug 26 '22 05:08 AlmogBaku

Also, it's probably better to recommend using the controller-runtime recorder over the raw client recorder: https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/recorder/recorder.go

AlmogBaku avatar Aug 26 '22 05:08 AlmogBaku

@AlmogBaku: The label(s) /label triage/accepted cannot be applied. These labels are supported: api-review, tide/merge-method-merge, tide/merge-method-rebase, tide/merge-method-squash, team/katacoda, refactor

In response to this:

/label triage/accepted

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Aug 26 '22 05:08 k8s-ci-robot

Following is some relevant info which would be important we cover in the doc:

(IMO) we could add a warning with:

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 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.

Also, we can share 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

Then, we can also create a note to let users know that the new deploy-image plugin raises events and can be used as an example:

What is the purpose of this plugin? The deploy Image plugin allows users to scaffold API/Controllers to deploy and manage an Operand (image) on the cluster following the guidelines and best practices. It abstracts the complexities of achieving this goal while allowing users to customize the generated code. (More info). Demo: https://www.youtube.com/watch?v=UwPuRjjnMjY

Note that we have a doc in the old book version. So, we might use this content as a base and just ensure that we have the info properly updated: https://book-v1.book.kubebuilder.io/beyond_basics/creating_events.html

By last, I think we could add it under the Reference section.

camilamacedo86 avatar Sep 11 '22 15:09 camilamacedo86

I would like to work on this, /assign

mjlshen avatar Sep 12 '22 12:09 mjlshen

Hi @mjlshen,

Are you working on this one? If you need help please feel free to ping your questions into the kubebuilder slack channel.

camilamacedo86 avatar Nov 01 '22 07:11 camilamacedo86

Hi @camilamacedo86! Sorry, yes I started - then got sidetracked - will pick this up again

mjlshen avatar Nov 01 '22 12:11 mjlshen

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Feb 08 '23 11:02 k8s-triage-robot

/remove-lifecycle stale

mjlshen avatar Feb 08 '23 13:02 mjlshen

/remove-lifecycle stale

camilamacedo86 avatar Feb 08 '23 14:02 camilamacedo86

Hello @mjlshen can I take this on?

Sajiyah-Salat avatar Feb 25 '23 03:02 Sajiyah-Salat

I would like to work on this @camilamacedo86

/assign

ashutosh887 avatar Feb 25 '23 18:02 ashutosh887

@AlmogBaku Please guide me how should I proceed?

ashutosh887 avatar Feb 26 '23 09:02 ashutosh887

Hey @ashutosh887 if you want we can work together. /assign

Sajiyah-Salat avatar Feb 26 '23 11:02 Sajiyah-Salat

take a look at how I do at Raptor.ml

In general, you should inject the event recorder to the Reconciler when initializing it, then record events

AlmogBaku avatar Feb 26 '23 14:02 AlmogBaku

hello @almogBaku, in v1 docs it is given perfectly. I dont have depth so I dont know which things need to be updated. morever I have questions regarding to place a record event file. i think I should just open a pr with v1 doc record event file and after your reviews and suggestion we can make it ready for current version?

Sajiyah-Salat avatar Feb 27 '23 02:02 Sajiyah-Salat

hello @AlmogBaku, in v1 docs it is given perfectly. I dont have depth so I dont know which things need to be updated. morever I have questions regarding to place a record event file. i think I should just open a pr with v1 doc record event file and after your reviews and suggestion we can make it ready for current version?

/cc @camilamacedo86

Sajiyah-Salat avatar Mar 07 '23 11:03 Sajiyah-Salat

Yes, we can start by adding the content from v1 Then, as part of this task you should follow up the instructions to ensure that is right and/or update what is required. Also, we should let the users know and point they out that deploy image plugin scaffold will use it and can be checked as an example, see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4-with-deploy-image/cmd/main.go#L95

camilamacedo86 avatar Mar 07 '23 11:03 camilamacedo86

Sure I've started working on it @camilamacedo86 Thanks

ashutosh887 avatar Mar 13 '23 05:03 ashutosh887

Hello @ashutosh887 are you still working on this. If yes, please link the pr.

Sajiyah-Salat avatar Apr 29 '23 02:04 Sajiyah-Salat

Yes I'm willing to take this forward @Sajiyah-Salat

ashutosh887 avatar Apr 29 '23 02:04 ashutosh887

Have you made a pr

Sajiyah-Salat avatar Apr 29 '23 12:04 Sajiyah-Salat

Following is some relevant info which would be important we cover in the doc:

(IMO) we could add a warning with:

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 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.

Also, we can share 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

Then, we can also create a note to let users know that the new deploy-image plugin raises events and can be used as an example:

What is the purpose of this plugin? The deploy Image plugin allows users to scaffold API/Controllers to deploy and manage an Operand (image) on the cluster following the guidelines and best practices. It abstracts the complexities of achieving this goal while allowing users to customize the generated code. (More info). Demo: https://www.youtube.com/watch?v=UwPuRjjnMjY

Note that we have a doc in the old book version. So, we might use this content as a base and just ensure that we have the info properly updated: https://book-v1.book.kubebuilder.io/beyond_basics/creating_events.html

By last, I think we could add it under the Reference section.

The video you suggested is of v1. do you think we should add that?

Sajiyah-Salat avatar Apr 30 '23 02:04 Sajiyah-Salat

It is done : https://book.kubebuilder.io/reference/raising-events

Closing this one.

camilamacedo86 avatar Sep 06 '23 08:09 camilamacedo86