Skip to content

Valuereflect: Add support for arrays#313

Open
alvaroaleman wants to merge 1 commit into
kubernetes-sigs:masterfrom
alvaroaleman:array
Open

Valuereflect: Add support for arrays#313
alvaroaleman wants to merge 1 commit into
kubernetes-sigs:masterfrom
alvaroaleman:array

Conversation

@alvaroaleman

Copy link
Copy Markdown
Member

Without this, the Extract function generated by applyconfig-gen panics:

unsupported type: [3]int

Fixes #311

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: alvaroaleman
Once this PR has been reviewed and has the lgtm label, please assign liggitt 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 cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 19, 2026
Without this, the Extract function generated by applyconfig-gen panics:
```
unsupported type: [3]int
```
@k8s-ci-robot k8s-ci-robot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Feb 19, 2026
@alvaroaleman

Copy link
Copy Markdown
Member Author

/assign @liggitt

@liggitt

liggitt commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

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?

Comment thread value/valuereflect.go
case reflect.Array:
elemKind := typ.Elem().Kind()
if elemKind == reflect.Uint8 {
return byteStringType

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this special-case doesn't apply to arrays ... json marshals [n]byte as an actual list, not a base-64-encoded string

see https://go.dev/play/p/fG8JTbZSMjR

@liggitt

liggitt commented May 21, 2026

Copy link
Copy Markdown
Contributor

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

@alvaroaleman

alvaroaleman commented May 21, 2026

Copy link
Copy Markdown
Member Author

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?

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 was added in kubernetes-sigs/controller-tools#648 to fix kubernetes-sigs/controller-tools#613

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?

@liggitt

liggitt commented May 21, 2026

Copy link
Copy Markdown
Contributor

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.

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/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sized array unsupported/causes panic

4 participants