Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

📖 update webhooks for core types to match controller-runtime v0.15 #3399

Closed
wants to merge 1 commit into from

Conversation

mythi
Copy link

@mythi mythi commented May 9, 2023

Fixes: #3393

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels May 9, 2023
@k8s-ci-robot
Copy link
Contributor

Hi @mythi. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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 k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 9, 2023
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mythi,

I am not sure if I understand this changes.
See that the Handler still existing for 0.15.0: https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/webhook/admission#Handler

The only breaking change that I saw is that now we have admission.Warnings in the method signature, see:

https://github.com/kubernetes-sigs/kubebuilder/pull/3444/files#diff-c157b03fcfe4b2116022e44c782e84f45db09e5e1488e2061c9007e37e634c48R119-R124

This change should be in placed in the docs as well for master since after we do the changes we must to run make generate and then the docs are updated.

So, do we still needing this PR?

@mythi
Copy link
Author

mythi commented Jun 14, 2023

@camilamacedo86 I believe it's still needed. pkg/inject is also removed so the example makes the webhook to crash. This moves the book to use the builder approach following the CR change and my fixes

mythi referenced this pull request in kubernetes-sigs/controller-runtime Jun 14, 2023
Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
@mythi
Copy link
Author

mythi commented Jun 20, 2023

@camilamacedo86 anything I can/need to do here?

@camilamacedo86
Copy link
Member

camilamacedo86 commented Jun 20, 2023

Hi @mythi,

@camilamacedo86 anything I can/need to do here?

By using the master branch and checking the samples code in the master, what issues are you still face?
Can you list them out and let us know what changes are required then, I can help you with where then should be made.

I believe it's still needed. pkg/inject is also removed so the example makes the webhook to crash.

We do not use sigs.k8s.io/controller-runtime/pkg/runtime/inject.
However, if we need to change something it seems that it must be done in. the default scaffolds.
So, can you let us know when you create a project, then api and a webhook what is wrong?

@mythi
Copy link
Author

mythi commented Jun 21, 2023

So, can you let us know when you create a project, then api and a webhook what is wrong?

@camilamacedo86 hmm but this PR is not about the scaffolding process but this page https://book.kubebuilder.io/reference/webhook-for-core-types.html which is wrong.

@camilamacedo86
Copy link
Member

Hi @mythi,

@camilamacedo86 hmm but this PR is not about the scaffolding process but this page https://book.kubebuilder.io/reference/webhook-for-core-types.html which is wrong.

It seems make sense. When it no longer be a draft could you please either ping in the slack so that we won a help from the community in the review?

@camilamacedo86
Copy link
Member

@erikgb

I think you are very skilled in this area, could you please give a hand in the review of this PR?

Copy link
Contributor

@erikgb erikgb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mythi! This looks good! A couple of suggestions/nits, but none of them should block this PR from being merged.

docs/book/src/reference/webhook-for-core-types.md Outdated Show resolved Hide resolved

## Update main.go

Now you need to register your handler in the webhook server.

```go
mgr.GetWebhookServer().Register("/mutate-v1-pod", &webhook.Admission{Handler: &podAnnotator{Client: mgr.GetClient()}})
if err := builder.WebhookManagedBy(mgr).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a func to podAnnotator to set it up with Manager - as we do for controllers?

func (r *podAnnotator) SetupWithManager(mgr ctrl.Manager) error

IMO the code will be easier to read. An advanced user can always in-line it...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIU, the same is covered by the new snippet. That is used with:

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{})
...
if err := builder.WebhookManagedBy(mgr).
...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but if using kubebuilder to create the webhook, I think it will generate a SetupWithManager func.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but if using kubebuilder to create the webhook, I think it will generate a SetupWithManager func.

@erikgb is correct. For example, see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4/api/v1/captain_webhook.go

Even though they do the same thing, I agree that for the Kubebuilder documentation we should ensure we are accurately reflecting what is scaffolded by default by Kubebuilder.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ack, will look into it

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be covered now. apologies for the silence!

@mythi mythi marked this pull request as ready for review July 15, 2023 18:59
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mythi
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 15, 2023
@mythi mythi changed the title 📖 update webhooks for core types to match cr 0.15 📖 update webhooks for core types to match controller-runtime v0.15 Jul 15, 2023
@mythi
Copy link
Author

mythi commented Aug 16, 2023

@erikgb @camilamacedo86 the review comments are addressed, and this is ready for another review

@erikgb
Copy link
Contributor

erikgb commented Aug 17, 2023

/ok-to-test
/lgtm

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 17, 2023
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 17, 2023
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 13, 2023
@k8s-triage-robot
Copy link

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-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jan 21, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active 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 rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

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

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Mar 2, 2024
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 4, 2024
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@mythi
Copy link
Author

mythi commented Mar 4, 2024

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Mar 4, 2024
@mythi mythi force-pushed the cr-0.15 branch 2 times, most recently from f66aa72 to 3781a81 Compare March 4, 2024 11:59
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 22, 2024
return admission.Errored(http.StatusInternalServerError, err)
}
return admission.PatchResponseFromRaw(req.Object.Raw, marshaledPod)
return nil
Copy link
Member

@camilamacedo86 camilamacedo86 Apr 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before it could return an error because it was patching the value
so, if an error were faced it will be returned now I am not sure if we we are patching the value.
Did you tested it out?

It seems that it is not doing the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you tested it out?

The code is same as in https://github.com/kubernetes-sigs/controller-runtime/blob/76d3d0826fa9dca267c70c68c706f6de40084043/examples/builtins/mutatingwebhook.go so I'm assuming it's tested by controller-runtime. FWIW, my own webhook follows the same flow also.

Copy link
Member

@camilamacedo86 camilamacedo86 Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the same
Before it was use the client to perform the changes on the cluster side and return its result (nil OR error)
Now, it adds the value to the pod, do nothing and return nil always

Also, we are changing how to do.
So, anyway, for any tutorial example we should test things out, ensure that it is right.
Could you please test this one?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not the same

I'm pretty sure it's the same. I just copied the Default() func and compared with what is in this file and there are no functional changes.

Copy link
Member

@camilamacedo86 camilamacedo86 Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the example that we have here does

marshaledPod, err := json.Marshal(pod)
	if err != nil {
		return admission.Errored(http.StatusInternalServerError, err)
	}
	return admission.PatchResponseFromRaw(req.Object.Raw, marshaledPod)

It would not add too much value just have the sample controller-runtime right?
Would still possible to do the same with the new changes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would not add too much value just have the sample controller-runtime right?

That's how it's been. I'm just a messenger and making the same changes that controller-runtime has between controller-runtime release-0.14 and release-0.15.

Copy link
Member

@camilamacedo86 camilamacedo86 Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mythi

Sure, and we appreciate it a lot.
What I am trying to say is that we should update the doc to keep the same example that we have before but now addressing the controller-runtime changes. That would provide more value than change the current example to copy and paste an example from there.

So that we could ensure that we are able to do the same but in another way and that the example that we have is valid.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would provide more value than change the current example to copy and paste an example from there.

What I tried to say was that the current example is also a copy and paste and that the diff here is how controller-runtime addressed their changes in the example. I kinda understand what you're asking me to change but the counterargument is why would we want to diverge from the example given elsewhere (especially since we used to be aligned).

Signed-off-by: Mikko Ylinen <mikko.ylinen@intel.com>
@drewwells
Copy link

drewwells commented Apr 19, 2024

Would love to see docs updated. The example code works nicely, but the docs are misleading (to me). They don't align with the code example.

@mythi
Copy link
Author

mythi commented Apr 20, 2024

The example code works nicely, but the docs are misleading (to me). They don't align with the code example.

Just to clarify: when you say "example", you mean the controller-runtime example the book points to? This PR is exactly about getting those aligned.

@camilamacedo86
Copy link
Member

camilamacedo86 commented Apr 20, 2024

HI @mythi

How, we should change this doc?

  • Just ensure that the current example provided in the docs (same kubebuilder example) will be changed to address breakchanges
  • Ensure that the example provide can properly work and matches with kubebuilder layout by creating a project and checking it out

We should not:

  • Copy and paste the examples from controller-runtime (it does not bring value for the users, if we want to use their example we can just link it. Make no sense we duplicate things) Furthermore, just copy a controller-runtime in the doc does not mean that will work. We must to describe to users how to do the same with Kubebuilder layout, describe the steps, and ensure that the info provided is accurate.
  • Change the example in away that it does not work with the default kubebuilder layout or not fits well on it.
  • Change the logic of the example provided without any good reason to do so.

I hope that clarifies.

@mythi
Copy link
Author

mythi commented Apr 22, 2024

We should not:

I don't think the current example meets any of these bullets either. However, if that is desired, we could close this and someone can pick up re-writing this page according to the new ask.

@k8s-ci-robot
Copy link
Contributor

@mythi: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-27-10 7bbc5f5 link true /test pull-kubebuilder-e2e-k8s-1-27-10
pull-kubebuilder-e2e-k8s-1-28-6 7bbc5f5 link true /test pull-kubebuilder-e2e-k8s-1-28-6
pull-kubebuilder-e2e-k8s-1-29-0 7bbc5f5 link true /test pull-kubebuilder-e2e-k8s-1-29-0
pull-kubebuilder-e2e-k8s-1-28-0 3781a81 link true /test pull-kubebuilder-e2e-k8s-1-28-0
pull-kubebuilder-e2e-k8s-1-30-0 2db6ee6 link true /test pull-kubebuilder-e2e-k8s-1-30-0

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-sigs/prow repository. I understand the commands that are listed here.

@camilamacedo86 camilamacedo86 added the help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. label May 24, 2024
@mythi mythi closed this Aug 21, 2024
@camilamacedo86
Copy link
Member

Hi @mythi

See: #4061
I tried to address those changes.

@mythi
Copy link
Author

mythi commented Aug 22, 2024

Hi @mythi

See: #4061 I tried to address those changes.

Yeah I saw that. I think it has problems with the markers and perhaps mention when to use one over the other. Other than that looks fine

@camilamacedo86
Copy link
Member

HI @mythi

Yeah I saw that. I think it has problems with the markers and perhaps mention when to use one over the other. Other than that looks fine

Not sure if I can follow up.
But please, feel free to review the PR and add your inputs there.
Your collab is very welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update Webhook For Core Types for CR 0.15
7 participants