-
Notifications
You must be signed in to change notification settings - Fork 128
fix: handle nil chain type in FromChainToRulesArray #3131
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
base: master
Are you sure you want to change the base?
fix: handle nil chain type in FromChainToRulesArray #3131
Conversation
Hi @riccardotornesello. Thanks for your PR! I am @adamjensenbot.
Make sure this PR appears in the liqo changelog, adding one of the following labels:
|
/test |
Thanks for spotting this @riccardotornesello! Your PR should definitely fix the issue. |
Hi @fra98, I have already (partially) tried that solution, but it would not work correctly in my opinion. |
You are right that schema validation happens after the mutating webhook run.
Then the schema validation would correctly deny the resource since the type passed ( Of course, all of this holds only if we don't have a valid use case for the user to leave What do you think? |
I agree with @fra98. I would simply change that type from a pointer to a string. If the string is empty, we can return a void array and allow the validation webhook to return an error. @riccardotornesello, could you please check if this works? |
Sure @cheina97, I'll take care of that. |
Yep, we usually squash all PR commits in a single commit. |
this update solves an issue with the FirewallConfiguration's mutating webhook that returns a nil pointer exception when the Type field is omitted
2539ddd
to
c0edf42
Compare
@fra98 I modified the struct to follow the strategy you suggested. |
@riccardotornesello PR looks good (just left a minor comment). Thank you for addressing this! Unfortunately our e2e testing pipeline is broken at the moment, thus I cannot run tests. Will launch test and hopefully merge when pipeline is fixed |
pkg/liqo-controller-manager/networking/internal-network/gw-masq-bypass/leftovers.go
Outdated
Show resolved
Hide resolved
Co-authored-by: Francesco Torta <[email protected]>
Description
When applying a
FirewallConfiguration
without thetype
field in the chain, this error occurs:This happens because the mutation webhook is executed before the resource schema is validated, so the functions expect all required fields to have values, even though this is not always the case.
The error is due to the
FromChainToRulesArray
function, which performs a switch on*chain.Type
, which can sometimes benil
.To resolve the issue, the
FromChainToRulesArray
function was modified so that it returns an error ifchain
orchain.Type
arenil
. It was also necessary to modify the functions that called it in order to propagate the error.With this update, you will see this message instead:
Error stack trace
This is the error message that appears in the webhook pod logs:
Test resource
This is the resource used to generate the outputs shown above: