You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request]: Support "Warning" for Validation Webhook #1896
Warnings for validation webhook would bring much help for users with interacting with API.
Currently, users of controller-runtime could implement their "customized" admission.Handler to respond with "warnings". But it's might be not easy to use. Also as mentioned in #1788, using util to wrap warning messages might be helpful. IMHO, controller-runtime should support warning "natively" with Validator and CustomValidator.
I am interested in this feature/enhancement, so maybe there are possible designs and steps to build this feature:
extend Allowed(), Denied(), ValidationResponse(), make them support warning []string
bring an interface to extend error, called ErrorWithWarnings like:
it means it user want to respond with warning, it should return this interface with ValidateXXX()
make type assertion when resolving the error from Validator/CustomValidator, fill Warnings in v1.AdmissionResponse
Some changes might break the existing API, I think it's OK to controller-runtime. If not, I could still try to only introduce new API without breaking the exist one.
Reacted by Max Brauer, Antoine Cordier, Ouahid Khelifi, Shu Kutsuzawa and Justin Garrison
Emm... I don't really understand. Handler implementation just has to define a func Handle(context.Context, Request) Response and its response could also use the WithWarnings.
Oh, you mean expose the Warnings in the Validator/CustomValidator interfaces? In this way, we should not only expose the Warnings, but the Response with its fields like Warnings, ErrorCode, Reason.
Warning is not considered right now, so I think maybe we could use a similar way. :)
One different thing is a user might want only to respond "warnings" without "error". I realized that my original design might not work well with this situation, because it could not resolve the error is nil.
Maybe make changes on Validator interface (or another interface ValidatorWarning) are required:
I realized that my original design might not work well with this situation, because it could not resolve the error is nil.
We could resolve that right? If the error is an ErrorWithWarnings we can use the embedded error as the "real" error, and that one can be nil while warnings is not.
If the returned error is not an ErrorWithWarnings, then we have the "real" error directly with no warnings.
Hm, after skimming the conversation I am actually in favor of breaking the interface over making it hard to use in the context of warnings by having to return a specific error type. It will be a visible break that is easy to fix.
The only comment I have on the suggestion in #1896 (comment) regarding how that would look like is that errors per golang convention should always be the last return parameter.
Reacted by Stefan Büringer, Fabrizio Pandini and Zhiqiang ZHOU
I am actually in favor of breaking the interface over making it hard to use in the context of warnings by having to return a specific error type. It will be a visible break that is easy to fix.
I realized that my original design might not work well with this situation, because it could not resolve the error is nil.
We could resolve that right? If the error is an ErrorWithWarnings we can use the embedded error as the "real" error, and that one can be nil while warnings is not.
If the returned error is not an ErrorWithWarnings, then we have the "real" error directly with no warnings.
No. I do not think we could resolve that, because ErrorWithWarnings is an interface(which composes an error interface), not a struct(which embeds an error instance). We could not return a result that carries the "warnings" and also introduces "error is nil" at the same time
Hm, after skimming the conversation I am actually in favor of breaking the interface over making it hard to use in the context of warnings by having to return a specific error type. It will be a visible break that is easy to fix.
The only comment I have on the suggestion in #1896 (comment) regarding how that would look like is that errors per golang convention should always be the last return parameter.
I would update the PR soon!
Reacted by Stefan Büringer, Antoine Cordier and Antoine Mouliere
Activity
STRRL commentedon May 10, 2022
what do you think? If you are not satisfied with this design, I am very happy to make it better. :)
/cc @FillZpp @vincepri @alvaroaleman
FillZpp commentedon May 10, 2022
@STRRL Thanks. Does the existing
WithWarningsfunction not satisfy the requirement?controller-runtime/pkg/webhook/admission/response.go
Lines 116 to 121 in 26c95ad
We can use it with any response like
Allowed(),Denied()orValidationResponse(). For exampleSTRRL commentedon May 10, 2022
Ohh, I missed that method. That would help a lot. We do not require the first step in my original design. ❤️
But the user still needs to implement
Handlerinstead ofValidatorandCustomValidator, I think maybe introducingErrorWithWarningsstill makes sense.FillZpp commentedon May 10, 2022
Emm... I don't really understand.
Handlerimplementation just has to define a funcHandle(context.Context, Request) Responseand its response could also use theWithWarnings.STRRL commentedon May 10, 2022
I think it's better also support waning on high-level API
Validator/CustomValidatorbased on the provided low-level APIResponse.WithWarnings. :)FillZpp commentedon May 10, 2022
Oh, you mean expose the
Warningsin theValidator/CustomValidatorinterfaces? In this way, we should not only expose theWarnings, but theResponsewith its fields likeWarnings,ErrorCode,Reason.controller-runtime/pkg/webhook/admission/validator.go
Lines 30 to 35 in 26c95ad
controller-runtime/pkg/webhook/admission/validator_custom.go
Lines 31 to 35 in 26c95ad
That's ok to me. But I'm not sure if the API change is necessary. WDYT @alvaroaleman @vincepri
STRRL commentedon May 10, 2022
ErrorCode,Reasoncould be carried withapierrors.APIStatus:controller-runtime/pkg/webhook/admission/validator.go
Lines 71 to 78 in b826f39
Warningis not considered right now, so I think maybe we could use a similar way. :)One different thing is a user might want only to respond "warnings" without "error". I realized that my original design might not work well with this situation, because it could not resolve the error is nil.
Maybe make changes on
Validatorinterface (or another interfaceValidatorWarning) are required:k8s-triage-robot commentedon Aug 8, 2022
The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/lifecycle rotten/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
invidian commentedon Aug 8, 2022
/remove-lifecycle stale
STRRL commentedon Oct 4, 2022
Hi @invidian , I create a PR for resolve this issue, PTAL ❤️
STRRL commentedon Oct 5, 2022
also cc @FillZpp
joelanford commentedon Nov 8, 2022
We could resolve that right? If the error is an
ErrorWithWarningswe can use the embedded error as the "real" error, and that one can benilwhile warnings is not.If the returned error is not an
ErrorWithWarnings, then we have the "real" error directly with no warnings.sbueringer commentedon Nov 25, 2022
@joelanford's suggestion sounds good to me
I think we have one fundamental choice to make and then everything follows from there:
@alvaroaleman @vincepri Sorry for the ping, I know you're pretty busy. What is your opinion on that?
P.S. Does 2. come down to the same as #1788?
alvaroaleman commentedon Nov 25, 2022
Hm, after skimming the conversation I am actually in favor of breaking the interface over making it hard to use in the context of warnings by having to return a specific error type. It will be a visible break that is easy to fix.
The only comment I have on the suggestion in #1896 (comment) regarding how that would look like is that errors per golang convention should always be the last return parameter.
sbueringer commentedon Nov 26, 2022
Sounds good to me!
fabriziopandini commentedon Nov 28, 2022
+1
STRRL commentedon Dec 5, 2022
No. I do not think we could resolve that, because
ErrorWithWarningsis aninterface(which composes anerrorinterface), not astruct(which embeds anerrorinstance). We could not return a result that carries the "warnings" and also introduces "error is nil" at the same timeSTRRL commentedon Dec 5, 2022
I would update the PR soon!
k8s-triage-robot commentedon Mar 5, 2023
The Kubernetes project currently lacks enough contributors to adequately respond to all issues.
This bot triages un-triaged issues according to the following rules:
lifecycle/staleis appliedlifecycle/stalewas applied,lifecycle/rottenis appliedlifecycle/rottenwas applied, the issue is closedYou can:
/remove-lifecycle stale/closePlease send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
invidian commentedon Mar 5, 2023
/remove-lifecycle stale