From aa7ab678e1b85a6babdc1bade9171303d85a4b72 Mon Sep 17 00:00:00 2001 From: Joe Kralicky Date: Mon, 13 Dec 2021 10:44:47 -0500 Subject: [PATCH 1/2] Fixed panic when parsing selector expressions containing composite literals Signed-off-by: Joe Kralicky --- pkg/loader/refs.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/loader/refs.go b/pkg/loader/refs.go index 59ea262bb..37c3295f1 100644 --- a/pkg/loader/refs.go +++ b/pkg/loader/refs.go @@ -133,9 +133,14 @@ func (c *referenceCollector) Visit(node ast.Node) ast.Visitor { // local reference or dot-import, ignore return nil case *ast.SelectorExpr: - pkgName := typedNode.X.(*ast.Ident).Name - c.refs.external(pkgName) - return nil + switch x := typedNode.X.(type) { + case *ast.Ident: + pkgName := x.Name + c.refs.external(pkgName) + return nil + default: + return c + } default: return c } From 3102f89c9494638e316314f1065d495aada74b17 Mon Sep 17 00:00:00 2001 From: Joe Kralicky Date: Tue, 14 Dec 2021 13:46:34 -0500 Subject: [PATCH 2/2] Add array types to crd test data Signed-off-by: Joe Kralicky --- pkg/crd/testdata/cronjob_types.go | 6 ++++++ .../testdata/testdata.kubebuilder.io_cronjobs.yaml | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/pkg/crd/testdata/cronjob_types.go b/pkg/crd/testdata/cronjob_types.go index da389118d..9edf68a6f 100644 --- a/pkg/crd/testdata/cronjob_types.go +++ b/pkg/crd/testdata/cronjob_types.go @@ -193,6 +193,12 @@ type CronJobSpec struct { // +kubebuilder:validation:XValidation:rule="self.size() % 2 == 0",message="must have even length" // +kubebuilder:validation:XValidation:rule="true" StringWithEvenLength string `json:"stringWithEvenLength,omitempty"` + + // Checks that fixed-length arrays work + Array [3]int `json:"array,omitempty"` + + // Checks that arrays work when the type contains a composite literal + ArrayUsingCompositeLiteral [len(struct{ X [3]int }{}.X)]string `json:"arrayUsingCompositeLiteral,omitempty"` } type ContainsNestedMap struct { diff --git a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml index 9fd4d1ee0..3b773d965 100644 --- a/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml +++ b/pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml @@ -35,6 +35,17 @@ spec: spec: description: CronJobSpec defines the desired state of CronJob properties: + array: + description: Checks that fixed-length arrays work + items: + type: integer + type: array + arrayUsingCompositeLiteral: + description: Checks that arrays work when the type contains a composite + literal + items: + type: string + type: array associativeList: description: This tests that associative lists work. items: