Skip to content

Context-Specific Custom Views #3717

@uozalp

Description

@uozalp

Add support for context-specific custom views in k9s, allowing users to define different column layouts for the same resource type across different Kubernetes clusters/contexts.

Motivation
When working with multiple Kubernetes clusters (production, staging, development, homelab etc), users might need different column layouts for the same resources:

Currently, k9s custom views are global across all contexts, forcing users to choose a single layout that may not be optimal for different environments.

Proposed Solution
Extend the existing custom views syntax to support context-specific patterns using the @context: suffix, similar to the existing @namespace pattern.

views:
  # Context-specific view for production
  v1/pods@context:production:
    columns:
      - NAMESPACE
      - NAME
      - STATUS
      - READY
      - NODE
      - RESTARTS

  # Context-specific view for development
  v1/pods@context:development:
    columns:
      - NAME
      - READY
      - RESTARTS
      - AGE
      - IP

  # Combined: namespace + context (most specific)
  v1/pods@kube-system@context:production:
    columns:
      - NAME
      - NODE
      - STATUS
      - AGE

  # Generic fallback for all contexts
  v1/pods:
    columns:
      - NAME
      - STATUS
      - AGE

Alternativ, but with the current design, YAML specification doesn't allow duplicate keys. Having multiple v1/pods: entries causes a parsing error: yaml: unmarshal errors: mapping key "v1/pods" already defined.

  v1/pods
    context: development
    columns:
      - NAME
      - READY
      - RESTARTS
      - AGE
      - IP

@derailed I have a PR ready, but need some inputs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions