Skip to content

Commit cce03d2

Browse files
authored
Merge pull request #753 from kubernetes-sigs/fix-generation-of-sets
🐛 Fix the generation of listType=set
2 parents 521024d + 82a53e3 commit cce03d2

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

pkg/crd/markers/topology.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ func (l ListType) ApplyToSchema(schema *apiext.JSONSchemaProps) error {
114114
if l != "map" && l != "atomic" && l != "set" {
115115
return fmt.Errorf(`ListType must be either "map", "set" or "atomic"`)
116116
}
117+
118+
if l == "set" {
119+
if itemSchema := schema.Items.Schema; itemSchema != nil {
120+
v := "atomic"
121+
itemSchema.XMapType = &v
122+
}
123+
}
117124
p := string(l)
118125
schema.XListType = &p
119126
return nil

pkg/crd/testdata/cronjob_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ type CronJobSpec struct {
233233

234234
// Checks that arrays work when the type contains a composite literal
235235
ArrayUsingCompositeLiteral [len(struct{ X [3]int }{}.X)]string `json:"arrayUsingCompositeLiteral,omitempty"`
236+
237+
// Tests the generation of a set list type
238+
// +listType=set
239+
// +optional
240+
Set []string `json:"set,omitempty"`
236241
}
237242

238243
type ContainsNestedMap struct {

pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: (devel)
76
api-approved.kubernetes.io: https://github.com/kubernetes-sigs/controller-tools
87
cert-manager.io/inject-ca-from-secret: cert-manager/cert-manager-webhook-ca
8+
controller-gen.kubebuilder.io/version: (devel)
99
creationTimestamp: null
1010
name: cronjobs.testdata.kubebuilder.io
1111
spec:
@@ -7330,6 +7330,13 @@ spec:
73307330
type: string
73317331
schemaless:
73327332
description: This tests that the schemaless marker works
7333+
set:
7334+
description: Tests the generation of a set list type
7335+
items:
7336+
type: string
7337+
x-kubernetes-map-type: atomic
7338+
type: array
7339+
x-kubernetes-list-type: set
73337340
startingDeadlineSeconds:
73347341
description: Optional deadline in seconds for starting the job if
73357342
it misses scheduled time for any reason. Missed jobs executions

0 commit comments

Comments
 (0)