Valuereflect: Add support for arrays#313
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: alvaroaleman The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Without this, the Extract function generated by applyconfig-gen panics: ``` unsupported type: [3]int ```
|
/assign @liggitt |
|
Do you have examples of REST APIs using array types (not slice types)? Wouldn't that also error at decode time with incorrect length inputs? |
| case reflect.Array: | ||
| elemKind := typ.Elem().Kind() | ||
| if elemKind == reflect.Uint8 { | ||
| return byteStringType |
There was a problem hiding this comment.
this special-case doesn't apply to arrays ... json marshals [n]byte as an actual list, not a base-64-encoded string
|
I'm not convinced array support in the API is a good idea... making the generator fail on fields of this type might be a better way to move this error earlier to generate time rather than runtime |
Sorry for taking so long to come back to this. We have a giant sample CRD in controller-tools where ppl add fields that they found problematic over time and we tried to use it for applyconfig generation and currently have a few of these fields commented out: https://github.com/kubernetes-sigs/controller-tools/blob/e0458524f9c6c22915ccfb7b00311ec49410986e/pkg/applyconfiguration/testdata/cronjob/api/v1/cronjob_types.go#L330-L332 The specific case is here: https://github.com/kubernetes-sigs/controller-tools/blob/e0458524f9c6c22915ccfb7b00311ec49410986e/pkg/crd/testdata/cronjob_types.go#L348 This all predated my involvement in the project and it looks like that PR fixed two issues and all the linked repos ran into the other issue. So no, I don't have an example of a project using fixed-length arrays in their API. Should we close this and if/when someone complains that their SSA generation doesn't work and its because of this, we can revisit? |
|
If there's a way to move this from a runtime error to a generate-time error, or from a panic to an error, that seems useful, but that's as far as I would go for now. |
Without this, the Extract function generated by applyconfig-gen panics:
Fixes #311