Skip to content

Conversation

@darksworm
Copy link
Owner

@darksworm darksworm commented Jan 17, 2026

Summary

  • When pressing K on a resource in tree view, k9s now opens with the resource name pre-applied as a filter
  • Makes it easier to jump directly to a specific resource instead of manually filtering
  • Uses k9s's built-in filter syntax (-c 'deploy /name') documented in k9s#789

Before: k9s -c deploy -n default → shows all deployments
After: k9s -c 'deploy /my-app' -n default → shows only matching deployments

Test plan

  • All k9s e2e tests pass (9/9)
  • Manual test: open tree view, press K on a Deployment, verify k9s opens with filter applied

Summary by CodeRabbit

  • New Features
    • K9s launcher now preserves and applies a resource name filter during context selection; status bar displays kind, namespace, name and context.
  • Tests
    • End-to-end and unit tests updated to expect the resource-name filter in K9s invocation and in status rendering.

✏️ Tip: You can customize this high-level summary in your review settings.

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).
@coderabbitai
Copy link

coderabbitai bot commented Jan 17, 2026

Walkthrough

Add 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

Cohort / File(s) Summary
Types & model
cmd/app/k9s_types.go, cmd/app/model.go
Add exported K9sResourceParams (Kind, Namespace, Context, Name). Add k9sPendingName string to Model.
Input handling / context selection
cmd/app/input_handlers.go
Thread k9sPendingName through context selection flow; set/clear pending name on select/cancel; pass Name via K9sResourceParams to openK9s.
K9s launcher & status-bar integration
cmd/app/k9s_sandbox.go, cmd/app/k9s_sandbox_other.go
Change openK9s to accept K9sResourceParams; build k9s args to include " /" when Name provided; update context/namespace handling and thread params through processK9sOutputWithStatusBar, injectStatusBarAtFrameBoundaries, buildStatusBarSequence, drawStatusBarBottom.
Tests (unit & e2e)
cmd/app/k9s_test.go, e2e/k9s_test.go
Update tests to construct/pass K9sResourceParams and expect name-filtered k9s args (e.g., "-c deploy /demo-deploy").

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • feat: open resources in k9s #151 — Refactors k9s integration to accept a params struct (K9sResourceParams) and adjusts status-bar and model k9s state, closely related to this change.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main feature: k9s now opens with a resource name filter pre-applied, which is the primary change across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Tests ✅ Passed The PR includes proper test coverage for the new Name filtering feature with unit tests verifying ANSI sequence processing and e2e tests validating k9s command arguments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@greptile-apps
Copy link

greptile-apps bot commented Jan 17, 2026

Greptile Summary

This PR enhances the k9s integration by pre-applying resource name filters when opening k9s from the tree view. When pressing K on a resource, k9s now opens with the filter syntax -c 'deploy /my-app' instead of just -c deploy, making it easier to jump directly to specific resources.

Key Changes:

  • Added name parameter to openK9s() function and throughout the call chain
  • Filter syntax uses k9s's built-in /name pattern documented in k9s#789
  • Resource name is displayed in the status bar: (Deployment/default: my-app)
  • Both Unix (PTY-based) and non-Unix implementations updated consistently
  • Pending state tracking added (k9sPendingName) for context selection flow
  • All 9 e2e tests pass with updated assertions

Implementation Quality:

  • Clean parameter threading with no breaking changes
  • Consistent implementation across Unix and non-Unix platforms
  • Proper state cleanup in context selection cancellation paths
  • Well-tested with comprehensive e2e coverage

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is clean, well-tested, and follows existing patterns. The change is additive (new parameter with default empty value), maintains backward compatibility, and has comprehensive e2e test coverage (9/9 passing). No security issues found - the resource name is used in a safe context within k9s filter syntax.
  • No files require special attention

Important Files Changed

Filename Overview
cmd/app/input_handlers.go Added name parameter threading through k9s context selection flow and cleanup logic
cmd/app/k9s_sandbox.go Implemented filter syntax -c 'deploy /name' for k9s and added name to status bar display
e2e/k9s_test.go Updated test assertions to verify filter argument is included in k9s command

Sequence Diagram

sequenceDiagram
    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
Loading

@greptile-apps
Copy link

greptile-apps bot commented Jan 17, 2026

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.
@darksworm
Copy link
Owner Author

@greptile how is the latest commit?

Copy link

@greptile-apps greptile-apps bot left a 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

  1. Clean Implementation: The new K9sResourceParams struct is a good refactor that makes the function signatures much cleaner and more maintainable.

  2. Proper Filter Syntax: You're correctly using k9s's filter syntax (deploy /my-app) which is the right way to implement this.

  3. Cross-Platform Support: Both Unix and non-Unix implementations are updated consistently.

  4. Comprehensive Test Updates: All tests are properly updated to expect the new filter behavior.

  5. Good State Management: The new k9sPendingName field is properly managed - set when needed and cleared appropriately.

  6. 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 K on "my-deployment"
  • k9s opens with deploy /my-deployment pre-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! 🚀

@darksworm darksworm merged commit 69c1fb0 into main Jan 17, 2026
5 checks passed
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.

2 participants