Skip to content

🐛 fix +listType marker not working on type alias fields#1359

Open
sivchari wants to merge 1 commit into
kubernetes-sigs:mainfrom
sivchari:fix-issue-988-listtype-type-alias
Open

🐛 fix +listType marker not working on type alias fields#1359
sivchari wants to merge 1 commit into
kubernetes-sigs:mainfrom
sivchari:fix-issue-988-listtype-type-alias

Conversation

@sivchari

@sivchari sivchari commented Mar 8, 2026

Copy link
Copy Markdown
Member

Include underlying type info (array/object) in schema for slice/map type aliases, allowing field-level markers like +listType to work.

Fixes #988

@k8s-ci-robot k8s-ci-robot added do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Mar 8, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sivchari
Once this PR has been reviewed and has the lgtm label, please assign sbueringer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 8, 2026
@sivchari sivchari force-pushed the fix-issue-988-listtype-type-alias branch from 06bfcda to a39b281 Compare March 9, 2026 02:23
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 9, 2026
@sivchari sivchari force-pushed the fix-issue-988-listtype-type-alias branch from a39b281 to 639035d Compare March 9, 2026 02:40
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 13, 2026
@sivchari sivchari force-pushed the fix-issue-988-listtype-type-alias branch from 639035d to 4d23c3a Compare March 16, 2026 08:37
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 16, 2026
@JoelSpeed

Copy link
Copy Markdown
Contributor

Code change looks good but we do need to fix the commit message please

@sivchari sivchari force-pushed the fix-issue-988-listtype-type-alias branch from 4d23c3a to 98002b0 Compare March 17, 2026 03:10
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Mar 17, 2026
@sivchari

Copy link
Copy Markdown
Member Author

Sorry, fixed.

@k8s-triage-robot

Copy link
Copy Markdown

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 15, 2026
Comment thread pkg/crd/schema.go Outdated
Comment on lines +318 to +319
// For type aliases to slice/map types, include the underlying type information
// so that markers like +listType can be applied at the field level.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// For type aliases to slice/map types, include the underlying type information
// so that markers like +listType can be applied at the field level.
// Set the type for slice and map aliases so field-level markers like +listType
// and +mapType can work. Structs are skipped — they use a $ref only.

I think we sould need to shape it here.

Comment thread pkg/crd/schema.go Outdated
Comment on lines +365 to +367
// For type aliases to slice/map types, include the underlying type information
// so that markers like +listType can be applied at the field level.
props := &apiextensionsv1.JSONSchemaProps{

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
// For type aliases to slice/map types, include the underlying type information
// so that markers like +listType can be applied at the field level.
props := &apiextensionsv1.JSONSchemaProps{
// Set the type for slice and map aliases so field-level markers like +listType
// and +mapType can work. Structs are skipped — they use a $ref only.
props := &apiextensionsv1.JSONSchemaProps{

here too?

Comment thread pkg/crd/schema.go
@@ -312,26 +315,31 @@ func localNamedToSchema(ctx *schemaContext, ident *ast.Ident) *apiextensionsv1.J
ctx.requestSchema(pkgPath, typeNameInfo.Name())
link := TypeRefLink(pkgPath, typeNameInfo.Name())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
resolvedType := typeInfoRaw
if aliasInfo, isAlias := typeInfoRaw.(*types.Alias); isAlias {
resolvedType = aliasInfo.Rhs()
}

I think we need to handle the case where Go 1.23+ represents type aliases as *types.Alias instead of *types.Named. Right now if someone has type Foo = []T in an external package, isNamed is false, typ stays empty and +listType still fails — same as before this fix. Could you add the alias unwrap before the switch? That seems like a blocker for merging this one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sivchari did you check this one ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, addressed with types.Unalias() so slice/map aliases resolve correctly and +listType/+mapType apply

@@ -207,6 +207,12 @@ type CronJobSpec struct {
// This tests that associative lists work via a nested type.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The PR adds props.Type = "object" for map aliases to make +mapType work at the field level, but there's no test covering that path. Could you add a field with a map alias type and +mapType on it? Without it a regression there would go unnoticed. Could you please add ?


// +kubebuilder:validation:MinLength=4
// This tests that markers that are allowed on both fields and types are applied to types
type LongerString string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hey, I was looking at flattenAllOfInto and noticed XListType and XListMapKeys don't have their own case there. If both the type and the field have +listType set, they'll hit default: and the annotation gets wiped from the top level of the CRD.

Could it not be a silent failure? XMapType has its own case already so it handles this fine, could we do the same for these two?

@camilamacedo86 camilamacedo86 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@sivchari

Thank you so much for looking on this one 🎉

I just try to do a full review. Could you please check it out?
Can you please rebase with main and address those ones?

Then, I would be happy to LGTM this one.

Thank you 🚀

@camilamacedo86

Copy link
Copy Markdown
Member

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 16, 2026
@sivchari sivchari force-pushed the fix-issue-988-listtype-type-alias branch from 98002b0 to 9284ccd Compare June 18, 2026 05:00
@sivchari

Copy link
Copy Markdown
Member Author

I addressed these comments. Thnaks.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 18, 2026
@camilamacedo86

Copy link
Copy Markdown
Member

Hi @sivchari

Could you please ensure that pass in the lint check and the tests?

@sivchari sivchari force-pushed the fix-issue-988-listtype-type-alias branch 3 times, most recently from bb50795 to d7f3da5 Compare June 18, 2026 06:07
Include underlying type info (array/object) in schema for slice/map
type aliases, allowing field-level markers like +listType to work.

Signed-off-by: sivchari <shibuuuu5@gmail.com>
@sivchari sivchari force-pushed the fix-issue-988-listtype-type-alias branch from d7f3da5 to 1d22cac Compare June 18, 2026 06:19
@sivchari

Copy link
Copy Markdown
Member Author

CI green now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

controller-gen: Type aliases to array types don't work with +listType/+listMapKey markers

5 participants