Skip to content

MultiValidatingHandler returns as soon as one handler fails, making it impossible to follow convention of reporting all validation errors #3203

Open
@dlipovetsky

Description

@dlipovetsky

The prevailing convention in Kubernetes resource validation is to report all validation errors, not only the first discovered error. The built-in API types follow this convention (example). The OpenAPI and CEL rule validation follows this convention, too. Most webhooks I have seen also follow it.

We provide a utility function for webhook authors that executes multiple validators:

// MultiValidatingHandler combines multiple validating webhook handlers into a single
// validating webhook handler. Handlers are called in sequential order, and the first
// `allowed: false` response may short-circuit the rest.
func MultiValidatingHandler(handlers ...Handler) Handler {
return multiValidating(handlers)
}

It returns as soon as one validator fails. That means that subsequent validators are not called, and any errors they might discover are not reported.

I think we should provide an alternative implementation that calls all validators, even if some fail, and aggregates their errors.

Also, because the existing utility function does not follow the convention, I think we should consider deprecating it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions