From 82a53e3d0f6e2bb569e97d0c12a1860cd5944afa Mon Sep 17 00:00:00 2001 From: Alvaro Aleman Date: Tue, 20 Dec 2022 12:43:39 -0500 Subject: [PATCH] :bug: Fix the generation of listType=set It has to have x-kubernetes-map-type: atomic set. --- pkg/crd/markers/topology.go | 7 +++++++ pkg/crd/testdata/cronjob_types.go | 5 +++++ pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml | 9 ++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/crd/markers/topology.go b/pkg/crd/markers/topology.go index a92995c80..a7757152f 100644 --- a/pkg/crd/markers/topology.go +++ b/pkg/crd/markers/topology.go @@ -114,6 +114,13 @@ func (l ListType) ApplyToSchema(schema *apiext.JSONSchemaProps) error { if l != "map" && l != "atomic" && l != "set" { return fmt.Errorf(`ListType must be either "map", "set" or "atomic"`) } + + if l == "set" { + if itemSchema := schema.Items.Schema; itemSchema != nil { + v := "atomic" + itemSchema.XMapType = &v + } + } p := string(l) schema.XListType = &p return nil diff --git a/pkg/crd/testdata/cronjob_types.go b/pkg/crd/testdata/cronjob_types.go index 279b81157..c02796e6d 100644 --- a/pkg/crd/testdata/cronjob_types.go +++ b/pkg/crd/testdata/cronjob_types.go @@ -233,6 +233,11 @@ type CronJobSpec struct { // Checks that arrays work when the type contains a composite literal ArrayUsingCompositeLiteral [len(struct{ X [3]int }{}.X)]string `json:"arrayUsingCompositeLiteral,omitempty"` + + // Tests the generation of a set list type + // +listType=set + // +optional + Set []string `json:"set,omitempty"` } type ContainsNestedMap struct { diff --git a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml index ead8723de..54128b2b9 100644 --- a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml +++ b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml @@ -3,9 +3,9 @@ apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: annotations: - controller-gen.kubebuilder.io/version: (devel) api-approved.kubernetes.io: https://github.com/kubernetes-sigs/controller-tools cert-manager.io/inject-ca-from-secret: cert-manager/cert-manager-webhook-ca + controller-gen.kubebuilder.io/version: (devel) creationTimestamp: null name: cronjobs.testdata.kubebuilder.io spec: @@ -7330,6 +7330,13 @@ spec: type: string schemaless: description: This tests that the schemaless marker works + set: + description: Tests the generation of a set list type + items: + type: string + x-kubernetes-map-type: atomic + type: array + x-kubernetes-list-type: set startingDeadlineSeconds: description: Optional deadline in seconds for starting the job if it misses scheduled time for any reason. Missed jobs executions