-
Notifications
You must be signed in to change notification settings - Fork 482
🐛 fix +listType marker not working on type alias fields #1359
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -215,10 +215,27 @@ type CronJobSpec struct { | |
| // This tests that associative lists work via a nested type. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ? |
||
| NestedAssociativeList NestedAssociativeList `json:"nestedassociativeList"` | ||
|
|
||
| // This tests that +listType can be applied at the field level for type aliases (issue #988). | ||
| // +listType=map | ||
| // +listMapKey=name | ||
| // +listMapKey=secondary | ||
| FieldLevelListType ConditionsWithoutMarker `json:"fieldLevelListType"` | ||
|
|
||
| // This tests that a field-level +listType combined with a type-level +listType | ||
| // is preserved at the top level instead of being wiped into allOf (issue #988). | ||
| // +listType=map | ||
| // +listMapKey=name | ||
| // +listMapKey=secondary | ||
| ListTypeFromTypeAndField NestedAssociativeList `json:"listTypeFromTypeAndField"` | ||
|
|
||
| // A map that allows different actors to manage different fields | ||
| // +mapType=granular | ||
| MapOfInfo map[string][]byte `json:"mapOfInfo"` | ||
|
|
||
| // This tests that +mapType can be applied at the field level for type aliases (issue #988). | ||
| // +mapType=granular | ||
| FieldLevelMapType MapWithoutMarker `json:"fieldLevelMapType"` | ||
|
|
||
| // A map that allows different actors to manage different fields via a nested type. | ||
| NestedMapOfInfo NestedMapOfInfo `json:"nestedMapOfInfo"` | ||
|
|
||
|
|
@@ -562,6 +579,14 @@ type NestedAssociativeList []AssociativeType | |
| // +mapType=granular | ||
| type NestedMapOfInfo map[string][]byte | ||
|
|
||
| // ConditionsWithoutMarker is a type alias to a slice without type-level markers. | ||
| // This tests that +listType can be applied at the field level (issue #988). | ||
| type ConditionsWithoutMarker []AssociativeType | ||
|
|
||
| // MapWithoutMarker is a type alias to a map without type-level markers. | ||
| // This tests that +mapType can be applied at the field level (issue #988). | ||
| type MapWithoutMarker map[string][]byte | ||
|
|
||
| // +kubebuilder:validation:MinLength=4 | ||
| // This tests that markers that are allowed on both fields and types are applied to types | ||
| type LongerString string | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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