Skip to content

Commit 5656666

Browse files
authored
Merge pull request #1079 from mtardy/pr/mtardy/fix-exprsel-alias
🐛 pkg/crd: fix a missed type casting panic with new *types.Alias
2 parents d0b7b74 + fd3bd9f commit 5656666

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

pkg/crd/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func namedToSchema(ctx *schemaContext, named *ast.SelectorExpr) *apiext.JSONSche
274274
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("unknown type %v.%s", named.X, named.Sel.Name), named))
275275
return &apiext.JSONSchemaProps{}
276276
}
277-
typeInfo := typeInfoRaw.(*types.Named)
277+
typeInfo := typeInfoRaw.(interface{ Obj() *types.TypeName })
278278
typeNameInfo := typeInfo.Obj()
279279
nonVendorPath := loader.NonVendorPath(typeNameInfo.Pkg().Path())
280280
ctx.requestSchema(nonVendorPath, typeNameInfo.Name())

pkg/crd/testdata/cronjob_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ type CronJobSpec struct {
327327

328328
HostsAlias Hosts `json:"hostsAlias,omitempty"`
329329

330+
// This tests that alias imported from a package is handled correctly. The
331+
// corev1.IPFamilyPolicyType is just reused since it's available from
332+
// imported package. We can create our own in a separate package if needed.
333+
AliasFromPackage corev1.IPFamilyPolicyType `json:"aliasFromPackage,omitempty"`
334+
330335
// This tests that string alias is handled correctly.
331336
StringAlias StringAlias `json:"stringAlias,omitempty"`
332337

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8975,6 +8975,12 @@ spec:
89758975
time for any reason. Missed jobs executions will be counted as failed ones.
89768976
format: int64
89778977
type: integer
8978+
aliasFromPackage:
8979+
description: |-
8980+
This tests that alias imported from a package is handled correctly. The
8981+
corev1.IPFamilyPolicyType is just reused since it's available from
8982+
imported package. We can create our own in a separate package if needed.
8983+
type: string
89788984
stringAlias:
89798985
description: This tests that string alias is handled correctly.
89808986
type: string

0 commit comments

Comments
 (0)