Skip to content

Commit

Permalink
Make topology markers also valid for type definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
chrischdi committed Jun 20, 2022
1 parent 529c857 commit 3ea6625
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/crd/markers/topology.go
Expand Up @@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions pkg/crd/testdata/cronjob_types.go
Expand Up @@ -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"`
Expand Down Expand Up @@ -267,6 +277,9 @@ type NestedObject struct {
Bar bool `json:"bar"`
}

// +structType=atomic
type NestedStructWithSeveralFields NestedObject

type JustNestedObject NestedObject

// +kubebuilder:validation:MinProperties=1
Expand Down Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
Expand Up @@ -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:
Expand All @@ -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.
Expand Down Expand Up @@ -7380,6 +7423,9 @@ spec:
- intWithValidations
- jobTemplate
- mapOfInfo
- nestedMapOfInfo
- nestedStructWithSeveralFields
- nestedassociativeList
- patternObject
- schedule
- structWithSeveralFields
Expand Down

0 comments on commit 3ea6625

Please sign in to comment.