Skip to content

Commit

Permalink
Merge pull request #1079 from mtardy/pr/mtardy/fix-exprsel-alias
Browse files Browse the repository at this point in the history
🐛 pkg/crd: fix a missed type casting panic with new *types.Alias
  • Loading branch information
k8s-ci-robot authored Oct 25, 2024
2 parents d0b7b74 + fd3bd9f commit 5656666
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/crd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func namedToSchema(ctx *schemaContext, named *ast.SelectorExpr) *apiext.JSONSche
ctx.pkg.AddError(loader.ErrFromNode(fmt.Errorf("unknown type %v.%s", named.X, named.Sel.Name), named))
return &apiext.JSONSchemaProps{}
}
typeInfo := typeInfoRaw.(*types.Named)
typeInfo := typeInfoRaw.(interface{ Obj() *types.TypeName })
typeNameInfo := typeInfo.Obj()
nonVendorPath := loader.NonVendorPath(typeNameInfo.Pkg().Path())
ctx.requestSchema(nonVendorPath, typeNameInfo.Name())
Expand Down
5 changes: 5 additions & 0 deletions pkg/crd/testdata/cronjob_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,11 @@ type CronJobSpec struct {

HostsAlias Hosts `json:"hostsAlias,omitempty"`

// This tests that alias imported from a package is handled correctly. The
// corev1.IPFamilyPolicyType is just reused since it's available from
// imported package. We can create our own in a separate package if needed.
AliasFromPackage corev1.IPFamilyPolicyType `json:"aliasFromPackage,omitempty"`

// This tests that string alias is handled correctly.
StringAlias StringAlias `json:"stringAlias,omitempty"`

Expand Down
6 changes: 6 additions & 0 deletions pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8975,6 +8975,12 @@ spec:
time for any reason. Missed jobs executions will be counted as failed ones.
format: int64
type: integer
aliasFromPackage:
description: |-
This tests that alias imported from a package is handled correctly. The
corev1.IPFamilyPolicyType is just reused since it's available from
imported package. We can create our own in a separate package if needed.
type: string
stringAlias:
description: This tests that string alias is handled correctly.
type: string
Expand Down

0 comments on commit 5656666

Please sign in to comment.