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

refactor(crds): Use built-in OpenAPI validation #5129

Merged
merged 2 commits into from
Sep 19, 2023

Conversation

jesse-c
Copy link
Contributor

@jesse-c jesse-c commented Sep 12, 2023

Part of a progressive change to use the CRD validation that's available via kubebuilder [1].

This has the benefits of us:

  • Not having to write the code for the validation, since it's generated/handled via OpenAPI
  • It's structurally/programatically available in the spec
  • Less repetition

This uses the generate suite_test.go for now [2].

[1] https://book.kubebuilder.io/reference/markers/crd-validation.html
[2] https://book.kubebuilder.io/cronjob-tutorial/writing-tests

@jesse-c jesse-c self-assigned this Sep 12, 2023
@jesse-c jesse-c force-pushed the jc/mlp-mlm-openapi-validation branch 2 times, most recently from 2254382 to 6ca6900 Compare September 12, 2023 13:34
@@ -25,42 +25,77 @@ import (
"github.com/seldonio/seldon-core/apis/go/v2/mlops/scheduler"
)

//+kubebuilder:object:root=true
Copy link
Contributor Author

@jesse-c jesse-c Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain: More conventional kubebuilder annotations to have this for both structs, and to be ordered this way. This is also the same for the new lines between fields.

// Synchronous output from this pipeline, optional
Output *PipelineOutput `json:"output,omitempty"`
}

// +kubebuilder:validation:Enum=inner;outer;any
type JoinType string

const (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain: It's not ideal that it's repeated here, but this approach seems common [1].

[1] https://github.com/search?q=%2Bkubebuilder%3Avalidation%3AEnum&type=code — e.g. Grafana, Cilium, etc.

@jesse-c jesse-c force-pushed the jc/mlp-mlm-openapi-validation branch 3 times, most recently from 2021065 to 8fd7e0e Compare September 14, 2023 09:42
@jesse-c jesse-c marked this pull request as ready for review September 14, 2023 09:48
Part of a progressive change to use the CRD validation that's
available via kubebuilder [1].

This has the benefits of us:

- Not having to write the code for the validation, since it's
generated/handled via OpenAPI
- It's structurally/programatically available in the spec
- Less repetition

[1] https://book.kubebuilder.io/reference/markers/crd-validation.html
@jesse-c jesse-c force-pushed the jc/mlp-mlm-openapi-validation branch from 8fd7e0e to be4560c Compare September 14, 2023 15:13
@jesse-c jesse-c merged commit aebc0e3 into SeldonIO:v2 Sep 19, 2023
4 of 5 checks passed
@jesse-c jesse-c deleted the jc/mlp-mlm-openapi-validation branch September 19, 2023 08:43
RemainingItemCount: nil,
},
Status: "Failure",
Message: fmt.Sprintf("Pipeline.mlops.seldon.io \"%s\" is invalid: [metadata.name: Invalid value: \"%s\": must be no more than 253 characters, metadata.name: Invalid value: \"%s\": a lowercase RFC 1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*'), spec.steps: Required value]", pipelineName, pipelineName, pipelineName),
Copy link
Contributor Author

@jesse-c jesse-c Nov 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RafalSkolasinski pushed a commit that referenced this pull request Jan 22, 2024
* refactor(crds): Use built-in OpenAPI validation

Part of a progressive change to use the CRD validation that's
available via kubebuilder [1].

This has the benefits of us:

- Not having to write the code for the validation, since it's
generated/handled via OpenAPI
- It's structurally/programatically available in the spec
- Less repetition

[1] https://book.kubebuilder.io/reference/markers/crd-validation.html
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

Successfully merging this pull request may close these issues.

2 participants