Skip to content

Commit 3b70a40

Browse files
authored
Merge pull request #1061 from mtardy/fix-panic-cast
🐛 pkg/crd: fix type casting panic with new default `*types.Alias` with Go 1.23
2 parents ecef93e + 0a52475 commit 3b70a40

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

pkg/crd/schema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiext.JSONSchema
254254
}
255255
// NB(directxman12): if there are dot imports, this might be an external reference,
256256
// so use typechecking info to get the actual object
257-
typeNameInfo := typeInfo.(*types.Named).Obj()
257+
typeNameInfo := typeInfo.(interface{ Obj() *types.TypeName }).Obj()
258258
pkg := typeNameInfo.Pkg()
259259
pkgPath := loader.NonVendorPath(pkg.Path())
260260
if pkg == ctx.pkg.Types {

pkg/crd/testdata/cronjob_types.go

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

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

330+
// This tests that string alias is handled correctly.
331+
StringAlias StringAlias `json:"stringAlias,omitempty"`
332+
330333
// This tests string slice validation.
331334
// +kubebuilder:validation:MinItems=2
332335
// +kubebuilder:validation:MaxItems=2
@@ -351,6 +354,8 @@ type CronJobSpec struct {
351354
Protocol corev1.Protocol `json:"protocol,omitempty" protobuf:"bytes,4,opt,name=protocol,casttype=Protocol"`
352355
}
353356

357+
type StringAlias = string
358+
354359
type ContainsNestedMap struct {
355360
InnerMap map[string]string `json:"innerMap,omitempty"`
356361
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8972,6 +8972,9 @@ spec:
89728972
time for any reason. Missed jobs executions will be counted as failed ones.
89738973
format: int64
89748974
type: integer
8975+
stringAlias:
8976+
description: This tests that string alias is handled correctly.
8977+
type: string
89758978
stringPair:
89768979
description: This tests string slice validation.
89778980
items:

0 commit comments

Comments
 (0)