diff --git a/pkg/crd/markers/topology.go b/pkg/crd/markers/topology.go index 0f4a94b18..45f8e7e58 100644 --- a/pkg/crd/markers/topology.go +++ b/pkg/crd/markers/topology.go @@ -28,12 +28,20 @@ import ( var TopologyMarkers = []*definitionWithHelp{ must(markers.MakeDefinition("listMapKey", markers.DescribesField, ListMapKey(""))). WithHelp(ListMapKey("").Help()), + must(markers.MakeDefinition("listMapKey", markers.DescribesType, ListMapKey(""))). + WithHelp(ListMapKey("").Help()), must(markers.MakeDefinition("listType", markers.DescribesField, ListType(""))). WithHelp(ListType("").Help()), + must(markers.MakeDefinition("listType", markers.DescribesType, ListType(""))). + WithHelp(ListType("").Help()), must(markers.MakeDefinition("mapType", markers.DescribesField, MapType(""))). WithHelp(MapType("").Help()), + must(markers.MakeDefinition("mapType", markers.DescribesType, MapType(""))). + WithHelp(MapType("").Help()), must(markers.MakeDefinition("structType", markers.DescribesField, StructType(""))). WithHelp(StructType("").Help()), + must(markers.MakeDefinition("structType", markers.DescribesType, StructType(""))). + WithHelp(StructType("").Help()), } func init() { diff --git a/pkg/crd/testdata/cronjob_types.go b/pkg/crd/testdata/cronjob_types.go index 5089c9ad2..ef43d058b 100644 --- a/pkg/crd/testdata/cronjob_types.go +++ b/pkg/crd/testdata/cronjob_types.go @@ -147,14 +147,24 @@ type CronJobSpec struct { // +listMapKey=secondary AssociativeList []AssociativeType `json:"associativeList"` + // This tests that associative lists work via a nested type. + NestedAssociativeList NestedAssociativeList `json:"nestedassociativeList"` + // A map that allows different actors to manage different fields // +mapType=granular MapOfInfo map[string][]byte `json:"mapOfInfo"` + // A map that allows different actors to manage different fields via a nested type. + NestedMapOfInfo NestedMapOfInfo `json:"nestedMapOfInfo"` + // A struct that can only be entirely replaced // +structType=atomic StructWithSeveralFields NestedObject `json:"structWithSeveralFields"` + // A struct that can only be entirely replaced via a nested type. + // +structType=atomic + NestedStructWithSeveralFields NestedStructWithSeveralFields `json:"nestedStructWithSeveralFields"` + // This tests that type references are properly flattened // +kubebuilder:validation:optional JustNestedObject *JustNestedObject `json:"justNestedObject,omitempty"` @@ -267,6 +277,9 @@ type NestedObject struct { Bar bool `json:"bar"` } +// +structType=atomic +type NestedStructWithSeveralFields NestedObject + type JustNestedObject NestedObject // +kubebuilder:validation:MinProperties=1 @@ -303,6 +316,14 @@ type AssociativeType struct { Foo string `json:"foo"` } +// +listType=map +// +listMapKey=name +// +listMapKey=secondary +type NestedAssociativeList []AssociativeType + +// +mapType=granular +type NestedMapOfInfo map[string][]byte + // +kubebuilder:validation:MinLength=4 // This tests that markers that are allowed on both fields and types are applied to types type LongerString string diff --git a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml index 6c859ff85..1cb9a458a 100644 --- a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml +++ b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml @@ -7260,6 +7260,14 @@ spec: type: object description: Checks that maps containing types that contain maps work type: object + nestedMapOfInfo: + additionalProperties: + format: byte + type: string + description: A map that allows different actors to manage different + fields via a nested type. + type: object + x-kubernetes-map-type: granular nestedNestedMap: additionalProperties: additionalProperties: @@ -7269,6 +7277,41 @@ spec: type: object description: Checks that multiply-nested maps work type: object + nestedStructWithSeveralFields: + allOf: + - x-kubernetes-map-type: atomic + - x-kubernetes-map-type: atomic + description: A struct that can only be entirely replaced via a nested + type. + properties: + bar: + type: boolean + foo: + type: string + required: + - bar + - foo + type: object + nestedassociativeList: + description: This tests that associative lists work via a nested type. + items: + properties: + foo: + type: string + name: + type: string + secondary: + type: integer + required: + - foo + - name + - secondary + type: object + type: array + x-kubernetes-list-map-keys: + - name + - secondary + x-kubernetes-list-type: map noReallySuspend: description: This flag is like suspend, but for when you really mean it. It helps test the +kubebuilder:validation:Type marker. @@ -7380,6 +7423,9 @@ spec: - intWithValidations - jobTemplate - mapOfInfo + - nestedMapOfInfo + - nestedStructWithSeveralFields + - nestedassociativeList - patternObject - schedule - structWithSeveralFields