Skip to content

Custom additionalPrinterColumns for created CRDs #478

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

petar-cvit
Copy link

closes #476

Description

Adds additionalPrinterColumns to RGD and maps the columns to the created CRD in the RGD reconciler.

cc: @a-hilaly

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

Thank you for your PR @petar-cvit ! The PR implementation for custom additionalPrinterColumns looks correct overall.

However i wanted to explore an alternative approach with you, what if we enhanced the SimpleSchema instead of introducing a new top level field? users could potentially do something like:

schema:
  spec:
    name: string | required=true print=true # or kubectl_print=true

I recognize this wouldn't be sufficient for complex printer columns with additional attributes.

I also just came across KEP 4602 (https://github.com/kubernetes/enhancements/pull/4602/files) which seems relevant. We might want to explore this direction in parallel as it could influence our approach here.

Would love to hear your thoughts here :)

@petar-cvit
Copy link
Author

Hey @a-hilaly, thanks for the alternative approach! If we want to add the printer columns to the simple schema, we can easily get the JSONPath for a specific field. Also, this seems easier for users to set up.

I was also thinking about whether additionalPrinterColumns should be top-level with schema and resources, but it seems like we are losing a lot of flexibility for users in the long run if those are defined in the simple schema, especially with the CEL enhancement proposal.

In the case of CEL columns (as described in the KEP), tieing a CEL expression to a field using simple schema doesn't seem like the right fit, primarily because CEL expressions work with the whole CRs and can get data from multiple fields at once (KEP example expression: self.status.replicas == self.spec.replicas ? "READY" : "WAITING").

My point is that if we want to design it with CEL columns in mind, simple schema is probably not the way to go, but not sure how much should a KEP influence design decisions.

One argument for having a dedicated additionalPrinterColumns is that it follows how those are configured for CRDs, and users are familiar on how to use them.

Let me know what you think about the points I mentioned. Happy to discuss further

@a-hilaly
Copy link
Member

a-hilaly commented Apr 8, 2025

Yeah, I totally agree with everything you said @petar-cvit . Keeping additionalPrinterColumns separate makes a lot of sense, especially when thinking about where the KEP is heading. Maybe supporting the simple schema another day could provide a faster way to inject additionalPrinterColumns, just as a way to expose data directly into the kubectl output. with that said i think we should go with this PR :)

@a-hilaly
Copy link
Member

a-hilaly commented Apr 8, 2025

@petar-cvit BTW there's an ongoing thread in our Slack about introducing simple schema custom types and whether they should live directly in spec or in spec.schema. Regardless of where we land on that one, I think additionalPrinterColumns and these type definitions should probably live under the same parent field for consistency. Mind dropping your thoughts in that thread if you get a chance?

Comment on lines +105 to +111
func newCRDAdditionalPrinterColumns(additionalPrinterColumns []extv1.CustomResourceColumnDefinition) []extv1.CustomResourceColumnDefinition {
if len(additionalPrinterColumns) == 0 {
return defaultAdditionalPrinterColumns
}

return additionalPrinterColumns
}
Copy link
Member

@a-hilaly a-hilaly Apr 8, 2025

Choose a reason for hiding this comment

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

Thought: what are your thoughts on injecting specific default CustomResourceColumnDefinition objects, when they aren't specfied by users? that way we ensure that STATE/SYNCED/AGE are always included?

Copy link
Author

Choose a reason for hiding this comment

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

My reasoning was that users might not need the default columns and might want to remove them. If they are already customizing printer columns, my guess is that they want to show a specific state of their CRs.

However, I don't have such a strong opinion on this, and I can merge the defined additionalPrinterColumns with the default ones based on the name. Let me know if you agree with the point above or if we should add the default columns, and I can add them.

Copy link
Member

Choose a reason for hiding this comment

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

I think allowing users to override our default printer columns seems reasonable. If they want to maintain the existing ones, they should be able to.

I mentioned above we should call that out in the docs though

@petar-cvit
Copy link
Author

Thanks for the link to the discussion @a-hilaly. I left a comment with a different approach in the thread that might allow you to reuse types in multiple RGDs. Let me know if it makes sense or if it's overkill for this problem

Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

Neat, thanks @petar-cvit !

@@ -43,6 +44,11 @@ type ResourceGraphDefinitionSpec struct {
//
// +kubebuilder:validation:Optional
DefaultServiceAccounts map[string]string `json:"defaultServiceAccounts,omitempty"`
// AdditionalPrinterColumns defines additional printer columns that will
Copy link
Member

Choose a reason for hiding this comment

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

Worth calling out that setting this overrides the default printer columns, and if the user wants to retain the default columns they will need to specify them here explicitly?

Comment on lines +105 to +111
func newCRDAdditionalPrinterColumns(additionalPrinterColumns []extv1.CustomResourceColumnDefinition) []extv1.CustomResourceColumnDefinition {
if len(additionalPrinterColumns) == 0 {
return defaultAdditionalPrinterColumns
}

return additionalPrinterColumns
}
Copy link
Member

Choose a reason for hiding this comment

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

I think allowing users to override our default printer columns seems reasonable. If they want to maintain the existing ones, they should be able to.

I mentioned above we should call that out in the docs though

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.

Custom additionalPrinterColumns on created CRDs
3 participants