I'm currently writing a kubernetes controller, using kubernetes go-client.
I've managed to generate the OpenAPI spec for the resources managed by the controller (by running openapi-gen
and annotating types with +k8s:openapi-gen=true
).
I also want to generate validators like a maximum length or regex but I don't find any resource about how to do it.
Here is my types.go
package v1
import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +k8s:openapi-gen=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +resource:path=project
type Project struct {
meta.TypeMeta `json:",inline"`
meta.ObjectMeta `json:"metadata,omitempty"`
Domain string `json:"domain"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
type ProjectList struct {
meta.TypeMeta `json:",inline"`
meta.ListMeta `json:"metadata,omitempty"`
Items []Project `json:"items"`
}
What I'm trying to achieve is to generate the OpenAPI spec using openapi-gen
and include in the spec the following validation for the Domain
: regex [a-z]+
and maximum length of 18
.