Skip to content

Commit

Permalink
Use kubebuilder items markers
Browse files Browse the repository at this point in the history
The issue kubernetes-sigs/controller-tools#342
was fixed and CRD generator now supports validation markers for array items.

This change uses items markers and removes hack used to add
max length and pattern constraints to hosts.

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov committed Apr 22, 2024
1 parent ef1803d commit 0c7bd04
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 98 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ $(GENERATED): $(CRD_TYPE_SOURCE)
bash -x ./hack/update-codegen.sh

$(GENERATED_CRD): go.mod $(GENERATED)
go run sigs.k8s.io/controller-tools/cmd/[email protected] crd:crdVersions=v1 paths=./apis/... output:crd:dir=.
# workaround to add validation to array items. Not supported by controller-gen
# ref: https://github.com/kubernetes-sigs/controller-tools/issues/342
go run hack/crd/add_hosts_validation.go $(GENERATED_CRD)
go run sigs.k8s.io/controller-tools/cmd/[email protected] crd:crdVersions=v1 paths=./apis/... output:crd:dir=.

build.local: $(LOCAL_BINARIES) $(GENERATED_CRD)
build.linux: $(LINUX_BINARIES) $(GENERATED_CRD)
Expand Down
4 changes: 4 additions & 0 deletions apis/zalando.org/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type RouteGroupList struct {
type RouteGroupSpec struct {
// List of hostnames for the RouteGroup
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:items:MaxLength=255
// +kubebuilder:validation:items:Pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
// +listType=set
Hosts []string `json:"hosts,omitempty"`
// List of backends that can be referenced in the routes
Expand Down Expand Up @@ -180,6 +182,8 @@ type RouteGroupTLSSpec struct {
// The values in this list must match the host name(s) used for
// the RouteGroup in order to terminate TLS for the host(s).
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:items:MaxLength=255
// +kubebuilder:validation:items:Pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?([.][a-z0-9]([-a-z0-9]*[a-z0-9])?)*$"
// +listType=set
Hosts []string `json:"hosts"`

Expand Down
93 changes: 0 additions & 93 deletions hack/crd/add_hosts_validation.go

This file was deleted.

3 changes: 2 additions & 1 deletion zalando.org_routegroups.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
controller-gen.kubebuilder.io/version: v0.15.0
name: routegroups.zalando.org
spec:
group: zalando.org
Expand Down

0 comments on commit 0c7bd04

Please sign in to comment.