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 9e2b90e
Show file tree
Hide file tree
Showing 3 changed files with 37 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
8 changes: 8 additions & 0 deletions pkg/crd/testdata/cronjob_types.go
Expand Up @@ -147,6 +147,9 @@ 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"`
Expand Down Expand Up @@ -303,6 +306,11 @@ type AssociativeType struct {
Foo string `json:"foo"`
}

// +listType=map
// +listMapKey=name
// +listMapKey=secondary
type NestedAssociativeList []AssociativeType

// +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
21 changes: 21 additions & 0 deletions pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
Expand Up @@ -7269,6 +7269,26 @@ spec:
type: object
description: Checks that multiply-nested maps work
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 +7400,7 @@ spec:
- intWithValidations
- jobTemplate
- mapOfInfo
- nestedassociativeList
- patternObject
- schedule
- structWithSeveralFields
Expand Down

0 comments on commit 9e2b90e

Please sign in to comment.