-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
images/kube-webhook-certgen/rootfs: add support for patching APIService objects #7641
images/kube-webhook-certgen/rootfs: add support for patching APIService objects #7641
Conversation
@invidian: This issue is currently awaiting triage. If Ingress contributors determines this is a relevant issue, they will accept it by applying the The 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. |
Hi @invidian. Thanks for your PR. I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the 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. |
/ok-to-test |
damn this is big. Thanks @invidian I will put this on my review queue ASAP! |
Initially only from some to preserve existing behavior. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
So we don't call log.Fatal in so many places, which makes code testable. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
So initialize top-level contexts in tests and CLI, then pass them around all the way down, so there is an ability e.g. to add timeouts to patch operations, if needed and to follow general conventions. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
APIService object is very similar to MutatingWebhookConfiguration and ValidatingWebhookConfiguration objects, so support for patching it shouldn't be too much of a burden. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
So old function PatchWebhookConfigurations can be unexported and CLI can be extended to also support patching APIService. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
PatchObjects should be now used instead. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
To ignore manually built binaries during development process. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
By adding a PatchConfig and Patch function, it is now possible to test logic of flag validation, which was previously tied to CLI options. This commit adds nice set of tests covering existing logic. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Those strings will be changed anyway in future commits, so at first we can properly capitalize used names. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
As logic for creating a CA certificate and patching an object is almost the same for both webhook configuration and API services, this commit adds support to kube-webhook-certgen CLI to also patch APIService objects, so they can be served over TLS as well. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
k8s.k8s.patchWebhookConfigurations() always dereferences it and we do not do a nil check, so the code may panic in some conditions, so it's safer to just pass it by value, as it's just a wrapped string. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
36229c1
to
d573087
Compare
Thanks @rikatz! I this is not super urgent or anything on my side, but it would be nice to not having it stale.
Well, code required some creative work to keep it the same, add tests to existing functionality and make it extensible for new one. Hopefully another person adding features or fixing bugs in it will have a bit easier 😅 Also rebased after #7630 merge. |
// PatchWebhookConfigurations will patch validatingWebhook and mutatingWebhook clientConfig configurations with | ||
// the provided ca data. If failurePolicy is provided, patch all webhooks with this value | ||
func (k8s *k8s) PatchWebhookConfigurations( | ||
func (k8s *k8s) patchWebhookConfigurations( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: As you are unexporting the function (still wondering why!) you should change the comment as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still wondering why
To reduce the surface of the package and to promote use of newly introduced and more flexible PatchObjects
function. Though this is a breaking change on Go module level, so I can revert this change if you like.
you should change the comment as well
Probably, but then some of my linters yell, that comment is not capitalized, so I recently just started leaving those docs as they are.
Please suggest a desired change and I'll apply it, as I don't have a preference here.
@invidian overall lgtm, cool to see this project been extended :) Some comments:
Also, I was discussing with sig-net to turn this into an independent project without success, so if you don't mind we can keep the development here. I would suggest to add you as an approver/reviewer of the code of this program (we can add you into OWNERS file after you get membership in k8s org). One last thing, maybe we want in a future to add some e2e tests into this using github actions :D Thanks |
Thanks for a timely review @rikatz, highly appreciated. It would indeed be nice to plug this code into CI to ensure no regressions, if you plan to maintain it. However, I'll need to get familiar with existing setup for the project to adopt the standards also for this sub-directory. Once we have that, we can perhaps add some e2e tests as well.
I'm happy to apply for membership and become a reviewer here, I guess there shouldn't be too much work involved. Would you like to sponsor me in that? |
Yes sure, I can sponsor you for that :) |
I'm sorry @rikatz, but I think I won't be able to add CI or e2e tests for this code. I've been doing several attempts of trying to figure out how the existing CI setup works and I find it very hard to extend in a reasonable way. I think the following points are significant here:
Note, that this is only to entry the actual test logic written in Go. I could just drop a completely independent file to Regarding the membership in K8s org, I found another sponsor, so I will be applying for it today. |
Yeah, so about the CI we need to improve it. Components are really tied. What we CAN do right now is just verify if the image builds fine, and maybe create a kind cluster just to check if things gets patched. Anyway, we can look at this as a follow up. Thanks for all the clarifications Thanks |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: invidian, rikatz 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 |
Thanks for merging!
Yeah, having it "released" would be nice :)
Sure, I'll have a look into that. |
As a follow up to PR kubernetes#7641, this commit adds some basic e2e tests for kube-webhook-certgen image. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
Created #7717 for basic CI. |
As a follow up to PR #7641, this commit adds some basic e2e tests for kube-webhook-certgen image. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
To add myself as a reviewer as discussed in kubernetes#7641. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
* OWNERS_ALIASES: add ingress-nginx-kube-webhook-certgen-reviewers For extra kube-webhook-certgen reviewers. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen: add separate owners To add myself as a reviewer as discussed in #7641. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
…ce objects (kubernetes#7641) * images/kube-webhook-certgen/rootfs/pkg/k8s: return err from functions Initially only from some to preserve existing behavior. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs: make patching return error So we don't call log.Fatal in so many places, which makes code testable. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs/pkg/k8s: require context So initialize top-level contexts in tests and CLI, then pass them around all the way down, so there is an ability e.g. to add timeouts to patch operations, if needed and to follow general conventions. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs/pkg/k8s: support patching APIService APIService object is very similar to MutatingWebhookConfiguration and ValidatingWebhookConfiguration objects, so support for patching it shouldn't be too much of a burden. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs/cmd: use new patch API So old function PatchWebhookConfigurations can be unexported and CLI can be extended to also support patching APIService. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs/pkg/k8s: unexport old patch function PatchObjects should be now used instead. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs: add .gitignore To ignore manually built binaries during development process. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs/cmd: test patching By adding a PatchConfig and Patch function, it is now possible to test logic of flag validation, which was previously tied to CLI options. This commit adds nice set of tests covering existing logic. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs/cmd: improve formatting Those strings will be changed anyway in future commits, so at first we can properly capitalize used names. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs/cmd: support patching APIService As logic for creating a CA certificate and patching an object is almost the same for both webhook configuration and API services, this commit adds support to kube-webhook-certgen CLI to also patch APIService objects, so they can be served over TLS as well. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen/rootfs: pass failure policy by value k8s.k8s.patchWebhookConfigurations() always dereferences it and we do not do a nil check, so the code may panic in some conditions, so it's safer to just pass it by value, as it's just a wrapped string. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
As a follow up to PR kubernetes#7641, this commit adds some basic e2e tests for kube-webhook-certgen image. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
) * OWNERS_ALIASES: add ingress-nginx-kube-webhook-certgen-reviewers For extra kube-webhook-certgen reviewers. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com> * images/kube-webhook-certgen: add separate owners To add myself as a reviewer as discussed in kubernetes#7641. Signed-off-by: Mateusz Gozdek <mgozdek@microsoft.com>
What this PR does / why we need it:
This PR adds ability to inject created CA bundle to APIService objects, in addition to the existing ValidatingWebhookConfiguration and MutatingWebhookConfiguration, which is helpful, e.g. when one wants to use extension API server without
insecureSkipTLSVerify: true
.This mainly allows deploying APIService in a secure way without e.g. dependency on cert-manager, which in some environments might be undesirable.
Note, that right now this PR includes changes from PR #7630.
Do note that changes to the code includes some uncommon things, like
wrappedError
struct to 100% preserve existing behavior, I didn't know if it was actually required, but at least right now they should be easier to clean up.Types of changes
How Has This Been Tested?
There is decent set of unit tests implemented and
invidian/kube-webhook-certgen:controller-v1.0.0-61-g36229c197
Docker image has been used for testing https://github.com/newrelic/helm-charts/tree/gsanchez/metrics-adapter-chart.Checklist: