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
We should also have a better way to set the Default values and related validations in our CRDs side so that we can improve our CRD definition directly.
// +kubebuilder:validation:MinLength=1 for ALL required parameters to make sure the they are not empty, like Output.ImageURL, StrategyRef.Name, Source.URL, etc...
// +kubebuilder:validation:Pattern:=((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)? for Source.URL to make sure the Git URL is a correct format
Maybe Output.ImageURL also have a kind of format to check?
BuildRef check in BuildRun
Timeout format check
etc ...
Then we can run operator-sdk generate crds, the related validations will be added in the CRD validation.openAPIV3Schema automatically, like:
image:
description: ImageURL is the URL where the image will be pushed
to.
minLength: 1
type: string
The text was updated successfully, but these errors were encountered:
We should also have a better way to set the Default values and related validations in our CRDs side so that we can improve our CRD definition directly.
After Kube 1.17, we can set the default value in CRDs, then we set some values for timeout (10mins) or revision (master), if the end-user doesn't set it: https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/#validation
We can also try to set some validations to check if the git url or image url is valid.
So we can follow the
kubebuilder:validation
style to allow operator-sdk helps us to add validation on CRDs automatically:https://book.kubebuilder.io/reference/markers/crd-validation.html
Then once the CRD is generated, validation will be added directly by:
For example, we can add:
// +kubebuilder:validation:MinLength=1
for ALLrequired
parameters to make sure the they are not empty, likeOutput.ImageURL
,StrategyRef.Name
,Source.URL
, etc...// +kubebuilder:validation:Pattern:=((git|ssh|http(s)?)|(git@[\w\.]+))(:(//)?)([\w\.@\:/\-~]+)(\.git)(/)?
forSource.URL
to make sure the Git URL is a correct formatOutput.ImageURL
also have a kind of format to check?BuildRef
check in BuildRunTimeout
format checkThen we can run
operator-sdk generate crds
, the related validations will be added in the CRDvalidation.openAPIV3Schema
automatically, like:The text was updated successfully, but these errors were encountered: