feat: render CRD additionalPrinterColumns for custom resources#311
Open
DepravityDemo wants to merge 1 commit into
Open
feat: render CRD additionalPrinterColumns for custom resources#311DepravityDemo wants to merge 1 commit into
DepravityDemo wants to merge 1 commit into
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
kubectl get <custom-resource>against an sbctl-served bundle only showedNAMEandAGE, and-o wideadded nothing — even though the bundle containsthe resource's
CustomResourceDefinitionwithadditionalPrinterColumns. Alive apiserver renders those columns; sbctl did not.
This happens because custom resources are served as
unstructuredobjects andrendered 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
toTablenow detects unstructured objects and, when the bundle ships thematching CRD, builds a table with the CRD's
additionalPrinterColumnsvia theapiextensions
tableconvertor. It falls back to the existing built-in tablewhen no CRD matches or it declares no extra columns, so all existing behavior is
preserved.
crdPrinterColumnsreadscustom-resource-definitions.jsonandmatches the request's group/version/resource.
toTablebecomes ahandlermethod so it can reachclusterData.v1CRDs are handled;v1beta1bundles fall through unchanged.Before
After
Test plan
tests/backupstoragelocations_test.gousing theexisting
velero.ioBackupStorageLocationCRD fixture; asserts thePhase/Last Validated/Defaultcolumns are rendered.go test ./tests/...passes (existing pods/configmaps specs unaffected).gofmt,go vet, andgolangci-lintclean on the changed code.