Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Default values and Validations in Build related CRDs #474

Open
zhangtbj opened this issue Nov 10, 2020 · 0 comments
Open

Add Default values and Validations in Build related CRDs #474

zhangtbj opened this issue Nov 10, 2020 · 0 comments

Comments

@zhangtbj
Copy link
Contributor

zhangtbj commented Nov 10, 2020

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.

              properties:
                cronSpec:
                  type: string
                  pattern: '^(\d+|\*)(/\d+)?(\s+(\d+|\*)(/\d+)?){4}$'
                  default: "5 0 * * *"
                image:
                  type: string
                replicas:
                  type: integer
                  minimum: 1
                  maximum: 10
                  default: 1
  • Then we need to see if the operator-sdk can set this kind of data and auto-generate in CRD YAML directly.

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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant