Skip to content

🌱 add webhook flags #316

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

Merged
merged 2 commits into from
Feb 28, 2025
Merged

Conversation

defo89
Copy link
Contributor

@defo89 defo89 commented Feb 14, 2025

What this PR does / why we need it:

For local development and some cases where webhooks cannot be used, adds an option via env variable to disable them.

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

Welcome @defo89!

It looks like this is your first PR to kubernetes-sigs/cluster-api-ipam-provider-in-cluster 🎉. 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/cluster-api-ipam-provider-in-cluster 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 the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 14, 2025
Copy link
Member

@hardikdr hardikdr left a comment

Choose a reason for hiding this comment

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

This is certainly useful, thanks for the PR.

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 17, 2025
@schrej
Copy link
Member

schrej commented Feb 17, 2025

I'm not sure how useful this is. If you want to disable webhooks, you'll need to delete the configuration resources from the API server. If you only disable them within the provider the API server won't be able to reach the webhooks and fail every time.
If the webhooks aren't configured on the API server, they won't be called, even when they are still served by the provider.

@hardikdr hardikdr removed their assignment Feb 17, 2025
@defo89
Copy link
Contributor Author

defo89 commented Feb 18, 2025

I'm not sure how useful this is. If you want to disable webhooks, you'll need to delete the configuration resources from the API server. If you only disable them within the provider the API server won't be able to reach the webhooks and fail every time. If the webhooks aren't configured on the API server, they won't be called, even when they are still served by the provider.

Sure, whoever is doing this needs to make sure to omit deploying the resources and not to mount the respective secret in Deployment.

@schrej
Copy link
Member

schrej commented Feb 20, 2025

What's the benefit of disabling them in the provider though? Is disabling the webhook configuration not sufficient?
Do other providers also support this?

@defo89
Copy link
Contributor Author

defo89 commented Feb 25, 2025

What's the benefit of disabling them in the provider though? Is disabling the webhook configuration not sufficient?

Yes, both controller config and not deploying webhook resources are needed to disabling webhooks. Not disabling them in the provider leads to manager shutting down due to missing cert:

2025-02-25T10:32:02.812320520Z I0225 10:32:02.812258       1 internal.go:541] "Stopping and waiting for webhooks"
2025-02-25T10:32:02.812324141Z E0225 10:32:02.812259       1 kind.go:76] "failed to get informer from cache" err="Timeout: failed waiting for *v1alpha2.GlobalInClusterIPPool Informer to sync" logger="controller-runtime.source.EventHandler"
2025-02-25T10:32:02.812349844Z I0225 10:32:02.812295       1 internal.go:544] "Stopping and waiting for HTTP servers"
2025-02-25T10:32:02.812368849Z I0225 10:32:02.812334       1 server.go:254] "Shutting down metrics server with timeout of 1 minute" logger="controller-runtime.metrics"
2025-02-25T10:32:02.812372048Z E0225 10:32:02.812338       1 kind.go:76] "failed to get informer from cache" err="Timeout: failed waiting for *v1alpha2.InClusterIPPool Informer to sync" logger="controller-runtime.source.EventHandler"
2025-02-25T10:32:02.812445698Z I0225 10:32:02.812391       1 server.go:68] "shutting down server" name="health probe" addr="[::]:8081"
2025-02-25T10:32:02.812504998Z I0225 10:32:02.812457       1 internal.go:548] "Wait completed, proceeding to shutdown the manager"
2025-02-25T10:32:02.812531217Z E0225 10:32:02.812499       1 main.go:160] "problem running manager" err="open /tmp/k8s-webhook-server/serving-certs/tls.crt: no such file or directory" logger="setup"

Do other providers also support this?

I have seen same approach in many controller and in capi providers, too. e.g.
https://github.com/linode/cluster-api-provider-linode/blob/main/cmd/main.go#L230
https://github.com/k3s-io/cluster-api-k3s/blob/main/bootstrap/main.go#L99

@schrej
Copy link
Member

schrej commented Feb 25, 2025

Fine, we can add a way to disable webhooks. Instead of some env variable, would you also be fine with adding the Webhook flags that CAPI has and use --webhook-port=0 to disable them entirely?
A consistent solution for this among all providers would be great. I personally would prefer a flag over a env variable.

	fs.IntVar(&webhookPort, "webhook-port", 9443,
		"Webhook Server port")

	fs.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
		"Webhook cert dir.")

	fs.StringVar(&webhookCertName, "webhook-cert-name", "tls.crt",
		"Webhook cert name.")

	fs.StringVar(&webhookKeyName, "webhook-key-name", "tls.key",
		"Webhook key name.")

@defo89 defo89 force-pushed the webhook-disable-env branch from 5897662 to 7df4a4a Compare February 26, 2025 15:31
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 26, 2025
@defo89
Copy link
Contributor Author

defo89 commented Feb 26, 2025

Suggested approach sounds good to me. I have updated the PR accordingly.

@defo89 defo89 changed the title 🌱 disable webhooks via env 🌱 add webhook flags Feb 27, 2025
Copy link
Member

@schrej schrej left a comment

Choose a reason for hiding this comment

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

/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Feb 28, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: schrej

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

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 28, 2025
@k8s-ci-robot k8s-ci-robot merged commit 5d5b024 into kubernetes-sigs:main Feb 28, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants