Skip to content

Commit dfec387

Browse files
committed
✨ Allow title to be set on a type
Signed-off-by: Chris Bandy <[email protected]>
1 parent 9195c4d commit dfec387

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

pkg/crd/markers/validation.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ var ValidationMarkers = mustMakeAllWithPrefix(validationPrefix, markers.Describe
5252
ExclusiveMaximum(false),
5353
ExclusiveMinimum(false),
5454
MultipleOf(0),
55+
56+
// object markers
57+
5558
MinProperties(0),
5659
MaxProperties(0),
5760

@@ -61,7 +64,7 @@ var ValidationMarkers = mustMakeAllWithPrefix(validationPrefix, markers.Describe
6164
MinLength(0),
6265
Pattern(""),
6366

64-
// slice markers
67+
// array markers
6568

6669
MaxItems(0),
6770
MinItems(0),
@@ -114,9 +117,6 @@ var FieldOnlyMarkers = []*definitionWithHelp{
114117

115118
must(markers.MakeDefinition(SchemalessName, markers.DescribesField, Schemaless{})).
116119
WithHelp(Schemaless{}.Help()),
117-
118-
must(markers.MakeAnyTypeDefinition("kubebuilder:title", markers.DescribesField, Title{})).
119-
WithHelp(Title{}.Help()),
120120
}
121121

122122
// ValidationIshMarkers are field-and-type markers that don't fall under the
@@ -127,6 +127,11 @@ var ValidationIshMarkers = []*definitionWithHelp{
127127
WithHelp(XPreserveUnknownFields{}.Help()),
128128
must(markers.MakeDefinition("kubebuilder:pruning:PreserveUnknownFields", markers.DescribesType, XPreserveUnknownFields{})).
129129
WithHelp(XPreserveUnknownFields{}.Help()),
130+
131+
must(markers.MakeAnyTypeDefinition("kubebuilder:title", markers.DescribesField, Title{})).
132+
WithHelp(Title{}.Help()),
133+
must(markers.MakeAnyTypeDefinition("kubebuilder:title", markers.DescribesType, Title{})).
134+
WithHelp(Title{}.Help()),
130135
}
131136

132137
func init() {

pkg/crd/testdata/cronjob_types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,14 @@ type CronJobSpec struct {
352352
// +kubebuilder:validation:MaxLength=255
353353
StringAliasAddedValidation StringAlias `json:"stringAliasAddedValidation,omitempty"`
354354

355-
// This tests that validation on a the string alias type itself is handled correctly.
355+
// This tests that validation on a string alias type itself is handled correctly.
356356
StringAliasAlreadyValidated StringAliasWithValidation `json:"stringAliasAlreadyValidated,omitempty"`
357357

358+
// These test that title works on both a type and field, with field taking precedence.
359+
// +kubebuilder:title="title on field"
360+
StringAliasWithAddedTitle StringAliasWithTitle `json:"stringAliasWithAddedTitle,omitempty"`
361+
StringAliasWithTitle StringAliasWithTitle `json:"stringAliasWithTitle,omitempty"`
362+
358363
// This tests string slice validation.
359364
// +kubebuilder:validation:MinItems=2
360365
// +kubebuilder:validation:MaxItems=2
@@ -401,6 +406,9 @@ type EmbeddedStruct struct {
401406

402407
type StringAlias = string
403408

409+
// +kubebuilder:title="title on type"
410+
type StringAliasWithTitle = string
411+
404412
// +kubebuilder:validation:MinLength=1
405413
// +kubebuilder:validation:MaxLength=255
406414
type StringAliasWithValidation = string

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9021,13 +9021,21 @@ spec:
90219021
minLength: 1
90229022
type: string
90239023
stringAliasAlreadyValidated:
9024-
description: This tests that validation on a the string alias type
9025-
itself is handled correctly.
9024+
description: This tests that validation on a string alias type itself
9025+
is handled correctly.
90269026
maxLength: 255
90279027
minLength: 1
90289028
type: string
90299029
stringAliasPtr:
90309030
type: string
9031+
stringAliasWithAddedTitle:
9032+
description: These test that title works on both a type and field,
9033+
with field taking precedence.
9034+
title: title on field
9035+
type: string
9036+
stringAliasWithTitle:
9037+
title: title on type
9038+
type: string
90319039
stringPair:
90329040
description: This tests string slice validation.
90339041
items:

0 commit comments

Comments
 (0)