-
Notifications
You must be signed in to change notification settings - Fork 413
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
Merge existing and newly generated CRD OpenAPIv3 validation blocks #156
Comments
/cc @mengqiy @DirectXMan12 @droot |
It currently always rewrites the whole CRD. IMO having |
I agree with @mengqiy's reasoning here. Adding |
Ack. We should have validation directives to support everything. I don't think it makes sense to try and merge. |
Sounds good to me. If we can extend the supported tags to include |
@mengqiy I will submit a PR. |
@mengqiy @DirectXMan12 @droot what is meant by this code comment
Do you intend to support referencing other parsed types in |
I think that's intended to prevent recursive types from blowing out the generator. We intend to eventually support embedding validation for other types. The k/k validation parser doesn't support cross-group references, so we'd have to embed. |
@DirectXMan12 by "cross-group references" do you mean referencing validation using WDYT about having users define Go variables of type Example package v1alpha1
import (
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// ToyS3LogConfig defines logs configs using S3 backend
type ToyS3LogConfig struct {
// +kubebuilder:validation:MinLength=1
Bucket string `json:"bucket,omitempty"`
}
var toyS3LogConfigAllOfSchema = []apiextv1beta1.JSONSchemaProps{
{...},
}
// ToySpec defines the desired state of Toy
type ToySpec struct {
...
// Used this for testing fieldNames with number.
// +kubebuilder:validation:AllOf=toyS3LogConfigAllOfSchema
S3Log ToyS3LogConfig `json:"s3Log"`
...
}
type Toy struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ToySpec `json:"spec,omitempty"`
Status ToyStatus `json:"status,omitempty"`
} |
Yeah
No, I mean recursively replacing the ref with the actual type by fetching and generating a schema for that type (optionally with some overloading for certain types in k/k that don't behave as expected). See #190
That makes our parsing a lot more complicated. I'm planning to support putting validation on types instead of just fields, which makes it easier to share validation (e.g. |
Issues go stale after 90d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Stale issues rot after 30d of inactivity. If this issue is safe to close now please do so with Send feedback to sig-testing, kubernetes/test-infra and/or fejta. |
Whenever I modify a type, or add/remove/update
+kubebuilder:validation:
directives from api's inpkg/apis/<group>/<version>/*.go
, a CRD is generated with a validation block containing these changes. However if I add some validation field in a CRD that exists on-disk for an existing api, that field should be preserved in certain situations. Example:On-disk CRD:
Then write a value to some field manually, ex.
spec.validation.openAPIV3Shema.properties.spec.properties.size.title = "foo bar"
.Desired CRD after generation:
As far as I can tell, the CRD generator will overwrite the
title
field, even though there is no+kubebuilder:validation:Title
annotation according to the kubebuilder book. Is it possible to support persisting fields added manually, i.e. merge old and new CRD's, if:+kubebuilder:validation:
directive for that fieldThe text was updated successfully, but these errors were encountered: