Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 pkg/crd: fix type casting panic with new default *types.Alias with Go 1.23 #1061

Merged
merged 1 commit into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/crd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
}
// NB(directxman12): if there are dot imports, this might be an external reference,
mtardy marked this conversation as resolved.
Show resolved Hide resolved
// so use typechecking info to get the actual object
typeNameInfo := typeInfo.(*types.Named).Obj()
typeNameInfo := typeInfo.(interface{ Obj() *types.TypeName }).Obj()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow this is a nice one 😲

pkg := typeNameInfo.Pkg()
pkgPath := loader.NonVendorPath(pkg.Path())
if pkg == ctx.pkg.Types {
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,9 @@ type CronJobSpec struct {

HostsAlias Hosts `json:"hostsAlias,omitempty"`

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

// This tests string slice validation.
// +kubebuilder:validation:MinItems=2
// +kubebuilder:validation:MaxItems=2
Expand All @@ -351,6 +354,8 @@ type CronJobSpec struct {
Protocol corev1.Protocol `json:"protocol,omitempty" protobuf:"bytes,4,opt,name=protocol,casttype=Protocol"`
}

type StringAlias = string

type ContainsNestedMap struct {
InnerMap map[string]string `json:"innerMap,omitempty"`
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/crd/testdata/testdata.kubebuilder.io_cronjobs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8972,6 +8972,9 @@ spec:
time for any reason. Missed jobs executions will be counted as failed ones.
format: int64
type: integer
stringAlias:
description: This tests that string alias is handled correctly.
type: string
stringPair:
description: This tests string slice validation.
items:
Expand Down
Loading