Skip to content

Commit

Permalink
pkg/crd: fix a missed type casting panic with new *types.Alias
Browse files Browse the repository at this point in the history
This is a follow up on 0a52475 ("pkg/crd: fix type casting panic
with new default *types.Alias"). Look for the commit message of the
cited commit for more context.

Signed-off-by: Mahe Tardy <[email protected]>
  • Loading branch information
mtardy committed Oct 21, 2024
1 parent d0b7b74 commit fd3bd9f
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 fd3bd9f

Please sign in to comment.