-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Proposal : centralize validations / checks between cli, api & builder #13824
Description
As discussed a little bit on there #10409 (and more other issues and IRC I guess), we might want to have a package to handle validations that could be used in all builder, api and cli. I'm quoting @cpuguy83. An example is the following issue : #13821 where the check is done in cli and not at all in the API part of it ; leading to unwanted behavior.
What we could do is have an actual validator that gets checked before a container is even attempted to be created, and make sure that validation happens for each user input (builder, api, cli), and that it's all the same validator, since right now it's all over the place.
I propose to have a pkg/validation that would centralize validations and ease maintaining this as it gets updated. Not sure the name pkg/validation is the right one but..
I'm thinking of a way to make it as easy and flexible as possible but do not have a final idea in the head. In the current state of thinking I had (which is still pretty small), I was thinking we could have some sort of struct where we could set the context of the validation (cli, api, builder). The validation method would skip things or do differently depending on the context ; something roughly like the following.
// Have a way to get/build it easily
cliValidator := validators.ForCli()
builderValidator := validators.ForAPI()
// Same method on both
cliValidator.ValidateTagName(…, …)
builderValidator.ValidateTagName(…, …)
// Method
func (v *Validator) ValidateTageName(…) error {
// Do some common validation
if isCli(v) {
// Do some cli-only specific validation
}
if isAPI(v) {
// Do some API-only validation
}
// Do some more common validation
}It's really rough and I'm still looking for information, opinion, critics 😉. Any input is more than welcome 😝.
If it feels we want to implement this, it should probably be cut in several PR (for the general way to do this, and for each type of validations : volumes, repository/tag name, …), but I'm probably way ahead of myself here 😅.