Skip to content

feat: render CRD additionalPrinterColumns for custom resources#311

Open
DepravityDemo wants to merge 1 commit into
replicatedhq:mainfrom
DepravityDemo:feat/crd-additional-printer-columns
Open

feat: render CRD additionalPrinterColumns for custom resources#311
DepravityDemo wants to merge 1 commit into
replicatedhq:mainfrom
DepravityDemo:feat/crd-additional-printer-columns

Conversation

@DepravityDemo

Copy link
Copy Markdown

Summary

kubectl get <custom-resource> against an sbctl-served bundle only showed
NAME and AGE, and -o wide added nothing — even though the bundle contains
the resource's CustomResourceDefinition with additionalPrinterColumns. A
live apiserver renders those columns; sbctl did not.

This happens because custom resources are served as unstructured objects and
rendered with the built-in table generator (printersinternal.AddHandlers),
which only knows core/apps/batch types. Unknown types fall back to a generic
NAME/AGE table.

Change

toTable now detects unstructured objects and, when the bundle ships the
matching CRD, builds a table with the CRD's additionalPrinterColumns via the
apiextensions tableconvertor. It falls back to the existing built-in table
when no CRD matches or it declares no extra columns, so all existing behavior is
preserved.

  • New helper crdPrinterColumns reads custom-resource-definitions.json and
    matches the request's group/version/resource.
  • toTable becomes a handler method so it can reach clusterData.
  • Only v1 CRDs are handled; v1beta1 bundles fall through unchanged.

Before

$ kubectl get pg -A
NAMESPACE   NAME               AGE
default     job-d810lpwk17on   23h

After

$ kubectl get pg -A
NAMESPACE   NAME               STATUS    MINMEMBER   RUNNINGS   AGE
default     job-d810lpwk17on   Running   1           1          23h

$ kubectl get pg -A -o wide
NAMESPACE   NAME               STATUS    MINMEMBER   RUNNINGS   AGE   QUEUE
default     job-d810lpwk17on   Running   1           1          23h   aihcq-qitkz4auspzc

Test plan

  • Added integration test tests/backupstoragelocations_test.go using the
    existing velero.io BackupStorageLocation CRD fixture; asserts the
    Phase / Last Validated / Default columns are rendered.
  • go test ./tests/... passes (existing pods/configmaps specs unaffected).
  • gofmt, go vet, and golangci-lint clean on the changed code.
  • Manually verified against a real Volcano PodGroup support bundle.

Custom resources were served to `kubectl get` as unstructured objects and
rendered with the built-in table generator, which only knows core/apps/batch
types. As a result any CR (e.g. Volcano PodGroup, Velero BackupStorageLocation)
showed only NAME/AGE and `-o wide` added nothing, unlike a live apiserver.

When the bundle ships the matching CustomResourceDefinition, look up its
additionalPrinterColumns and render the table via the apiextensions
tableconvertor, so `kubectl get <cr>` and `-o wide` show the same columns a
live cluster would. Falls back to the existing NAME/AGE table when no CRD
matches or it declares no extra columns. Only v1 CRDs are supported; v1beta1
bundles fall through unchanged.

Adds an integration test exercising the velero.io BackupStorageLocation CRD
fixture (Phase / Last Validated / Default columns).
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