mirror of https://github.com/knative/pkg.git
Cleanup: Turn multiple warnings into multiple warnings. (#2619)
🧹 Previously we lacked a public method for turning our `apis.FieldError` multi-error into a list of constituent error messages, so when we turned things into a webhook warning we simply used the combined serialization of all of the warnings. Thanks to Nghia's recent change, we can now access the list of warnings to return as a list of errors.
/kind cleanup
This commit is contained in:
parent
728dfd8e28
commit
198b463706
|
@ -84,7 +84,10 @@ func (ac *reconciler) Admit(ctx context.Context, request *admissionv1.AdmissionR
|
|||
// below all overwrite `resp`, but the `defer` affords us one final
|
||||
// crack at things.
|
||||
defer func() {
|
||||
resp.Warnings = []string{warnings.Error()}
|
||||
resp.Warnings = make([]string, 0, len(warnings))
|
||||
for _, w := range warnings {
|
||||
resp.Warnings = append(resp.Warnings, w.Error())
|
||||
}
|
||||
}()
|
||||
}
|
||||
if errors != nil {
|
||||
|
@ -157,7 +160,7 @@ func (ac *reconciler) decodeRequestAndPrepareContext(
|
|||
return ctx, newObj, nil
|
||||
}
|
||||
|
||||
func validate(ctx context.Context, resource resourcesemantics.GenericCRD, req *admissionv1.AdmissionRequest) (err error, warn error) {
|
||||
func validate(ctx context.Context, resource resourcesemantics.GenericCRD, req *admissionv1.AdmissionRequest) (err error, warn []error) {
|
||||
logger := logging.FromContext(ctx)
|
||||
|
||||
// Only run validation for supported create and update validation.
|
||||
|
@ -187,7 +190,11 @@ func validate(ctx context.Context, resource resourcesemantics.GenericCRD, req *a
|
|||
err = errorResult
|
||||
}
|
||||
if warningResult := result.Filter(apis.WarningLevel); warningResult != nil {
|
||||
warn = warningResult
|
||||
ws := warningResult.WrappedErrors()
|
||||
warn = make([]error, 0, len(ws))
|
||||
for _, w := range ws {
|
||||
warn = append(warn, w)
|
||||
}
|
||||
}
|
||||
}
|
||||
return err, warn
|
||||
|
|
Loading…
Reference in New Issue