feat: add AdditionalPrinterColumnPolicy to control CRD printer column…#860
feat: add AdditionalPrinterColumnPolicy to control CRD printer column…#860yashpal2104 wants to merge 1 commit intokubernetes-sigs:mainfrom
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yashpal2104 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 |
|
Hi @yashpal2104. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/ok-to-test |
|
@yashpal2104: Cannot trigger testing until a trusted user reviews the PR and leaves an DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
| the SimpleSchema spec. | ||
| type: object | ||
| x-kubernetes-preserve-unknown-fields: true | ||
| validation: |
There was a problem hiding this comment.
this is a leftover. you really need to rebase properly.
jakobmoellerdev
left a comment
There was a problem hiding this comment.
TLDR: please stop recreating prs and rebasing incorrectly.
this is the last review i will make on a fresh pr. please stop recreating pull requests or I will start closing them.
You already created #790 and #653 even though on the second one I offered you to collaborate. you make it really hard for us maintainers to review and keep control of the pull request list otherwise. thanks!
|
I am sorry but I don't know how can I add you as a collaborator. Didn't mean to create problems for you, but I thought creating fesh PR and cherry picking will solve the problem. |
a835783 to
cb2eb79
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds the AdditionalPrinterColumnPolicy field to the Schema API to control how custom printer columns are merged with default columns in generated CRDs. Currently only "Add" mode is implemented, which merges user-provided columns with the defaults (State, Ready, Age), with user columns overriding defaults when they share the same Name.
- Introduces
AdditionalPrinterColumnPolicyenum type with "Add" as the only supported and default policy - Implements column merging logic that overrides defaults by Name and appends new columns
- Includes comprehensive unit tests and e2e tests validating the merge behavior
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| api/v1alpha1/resourcegraphdefinition_types.go | Adds AdditionalPrinterColumnPolicy type and Validation struct; updates Schema with new fields |
| api/v1alpha1/zz_generated.deepcopy.go | Generated deep copy methods for new Validation struct |
| helm/crds/kro.run_resourcegraphdefinitions.yaml | Updates CRD schema to include new printer column policy and validation fields with documentation |
| pkg/graph/builder.go | Updates SynthesizeCRD call to pass the new policy parameter |
| pkg/graph/crd/crd.go | Implements printer column merging logic and updates SynthesizeCRD signature |
| pkg/graph/crd/crd_test.go | Adds comprehensive unit tests for printer column merging behavior |
| test/e2e/chainsaw/check-additional-printer-columns/*.yaml | E2e test files validating default and Add policy behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // AdditionalPrinterColumnPolicy defines how additional printer columns are applied to the generated CustomResourceDefinition (CRD). | ||
| type AdditionalPrinterColumnPolicy string | ||
|
|
||
| const ( | ||
| // AdditionalPrinterColumnPolicyAdd specifies that the provided additional | ||
| // printer columns should be appended to the default columns. When there are | ||
| // conflicts (columns with the same Name), the user-provided columns take | ||
| // precedence over the defaults. | ||
| AdditionalPrinterColumnPolicyAdd AdditionalPrinterColumnPolicy = "Add" |
There was a problem hiding this comment.
The description states "Replace (default): User columns replace defaults" but the API definition shows "Add" as the only supported policy with +kubebuilder:default=Add. The PR description and CRD documentation are inconsistent with the actual implementation. Either "Replace" mode should be implemented or the PR description should be updated to clarify that only "Add" mode is currently supported.
| // Use defaults if no columns provided | ||
| printerColumns := additionalPrinterColumns | ||
| if len(printerColumns) == 0 { | ||
| printerColumns = defaultAdditionalPrinterColumns | ||
| } |
There was a problem hiding this comment.
The newCRD function has redundant logic. It checks if len(printerColumns) == 0 and assigns defaults, but SynthesizeCRD already calls newCRDAdditionalPrinterColumns which handles empty columns by returning defaults. This check on lines 41-45 is now redundant and creates duplicate logic that could lead to inconsistencies if only one location is updated in the future.
| jsonPath: .spec.name | ||
| name: State | ||
| type: string | ||
| # Default Synced column should remain |
There was a problem hiding this comment.
The comment says "Default Synced column should remain" but the column name is actually "Ready" (line 26). This is inconsistent and misleading - the comment should say "Default Ready column should remain" to match the actual column name.
| # Default Synced column should remain | |
| # Default Ready column should remain |
| // Validation is a list of validation rules that are applied to the | ||
| // resourcegraphdefinition. | ||
| Validation []Validation `json:"validation,omitempty"` |
There was a problem hiding this comment.
The Validation field and its related changes appear unrelated to the printer column policy feature described in the PR. This should either be part of a separate PR or explicitly mentioned in the PR description as an additional feature being added.
| // Validation is a list of validation rules that are applied to the | |
| // resourcegraphdefinition. | |
| Validation []Validation `json:"validation,omitempty"` |
There was a problem hiding this comment.
+1 to that. please get rid of validation
| ) | ||
|
|
||
| // SynthesizeCRD generates a CustomResourceDefinition for a given API version and kind | ||
| // with the provided spec and status schemas~ |
There was a problem hiding this comment.
The comment has a trailing tilde character (~) at the end of line 28 which appears to be a typo. This should be removed.
| // with the provided spec and status schemas~ | |
| // with the provided spec and status schemas |
| "state": { | ||
| stateProperty: { | ||
| Type: "string", | ||
| Description: "Custom state filed", |
There was a problem hiding this comment.
Typo: "filed" should be "field" in the description text.
| Description: "Custom state filed", | |
| Description: "Custom state field", |
| // User columns override defaults when they share the same Name. | ||
| // New user columns are appended after the defaults. | ||
| func newCRDAdditionalPrinterColumns( | ||
| policy v1alpha1.AdditionalPrinterColumnPolicy, |
There was a problem hiding this comment.
The policy parameter is declared but never used in the function logic. The comment on line 118 acknowledges this ("The policy parameter is currently unused as only 'Add' behavior is supported"), but this creates dead code and misleads callers into thinking the policy will be respected. Either implement the policy logic or remove the parameter if "Add" is the only behavior currently supported.
2250f0a to
f738e6d
Compare
| ) | ||
|
|
||
| // AdditionalPrinterColumnPolicy defines how additional printer columns are applied to the generated CustomResourceDefinition (CRD). | ||
| type AdditionalPrinterColumnPolicy string |
There was a problem hiding this comment.
leftover from spec change I believe
There was a problem hiding this comment.
is the policy not needed I thought as you said ( or ig amine said) this needs to be implemented as a policy can you pls confirm?
| // | ||
| // +kubebuilder:validation:Enum=Add | ||
| // +kubebuilder:default=Add | ||
| AdditionalPrinterColumnPolicy AdditionalPrinterColumnPolicy `json:"additionalPrinterColumnPolicy,omitempty"` |
There was a problem hiding this comment.
should be removed as discussed in comm call
There was a problem hiding this comment.
sorry was not present in the call so the policy needs to be removed?
There was a problem hiding this comment.
sorry was not present in the call so the policy needs to be removed?
There was a problem hiding this comment.
yes correct, if we only have one policy there is no need for a field anymore!
There was a problem hiding this comment.
so will we be using string instead of policy ("Add")? and also then we have to use string literals in tests instead of custom types
e2f5116 to
e5593bb
Compare
Add AdditionalPrinterColumnPolicy field to control how custom printer columns are merged with defaults. Currently only "Add" policy is supported, which merges user columns with default columns (State, Ready, Age), with user columns overriding defaults by Name. - Add AdditionalPrinterColumnPolicy type with "Add" enum value - Implement merge logic in newCRDAdditionalPrinterColumns - User columns override defaults when Name matches - New columns are appended after defaults - Default behavior: always merge (no replace option) Includes comprehensive unit tests (87.4% coverage) and e2e tests. Signed-off-by: Yash Pal <yashpal2104@gmail.com>
e5593bb to
d3249c2
Compare
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
thanks for your contribution! we decided we no longer want to expose this parameter in the RGD. at least in v1alpha1. |
… merging
Add AdditionalPrinterColumnPolicy field to Schema with two modes:
This allows users to either fully control printer columns or extend the defaults, maintaining backward compatibility with existing RGDs.
Includes comprehensive unit and e2e tests for both policy modes.