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

Controller-gen crd doesn't allow to override the type of a field with multiple types #735

Closed
juanluisvaladas opened this issue Nov 22, 2022 · 1 comment

Comments

@juanluisvaladas
Copy link

Currently a field in a struct can override its type with the marker +kubebuilder:validation:Type=<type>. I have a use case where I want to allow multiple types such as boolean and string. This could be achieved by defining the Parser's Schemata as:

apiext.JSONSchemaProps{
	AnyOf: []apiext.JSONSchemaProps{
		{Type: "boolean"},
		{Type: "string"},
	},
}

And it's currently done in the types k8s.io/apimachinery/pkg/api/resource.Quantity and k8s.io/apimachinery/pkg/util/intstr.IntOrString. However this is hardcoded and very limiting.

What I propose is adding a new validation marker called types which works by defining +kubebuilder:validation:Types=<Type1>[;Type2[;Type3...]]

I'm aware of #461 but I don't think they are mutually exclusive and I'm pretty sure that I can implement this in a reasonable amount of time.

@juanluisvaladas
Copy link
Author

I'm closing this issue as I don´t think this is actually feasible without making big changes in the schema validation. I don´t see a way to do this without changing fundamental aspects of it which I doubt the community would accept.

The schema validator skips a bunch of validations in the event of IntOrString so even if the schema is generated correctly the apiserver will not accept it anyway.

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