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

✨ Webhooks for external APIs #4176

Closed
wants to merge 1 commit into from

Conversation

fischor
Copy link

@fischor fischor commented Sep 16, 2024

This is a WIP branch. But looking for feedback already.

With this PR scaffolding for core resource types will be added. Addresses #2141.

This will currently only work with core resources, not external resources per se, since a flag to describe the external Go module is missing in this PR as of now.
Currently the changes in this PR rely of this map of groups here to get the external path set if its a core resource:

if domain, found := coreGroups[res.Group]; found {

Adding a flag like --module or resource-pkg-path would make this work with general external resources.

This flag could be added as part of the Golang plugin flag set or as part of the global kubebuilder flag set.
I am unsure if adding this flag to the global kubebuilder flag set might break some plugins that never assumed they will ever have to deal with external plugins.
So adding this flag to the global kubebuilder flag set would need further discussion I think.

I also had to change the SetupWithManager method that is as of now a receiver method on the resource struct type since one can not define methods on external struct types in Go.
At the moment it looks like this:

// SetupWebhookWithManager will setup the manager to manage the webhooks.
func SetupWebhookForJobWithManager(mgr ctrl.Manager) error {
	return ctrl.NewWebhookManagedBy(mgr).
		For(&batchv1.Job{}).
		WithValidator(&JobCustomValidator{}).
		WithDefaulter(&JobCustomDefaulter{}).
		Complete()
}

It seems webhooks are going to be moved to internal/webhook anyway: #4150
Then the new schema is similiar.

A --external-api-path flag is added also in #4171 as part of the Golang plugin flag set.

Feedback welcome.
I would espacially need to know:

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 16, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fischor
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
Copy link
Contributor

Welcome @fischor!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/kubebuilder has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 16, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @fischor. 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-sigs/prow repository.

@fischor
Copy link
Author

fischor commented Sep 16, 2024

After looking at #4150, I am not sure if this PR adds any more value, since in combination with #4171 the main aspects of having an import for the API struct type and having a way to determine if a resource is external or not are already solved.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 16, 2024
)

// nolint:unused
// log is for logging in this package.
var {{ lower .Resource.Kind }}log = logf.Log.WithName("{{ lower .Resource.Kind }}-resource")

// SetupWebhookWithManager will setup the manager to manage the webhooks.
{{- if .ExternalAPI }}
func SetupWebhookFor{{ .Resource.Kind }}WithManager(mgr ctrl.Manager) error {
Copy link
Member

Choose a reason for hiding this comment

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

Those changes will not be required after : #4150

return ctrl.NewWebhookManagedBy(mgr).
{{- if .ExternalAPI }}
For(&{{ .Resource.ImportAlias }}.{{ .Resource.Kind }}{}).
Copy link
Member

Choose a reason for hiding this comment

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

Here should be if the Resource.Path is not empty

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.

Thank you a lot for looking on that.
But the changes here will be a little diff.

Add the support for Core and External types is blocked by:

After we get this merged then we can do that in more precisely way and add tests to ensure it.

Please

/hold

Copy link

@sundaram2021 sundaram2021 left a comment

Choose a reason for hiding this comment

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

Review Feedback:
Modular Flag Addition: The flag for external resources seems essential, but clarity is needed on whether it should be added globally or to the Golang plugin. Care should be taken to ensure backward compatibility.

Webhook Setup Changes: The SetupWebhookForJobWithManager function modification looks appropriate for external types, but detailed testing and validation are required to ensure seamless integration with external APIs.

Dependency on Other PRs: The PR (#4150) decoupling webhooks from APIs needs to be merged first, as the current PR's changes depend on it.

Next Steps:
Rebase on #4150 and #4171 once they are merged.
Add tests to validate external API support fully.
Collaborate on flag placement (global vs. plugin).

@camilamacedo86
Copy link
Member

Hi @fischor, @sundaram2021,

Thank you for looking into this.

We do plan to add support for this feature. However, I would suggest not spending time on it right now, as the approach we'll take will be slightly different from how it's done in this context. It will likely be addressed as a follow-up to the ongoing PR: #4176 (review). I want to ensure that no time or effort is wasted, as there are many other priorities in the project!

If you'd like to help us move forward, we'd really appreciate your assistance with reviewing this PR: #4150. This will help us reach our goal more efficiently.

Thanks! 🎉

Comment on lines +99 to +101
if p.force {
return nil
}
Copy link
Member

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 of what was implemented before.

@camilamacedo86
Copy link
Member

Hi @fischor

I think the changes here would not work
Would you like to cherry-pick the PRS #4150 #4171 and then try to achieve this goal accordingly.

See that we should add the call to generate the webhook to test it out in https://github.com/kubernetes-sigs/kubebuilder/blob/master/test/testdata/generate.sh

@fischor
Copy link
Author

fischor commented Sep 26, 2024

@camilamacedo86 Yes, that is the plan. I am waiting for these two PRs to get merged before continuing.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 1, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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.

@camilamacedo86
Copy link
Member

Hi @fischor

In order to see if we can move forward with I started the PR: #4203
Please, your help is very appreciated. Feel free to get the PR and change it as you see fit

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants