Skip to content

Commit cf0446d

Browse files
mtardytsaarni
andcommitted
pkg/crd: add a test for embedded/inline struct type alias
User tsaarni bumped into a panic when using embedded/inline field with a type alias and that Alias types are enabled in Go. They thankfully included a reproducer that is shipped in this patch from the issue #1088. Co-authored-by: Tero Saarni <[email protected]> Signed-off-by: Mahe Tardy <[email protected]>
1 parent a7ed777 commit cf0446d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pkg/crd/testdata/cronjob_types.go

+11
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,17 @@ type CronJobSpec struct {
374374

375375
// This tests that selectable field.
376376
SelectableFieldString string `json:"selectableFieldString,omitempty"`
377+
378+
// This tests that embedded struct, which is an alias type, is handled correctly.
379+
InlineAlias `json:",inline"`
380+
}
381+
382+
type InlineAlias = EmbeddedStruct
383+
384+
// EmbeddedStruct is for testing that embedded struct is handled correctly when it is used through an alias type.
385+
type EmbeddedStruct struct {
386+
// FromEmbedded is a field from the embedded struct that was used through an alias type.
387+
FromEmbedded string `json:"fromEmbedded,omitempty"`
377388
}
378389

379390
type StringAlias = string

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

+4
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ spec:
234234
Test that we can add a forbidden field using XValidation Reason and FieldPath.
235235
The validation is applied to the spec struct itself and not the field.
236236
type: integer
237+
fromEmbedded:
238+
description: FromEmbedded is a field from the embedded struct that
239+
was used through an alias type.
240+
type: string
237241
hosts:
238242
description: This tests string slice item validation.
239243
items:

0 commit comments

Comments
 (0)