Skip to content

Commit 03cd0b7

Browse files
authored
Merge pull request #1282 from cbandy/type-title
✨ Allow title to be set on a type
2 parents 7505e72 + dfec387 commit 03cd0b7

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
@@ -425,6 +430,9 @@ type EmbeddedStruct struct {
425430

426431
type StringAlias = string
427432

433+
// +kubebuilder:title="title on type"
434+
type StringAliasWithTitle = string
435+
428436
// +kubebuilder:validation:MinLength=1
429437
// +kubebuilder:validation:MaxLength=255
430438
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
@@ -9050,13 +9050,21 @@ spec:
90509050
minLength: 1
90519051
type: string
90529052
stringAliasAlreadyValidated:
9053-
description: This tests that validation on a the string alias type
9054-
itself is handled correctly.
9053+
description: This tests that validation on a string alias type itself
9054+
is handled correctly.
90559055
maxLength: 255
90569056
minLength: 1
90579057
type: string
90589058
stringAliasPtr:
90599059
type: string
9060+
stringAliasWithAddedTitle:
9061+
description: These test that title works on both a type and field,
9062+
with field taking precedence.
9063+
title: title on field
9064+
type: string
9065+
stringAliasWithTitle:
9066+
title: title on type
9067+
type: string
90609068
stringPair:
90619069
description: This tests string slice validation.
90629070
items:

0 commit comments

Comments
 (0)