Skip to content

feat: Add TableColumns to resource.Schema with codegen support#1299

Open
IfSentient wants to merge 1 commit intomainfrom
IfSentient/printer-cols-table
Open

feat: Add TableColumns to resource.Schema with codegen support#1299
IfSentient wants to merge 1 commit intomainfrom
IfSentient/printer-cols-table

Conversation

@IfSentient
Copy link
Copy Markdown
Contributor

@IfSentient IfSentient commented Mar 18, 2026

What Changed? Why?

Extended resource.Schema with a TableColumns() method that provides type-safe column accessors for kubectl get table display, eliminating the need for reflection-based JSONPath resolution.

Why: Previously, the apiserver's TableConverter was always the default k8s one, and the fields in AdditionalPrinterColumns were ignored. This change unifies the behavior of an apiserver app with that of one which uses CRDs.

How was it tested?

  • Full test suite passes (unit tests + golden file codegen tests)
  • Lint passes (0 issues)
  • Added comprehensive tests for table convertor: single objects, lists, error handling, nil values, no headers, resource version propagation
  • Added example AdditionalPrinterColumns to apiserver example kind (TestKind.v1alpha1)
  • Verified generated schema code includes WithTableColumns() with correct ValueFunc closures

Also tested that the examples/apiserver returned the new column in the table view view kubectl --kubeconfig=kubeconfig get testkinds

Where did you document your changes?

  • Updated examples/apiserver/README.md with kubectl usage examples
  • Added kubeconfig file for local apiserver testing
  • Inline code comments in new methods
  • Type documentation on TableColumn struct

Notes to Reviewers

  • This is a breaking change to resource.Schema interface (adds TableColumns() method). Given the SDK is v0.x/experimental, this is acceptable.
  • getTableColumns() duplicates some validation logic from getSelectableFields() (JSONPath parsing, CUE lookup). This could be extracted to a shared helper in a follow-up.

Co-authored by claude code

Extends resource.Schema with TableColumns() method providing type-safe column accessors for kubectl table display, eliminating the need for reflection-based JSONPath resolution.

Changes:
- Added TableColumn type to resource/schema.go with ValueFunc for direct field extraction
- Extended Schema interface with TableColumns() method, implemented on SimpleSchema
- Added WithTableColumns() option for SimpleSchema configuration
- Implemented getTableColumns() in codegen/jennies/schema.go to validate and generate table column metadata from CUE AdditionalPrinterColumns
- Updated schema.tmpl to generate WithTableColumns() calls with type-safe closures
- Rewrote k8s/apiserver/tableconvertor.go to use Schema TableColumns exclusively, removed all reflection code
- Simplified storage.go to read columns from kind.TableColumns() directly
- Added example AdditionalPrinterColumns to apiserver example
- Added comprehensive tests and kubeconfig for local apiserver testing

This follows the same pattern as SelectableFields, providing codegen-generated type-safe accessors instead of reflection.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@IfSentient IfSentient requested a review from a team as a code owner March 18, 2026 19:45
routes: namespaced: {
"/foobar": {
"GET": {
name: "getFoobar"
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Drive-by to fix codegen, as name is now required for all routes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant