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
🐛 fix nil Decoder in multiValidating and multiMutating handlers by implementing DecoderInjector #1502
🐛 fix nil Decoder in multiValidating and multiMutating handlers by implementing DecoderInjector #1502
Conversation
Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA. It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.
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. I understand the commands that are listed here. |
Welcome @d-honeybadger! |
Hi @d-honeybadger. 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 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. |
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.
The fix proposed in this PR is not the only possible solution. Another one could be to switch back the order of inject.InjectorInto and cm.cluster.SetFields in
@d-honeybadger would you mind to also do that, just on the off chance that something else also relied on the order there?
/ok-to-test
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
go func() { | ||
_ = server.Start(ctx) |
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.
Please check the return
0fa8eac
to
e617f06
Compare
👍 done! |
e617f06
to
21ac80f
Compare
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
/approve
thanks!
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: alvaroaleman, d-honeybadger 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 |
…plementing DecoderInjector (kubernetes-sigs#1502) * multiValidating and multiMutating handlers implement DecoderInjector * set fields before injecting in controllerManager
TL;DR
Webhooks with
multiValidating
andmultiMutating
handlers currently fail to inject decoders into their sub-handlers, resulting in nil pointer panics. This PR is fixing it.Full description
Before the change in #1307, webhook method
webhook.InjectScheme
was called beforewebhook.InjectFunc
, meaning that decoder intstantiation was happening before injecting it bywebhook.InjectFunc
.After that PR (specifically, the changes to
controllerManager.SetFields
inpkg/manager/internal.go
) , the order has changed, and nowwebhook.InjectFunc
gets called beforewebhook.InjectScheme
, meaning that wewebhook.InjectFunc
injects anil
decoder.It appears that such re-ordering was anticipated, because in the
webhook.InjectScheme
it tries to inject decoder again, just in case, with this comment:This second attempt at decoder injection works just fine for regular webhooks, but fails if the weebhook's handler is a
multiValidating
ormultiMutating
handler, because those handlers do not implementDecoderInjector
interface.Note that for regular handlers, it is the responsibility of the user to implement
DecoderInjector
interface, but because bothmultiValidating
andmultiMutating
are unexported types, a user cannot do so for them.The fix proposed in this PR is not the only possible solution. Another one could be to switch back the order of
inject.InjectorInto
andcm.cluster.SetFields
incontroller-runtime/pkg/manager/internal.go
Line 227 in 2c238de
Link to the issue that was filed for this bug: #1487
Tagging @porridge since you were looking at that issue and @alvaroaleman as the author of the PR that re-ordered
webhook.InjectScheme
andwebhook.InjectFunc
.Happy to make any changes or implement a different fix for this bug.