Skip to content

Commit 8d80422

Browse files
authored
Merge pull request #693 from k8s-infra-cherrypick-robot/cherry-pick-692-to-release-0.9
🐛 Make topology markers also valid for type definitions
2 parents 3c8b410 + 3fe0a0c commit 8d80422

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

pkg/crd/markers/topology.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,20 @@ import (
2828
var TopologyMarkers = []*definitionWithHelp{
2929
must(markers.MakeDefinition("listMapKey", markers.DescribesField, ListMapKey(""))).
3030
WithHelp(ListMapKey("").Help()),
31+
must(markers.MakeDefinition("listMapKey", markers.DescribesType, ListMapKey(""))).
32+
WithHelp(ListMapKey("").Help()),
3133
must(markers.MakeDefinition("listType", markers.DescribesField, ListType(""))).
3234
WithHelp(ListType("").Help()),
35+
must(markers.MakeDefinition("listType", markers.DescribesType, ListType(""))).
36+
WithHelp(ListType("").Help()),
3337
must(markers.MakeDefinition("mapType", markers.DescribesField, MapType(""))).
3438
WithHelp(MapType("").Help()),
39+
must(markers.MakeDefinition("mapType", markers.DescribesType, MapType(""))).
40+
WithHelp(MapType("").Help()),
3541
must(markers.MakeDefinition("structType", markers.DescribesField, StructType(""))).
3642
WithHelp(StructType("").Help()),
43+
must(markers.MakeDefinition("structType", markers.DescribesType, StructType(""))).
44+
WithHelp(StructType("").Help()),
3745
}
3846

3947
func init() {

pkg/crd/testdata/cronjob_types.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,24 @@ type CronJobSpec struct {
143143
// +listMapKey=secondary
144144
AssociativeList []AssociativeType `json:"associativeList"`
145145

146+
// This tests that associative lists work via a nested type.
147+
NestedAssociativeList NestedAssociativeList `json:"nestedassociativeList"`
148+
146149
// A map that allows different actors to manage different fields
147150
// +mapType=granular
148151
MapOfInfo map[string][]byte `json:"mapOfInfo"`
149152

153+
// A map that allows different actors to manage different fields via a nested type.
154+
NestedMapOfInfo NestedMapOfInfo `json:"nestedMapOfInfo"`
155+
150156
// A struct that can only be entirely replaced
151157
// +structType=atomic
152158
StructWithSeveralFields NestedObject `json:"structWithSeveralFields"`
153159

160+
// A struct that can only be entirely replaced via a nested type.
161+
// +structType=atomic
162+
NestedStructWithSeveralFields NestedStructWithSeveralFields `json:"nestedStructWithSeveralFields"`
163+
154164
// This tests that type references are properly flattened
155165
// +kubebuilder:validation:optional
156166
JustNestedObject *JustNestedObject `json:"justNestedObject,omitempty"`
@@ -263,6 +273,9 @@ type NestedObject struct {
263273
Bar bool `json:"bar"`
264274
}
265275

276+
// +structType=atomic
277+
type NestedStructWithSeveralFields NestedObject
278+
266279
type JustNestedObject NestedObject
267280

268281
// +kubebuilder:validation:MinProperties=1
@@ -299,6 +312,14 @@ type AssociativeType struct {
299312
Foo string `json:"foo"`
300313
}
301314

315+
// +listType=map
316+
// +listMapKey=name
317+
// +listMapKey=secondary
318+
type NestedAssociativeList []AssociativeType
319+
320+
// +mapType=granular
321+
type NestedMapOfInfo map[string][]byte
322+
302323
// +kubebuilder:validation:MinLength=4
303324
// This tests that markers that are allowed on both fields and types are applied to types
304325
type LongerString string

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7259,6 +7259,14 @@ spec:
72597259
type: object
72607260
description: Checks that maps containing types that contain maps work
72617261
type: object
7262+
nestedMapOfInfo:
7263+
additionalProperties:
7264+
format: byte
7265+
type: string
7266+
description: A map that allows different actors to manage different
7267+
fields via a nested type.
7268+
type: object
7269+
x-kubernetes-map-type: granular
72627270
nestedNestedMap:
72637271
additionalProperties:
72647272
additionalProperties:
@@ -7268,6 +7276,41 @@ spec:
72687276
type: object
72697277
description: Checks that multiply-nested maps work
72707278
type: object
7279+
nestedStructWithSeveralFields:
7280+
allOf:
7281+
- x-kubernetes-map-type: atomic
7282+
- x-kubernetes-map-type: atomic
7283+
description: A struct that can only be entirely replaced via a nested
7284+
type.
7285+
properties:
7286+
bar:
7287+
type: boolean
7288+
foo:
7289+
type: string
7290+
required:
7291+
- bar
7292+
- foo
7293+
type: object
7294+
nestedassociativeList:
7295+
description: This tests that associative lists work via a nested type.
7296+
items:
7297+
properties:
7298+
foo:
7299+
type: string
7300+
name:
7301+
type: string
7302+
secondary:
7303+
type: integer
7304+
required:
7305+
- foo
7306+
- name
7307+
- secondary
7308+
type: object
7309+
type: array
7310+
x-kubernetes-list-map-keys:
7311+
- name
7312+
- secondary
7313+
x-kubernetes-list-type: map
72717314
noReallySuspend:
72727315
description: This flag is like suspend, but for when you really mean
72737316
it. It helps test the +kubebuilder:validation:Type marker.
@@ -7374,6 +7417,9 @@ spec:
73747417
- intWithValidations
73757418
- jobTemplate
73767419
- mapOfInfo
7420+
- nestedMapOfInfo
7421+
- nestedStructWithSeveralFields
7422+
- nestedassociativeList
73777423
- patternObject
73787424
- schedule
73797425
- structWithSeveralFields

0 commit comments

Comments
 (0)