-
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: k9s opens with resource name filter pre-applied #184
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
Conversation
When pressing K on a resource in tree view, k9s now opens with the resource name as a filter. This makes it easier to jump directly to a specific resource instead of having to manually filter. Example: pressing K on Deployment "my-app" now launches: k9s -c 'deploy /my-app' -n default --context cluster This uses k9s's built-in filter syntax (documented in k9s#789).
WalkthroughAdd a K9sResourceParams struct (Kind, Namespace, Context, Name), thread a pending resource Name through Model and input handlers, update openK9s and downstream status-bar/output functions to accept the params struct and include optional name-based filtering in spawned k9s args and status rendering. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant UI as App UI
participant Model
participant ContextSel as Context Selector
participant Launcher as openK9s
participant K9s as k9s Process
participant ProcOut as Output Processor
participant Status as Status Bar Builder
User->>UI: request open resource (kind, ns, name)
UI->>Model: set k9sPendingKind / k9sPendingNamespace / k9sPendingName
UI->>ContextSel: prompt context selection
alt context selected
ContextSel-->>Model: selected context
Model->>Launcher: openK9s(K9sResourceParams{Kind, Namespace, Context, Name})
else no contexts or load fail
Model->>Launcher: openK9s(K9sResourceParams{Kind, Namespace, "", Name})
end
Launcher->>K9s: spawn k9s with args (include "<resourceAlias> /<Name>" if Name)
K9s-->>ProcOut: terminal frames
ProcOut->>Status: process frames with params
Status-->>ProcOut: frames with injected status bar (shows Name)
ProcOut-->>UI: rendered output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Greptile SummaryThis PR enhances the k9s integration by pre-applying resource name filters when opening k9s from the tree view. When pressing Key Changes:
Implementation Quality:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant TreeView
participant InputHandler as input_handlers.go
participant Model
participant K9sSandbox as k9s_sandbox.go
participant K9s as k9s CLI
User->>TreeView: Press 'K' on Deployment
TreeView->>InputHandler: handleOpenK9s()
InputHandler->>TreeView: SelectedResource()
TreeView-->>InputHandler: (group, kind, namespace, name)
Note over InputHandler: Extracts resource details:<br/>kind="Deployment"<br/>namespace="default"<br/>name="demo-deploy"
alt Context not found
InputHandler->>Model: Store pending state
Model->>Model: k9sPendingKind = "Deployment"
Model->>Model: k9sPendingNamespace = "default"
Model->>Model: k9sPendingName = "demo-deploy"
InputHandler->>User: Show context picker
User->>InputHandler: Select context
end
InputHandler->>K9sSandbox: openK9s(kind, namespace, context, name)
Note over K9sSandbox: Build k9s args:<br/>-c 'deploy /demo-deploy'<br/>-n default<br/>--context cluster-a
K9sSandbox->>K9s: Launch with filter
Note over K9s: Opens with pre-applied filter<br/>showing only matching resources
K9s-->>User: Filtered view
User->>K9s: :q to exit
K9s-->>K9sSandbox: Exit
K9sSandbox-->>InputHandler: Return to tree view
|
Greptile's behavior is changing!From now on, if a review finishes with no comments, we will not post an additional "statistics" comment to confirm that our review found nothing to comment on. However, you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
Introduces a struct to group related parameters (kind, namespace, context, name) instead of passing them as separate arguments. This improves readability and follows the new convention of using structs for functions with 3+ parameters.
|
@greptile how is the latest commit? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the latest commit, this is a well-implemented feature that enhances the user experience! Here's my assessment:
✅ What's Done Well
-
Clean Implementation: The new
K9sResourceParamsstruct is a good refactor that makes the function signatures much cleaner and more maintainable. -
Proper Filter Syntax: You're correctly using k9s's filter syntax (
deploy /my-app) which is the right way to implement this. -
Cross-Platform Support: Both Unix and non-Unix implementations are updated consistently.
-
Comprehensive Test Updates: All tests are properly updated to expect the new filter behavior.
-
Good State Management: The new
k9sPendingNamefield is properly managed - set when needed and cleared appropriately. -
Enhanced Status Bar: The status bar now shows the resource name, which provides good context to users.
🎯 The Feature Impact
This is a genuinely useful enhancement. Instead of opening k9s and then manually typing a filter, users can now:
- Press
Kon "my-deployment" - k9s opens with
deploy /my-deploymentpre-filtered - Immediately see only the relevant resource
📋 Minor Observations
The implementation is solid. The only thing I'd note is that the filter will show partial matches (k9s behavior), but that's actually helpful - if you have my-app-v1 and my-app-v2, filtering by my-app will show both, which is often what users want.
Overall, this is a high-quality commit that adds real value while maintaining code quality and test coverage. Nice work! 🚀
Summary
Kon a resource in tree view, k9s now opens with the resource name pre-applied as a filter-c 'deploy /name') documented in k9s#789Before:
k9s -c deploy -n default→ shows all deploymentsAfter:
k9s -c 'deploy /my-app' -n default→ shows only matching deploymentsTest plan
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.