-
Notifications
You must be signed in to change notification settings - Fork 726
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
Remove "all" namespace from managed namespaces #5187
Remove "all" namespace from managed namespaces #5187
Conversation
…abled, as it causes 'unknown namespace' errors in controller-runtime, and cluster-scoped resources are handled properly now in ctrl-runtime. see kubernetes-sigs/controller-runtime#1418
I don't think it makes a lot of sense to deploy several "restricted" operators and expect one of them to validate resources at the cluster level. Using a single service to validate/mutate resources is a limitation of K8S itself.
👍 we could do that as a best effort. I'm not familiar with the |
The |
As I understand the The only mechanism the webhook API has to restrict responsibility to a namespace or multiple namespaces is the So maybe it would make sense to implement the little |
Ok, I clearly made a mistake when rebasing this branch... going to try to fix this.... ignore this for now. |
Updates webhook tests to ensure behavior.
2d216fa
to
c5c3819
Compare
run full pr build |
move log line down for consistency
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.
I think we need to cover the other webhooks as well see my comments. Also something is wrong with GH web UI today I have a hard time leaving review comments that are not markup garbage, I hope I got them all fixed up now.
Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com>
Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com>
and to allow managedNamespaces in webhooks to be handled properly across all webhooks. Adjust all managed objects to use new webhook package on setup.
run full pr build |
…to query namespace. Add logging when skipping resource validation. Add additional information to 'reason' for allowing request.
I noticed the ci tests failing yesterday, and thought I resolved them all, but something is now failing in the e2e test. I'm investigating. |
…hether the given namespaces is managed.
Adjust how update is handled
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.
I think it's almost there but the upgrade validation is not working correctly.
|
||
if req.Operation == admissionv1.Update { | ||
oldObj := v.validator.DeepCopyObject() | ||
err = v.decoder.DecodeRaw(req.Object, oldObj) |
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.
err = v.decoder.DecodeRaw(req.Object, oldObj) | |
err = v.decoder.DecodeRaw(req.OldObject, oldObj) |
This is currently a NOOP validation comparing the new object with itself. This tells me that we are missing a unit test or if that's too complicated an e2e test to validate the webhook is actually validating what it is supposed to.
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.
I've fixed this in the latest commit. I will add a unit, or e2e test to ensure properly functionality next. I misread the documentation for decoder.Decode
, which state If you want decode the OldObject in the AdmissionRequest, use DecodeRaw.
...
I'll update when this test has been added.
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.
Unit test added.
Decode the old object in upgrade, not the original object.
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.
LGTM!
want admission.Response | ||
}{ | ||
{ | ||
"create properly validates valid agent, and returns allowed.", |
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.
I would be in favour of using keys in these structs instead of positional initialisation.
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.
No problem, and done. I'll merge this after ensuring all of the checks pass again.
* Don't append the 'all' namespaces when storage class validation is enabled, as it causes 'unknown namespace' errors in controller-runtime, and cluster-scoped resources are handled properly now in ctrl-runtime. see kubernetes-sigs/controller-runtime#1418 * Webhook ignores requests from namespaces that it doesn't manage Updates webhook tests to ensure behavior. * remove spaces in if err block move log line down for consistency * Move namespace validation within the Handle func to reduce duplication. * ES spelling in pkg/controller/elasticsearch/validation/webhook.go Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com> * ES spelling in pkg/controller/elasticsearch/validation/webhook.go Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com> * Use set operations to enhance readability. * Create new package to duplicate less code for setting up webhooks, and to allow managedNamespaces in webhooks to be handled properly across all webhooks. Adjust all managed objects to use new webhook package on setup. * Adjust common webhook to copy object properly, and use metav1.Object to query namespace. Add logging when skipping resource validation. Add additional information to 'reason' for allowing request. * add missing header * Check type assertion. * Ensure that the set of managed namespaces isn't all before checking whether the given namespaces is managed. * Simplify common webhook validation Adjust how update is handled * Remove debugging from webhook * Proper casing in comments. Decode the old object in upgrade, not the original object. * Adding unit tests for webhook validation. * Use keys in the webhook test structs Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com>
Don't append the 'all' namespaces when storage class validation is enabled, as it causes 'unknown namespace' errors in controller-runtime, and cluster-scoped resources are handled properly now in ctrl-runtime. This will supersede #5058, as it's a much simpler implementation to solve the same issue as the below PR better handles these types of situations in controller-runtime:
kubernetes-sigs/controller-runtime#1418
Tested with validation of storage class enabled, and successfully resized volumes from 100GB -> 200GB.
Known Issues
Validating webhooks for things such as ES PV resizing are created "unscoped"
https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/
The scope field specifies if only cluster-scoped resources ("Cluster") or namespace-scoped resources ("Namespaced") will match this rule. "∗" means that there are no scope restrictions.
This means that the webhook[s] get resources across the whole cluster, in namespaces that they do not manage, which generates the dreaded
There seems to be 2 approaches to handles this situation:
managedNamespaces
slice to webhook, and if the crud operation is outside of it's managed namespaces, allow it,which brings up the question: "How are the same webhook, with different names, all cluster scoped, and with the same rules (when having the operator installed twice in a cluster, and validating ES objects) handled? Do all have to validate, or just one?"(validated all webhooks with appropriate rules receive the request, and any can allow/deny)Namespaced
(which by looking at the operator framework docs, It wasn't clear how exactly to do this)