fabric8io / kubernetes-client

Java client for Kubernetes & OpenShift
http://fabric8.io
Apache License 2.0
3.35k stars 1.45k forks source link

JSONPath selection in PrinterColumn #3069

Open lburgazzoli opened 3 years ago

lburgazzoli commented 3 years ago

As today the @PrinterColumn annotation can only be set on a field, but in some case it would be nice to have the option to set in on a type, i.e. on a CustomResource

with the go sdk, one can do something like:

kubebuilder:printcolumn:name="provider",type=string,JSONPath=`.spec.runtime.provider`,description="provider"

but I don't a similar option with the java operator sdk

My use case is that I have a Java class used in both the spec and the status and I want to print the same field from spec and status but with a different name.

public class ConnectorSpec {    
    private DeploymentRef deployment;
}
public class ConnectorStatus {    
    private DeploymentRef deployment;
}

with the go sdk, I could write something like

kubebuilder:printcolumn:name=name="foo",type=string,JSONPath=`.spec.deployment.field`"
kubebuilder:printcolumn:name=name="bar",type=string,JSONPath=`.status.deployment.field`

I can workaround this by in-lining classes in the spec/status or having two distinct classes but since the information are exactly the same, it would put more maintenance

metacosm commented 3 years ago

I can think of two options at the moment: either a class level annotation allowing you to specify which path you want to add as a printer column, similarly to what the go sdk does, or make the @PrinterColumn annotation multiple so that a given field could be annotated with different values, adding a predicate field to determine how to activate a given version.

The first option is most likely simpler to implement but that decouples the annotation from the field it's targeting making it more difficult to maintain. The second option doesn't have that disadvantage but it is probably more complex to implement and possibly to understand depending on how complex the activation predicate could be.

What do you think, @iocanel @manusa?

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

lburgazzoli commented 2 years ago

@metacosm @iocanel this is how it is implemented din strimzi: https://github.com/strimzi/strimzi-kafka-operator/blob/a89f9b466a79b36d49b6b7fcdd120ad9b1c6cec4/api/src/main/java/io/strimzi/api/kafka/model/KafkaConnector.java#L53-L78

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

lburgazzoli commented 2 years ago

still relevant

stoetti commented 2 years ago

Are there any plans on implementing this enhancement in the near future?

In order to build CRDs in respect common api conventions (https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#typical-status-properties) it would be really necessary to provide printer columns that are defined using a JsonPath like this .status.conditions[?(@.type=="Ready")].status

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had any activity since 90 days. It will be closed if no further activity occurs within 7 days. Thank you for your contributions!

manusa commented 4 months ago

Hi @metacosm, What's the status of this issue? I'm planning the features to be completed in scope of v7.0.

metacosm commented 4 months ago

I haven't looked at this in a long time and probably don't have time to take it on anymore. Feel free to re-assign it to someone else.