Skip to content

feat: custom resource links #2562

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 1 commit into
base: master
Choose a base branch
from

Conversation

thejoeejoee
Copy link

Hello!

As described in #2561, I'm proposing a solution for custom resource links.

I've got some questions during implementation:

  1. internal.KeyFields from context is not taken into account in all Lister implementations -- that's intentional? I've added support to Table, makes sense to have implemented in all Lister implementations?
  2. should the customResourceLinks validation respects the target cluster and validates, if the target resource exists?
  3. is the name appropriate? I've chosen customResourceLinks as it's not only for custom resources, but also for built-in resources, and it's not only for relations, but also for filtering. I'm open to suggestions.

@thejoeejoee thejoeejoee force-pushed the feat-custom-resource-links branch 7 times, most recently from 30dd834 to a50f25c Compare February 24, 2024 17:17
@thejoeejoee thejoeejoee force-pushed the feat-custom-resource-links branch from a50f25c to 1c96f9d Compare March 6, 2024 08:19
@thejoeejoee thejoeejoee force-pushed the feat-custom-resource-links branch 5 times, most recently from 97b83e5 to 0ed934d Compare March 20, 2024 19:38
@thejoeejoee thejoeejoee force-pushed the feat-custom-resource-links branch 3 times, most recently from 3afc8a9 to f261a29 Compare October 5, 2024 09:27
@thejoeejoee thejoeejoee force-pushed the feat-custom-resource-links branch from f261a29 to df9e84e Compare October 5, 2024 09:35
Copy link
Owner

@derailed derailed left a comment

Choose a reason for hiding this comment

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

@thejoeejoee First off Thank you Josef for this pr.
I think this would be super useful!

It think it would be best to use the same strategy as the custom column field in kubectl. Thus I don't think it is necessary to differentiate label/field selectors since we end up with a json query anyway.
I am not super keen in overriding 'enter' as I think the default behavior might still be desirable and avoiding surprises while cruising a cluster. Not to mention there could be other fields a user might want to use to surface extended behavior ie list secrets and confimaps referenced by a given crd.

Thus I was thinking perhaps something like this could fit the bill ie pairing a key binding with the json Q to enable different actions from a given resource??

k9s:
  customActions:
  blee/v1/zorg:
  - target: v1/secrets
     description: View Secret
     action: U:metadata.labels.secret # => bind key U to show associated secret.
   - target: v1/configmaps
      description: View ConfigMap
      action: M:.spec.cm                       # => bind M to view associated cm

I also think introducing json parsing in this PR should allow us to reuse the parser logic to enable custom columns extensions.

WDT? and would this make sense?

@derailed derailed added enhancement New feature or request needs-tlc Pr needs additional updates labels Dec 7, 2024
@chivalryq
Copy link

chivalryq commented Feb 19, 2025

Hi @derailed

I'm facing basically the same problem this PR proposing to solve. And here's my two cents.

  1. It does make sense to support binding other keys than just <Enter>. But I'm still a fan of <Enter> which can align with the default deploy=>pod experience.

  2. Field Selector Use just json query for some fields (like metadata.labels.secret) can't express the action of selecting some of these resources. To select some target resources, we need two things:

    1. Use which fields of target resource to match.
    2. Match value

    What you have proposed here

    k9s:
      customActions:
      blee/v1/zorg:
      - target: v1/secrets
         description: View Secret
         action: U:metadata.labels.secret # => match which field of target resource? Maybe name but can't be custmized.
       - ...
    
  3. Label Selector There is another scenario: use labelSelector to select target resources. For example, Deployment won't list any Pods' name that belong to it.

LabelSelector is a common case when selecting. @thejoeejoee's original proposal didn't quite cover this case. I propose something like:

k9s:
  customResourceLinks:
    any.io/v1/customdeployment:
      target: v1/pods
      labelSelector: .spec.selector # JSON query that must points to a `k8s.io/apimachinery/pkg/apis/meta/v1.LabelSector`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request needs-tlc Pr needs additional updates
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants