Skip to content

rahulmysore23/dms-k8s

Repository files navigation

Kubernetes Context & Namespace Plugin for DMS

A comprehensive DMS (Dank Material Shell) plugin that displays both the current Kubernetes context and namespace in your bar, with the ability to switch between them directly from the UI.

Features

  • 🌐 Display Current Context: Shows the active Kubernetes context in the DankBar
  • 📁 Display Current Namespace: Shows the active namespace for the current context
  • 🔄 Quick Context Switching: Switch between contexts via popup menu
  • 📂 Quick Namespace Switching: Switch between namespaces via popup menu
  • ⚙️ Configurable Refresh Interval: Set how often to refresh (5-300 seconds)
  • 🎨 Customizable Icons: Toggle context and namespace icons on/off
  • 📝 Custom Kubeconfig Path: Support for custom kubeconfig file locations
  • 🎯 Visual Indicators: Clear visual feedback for active context and namespace
  • Auto-close Popup: Popup closes automatically after selection

Installation

  1. Create the plugin directory:
mkdir -p ~/.config/DankMaterialShell/plugins/kube-context-namespace
  1. Clone or copy the plugin files:
cd ~/.config/DankMaterialShell/plugins/
cp -r /home/rmysore/projects/test_plugin_dms_bar kube-context-namespace

Or clone directly:

cd ~/.config/DankMaterialShell/plugins/
git clone <your-repo-url> kube-context-namespace

Usage

  1. Enable the Plugin:

    • Open DMS Settings: Super + ,
    • Go to the "Plugins" tab
    • Enable the "Kube Context & Namespace" plugin
  2. Configure Settings (optional):

    • Kubeconfig Path: Set custom path (default: ~/.kube/config)
    • Refresh Interval: Adjust refresh rate (default: 15 seconds)
    • Show Context Icon: Toggle context icon display
    • Show Namespace Icon: Toggle namespace icon display
  3. Add to DankBar:

    • Add the kube-context-namespace widget to your DankBar configuration

Configuration

Settings

Setting Description Default Range
Kubeconfig Path Path to your Kubernetes config file ~/.kube/config Any valid path
Refresh Interval How often to refresh context/namespace 15 seconds 5-300 seconds
Show Context Icon Display cloud icon next to context true true/false
Show Namespace Icon Display folder icon next to namespace true true/false

Widget Display

Horizontal Bar:

☁️ my-cluster / default

Vertical Bar:

☁️ my-cluster
📁 default

Popup Menu:

  • Lists all available contexts (scrollable)
  • Lists all available namespaces (scrollable)
  • Click to switch
  • Visual indicators for active selections

Files

kube-context-namespace/
├── plugin.json           # Plugin manifest and metadata
├── KubeWidget.qml        # Main widget component
├── KubeSettings.qml      # Settings interface
└── README.md             # This file

Permissions

This plugin requires:

  • settings_read - To read plugin configurations
  • settings_write - To save plugin configurations

Requirements

  • kubectl: Command-line tool must be installed and accessible in PATH
  • Valid kubeconfig: A valid kubeconfig file at the configured path
  • Cluster Access: Active connection to at least one Kubernetes cluster

How It Works

The plugin uses kubectl commands to:

  1. Get current context:

    kubectl --kubeconfig ~/.kube/config config current-context
  2. Get current namespace:

    kubectl --kubeconfig ~/.kube/config config view --minify --output jsonpath={..namespace}
  3. List all contexts:

    kubectl --kubeconfig ~/.kube/config config get-contexts -o name
  4. List all namespaces:

    kubectl --kubeconfig ~/.kube/config get namespaces -o jsonpath={.items[*].metadata.name}
  5. Switch context:

    kubectl --kubeconfig ~/.kube/config config use-context <context-name>
  6. Switch namespace:

    kubectl --kubeconfig ~/.kube/config config set-context --current --namespace=<namespace-name>

All commands respect the configured kubeconfig path.

Comparison with dms-kubernetes

This plugin extends the functionality of the original dms-kubernetes plugin by adding:

Feature dms-kubernetes kube-context-namespace
Display Context
Display Namespace
Switch Context
Switch Namespace
List Namespaces
Dual Display
Separate Icons

Troubleshooting

Plugin doesn't show context/namespace

  1. Verify kubectl is installed:

    which kubectl
  2. Check kubeconfig exists:

    ls -la ~/.kube/config
  3. Test kubectl manually:

    kubectl config current-context
    kubectl config view --minify --output jsonpath={..namespace}

Error message in bar

  • Check DMS logs for detailed error messages
  • Verify kubeconfig path in plugin settings
  • Ensure you have access to the cluster

Namespaces not loading

  • Verify you have permissions to list namespaces:
    kubectl get namespaces

Development

To modify this plugin:

  1. Edit the QML files in ~/.config/DankMaterialShell/plugins/kube-context-namespace/
  2. Reload DMS or restart the plugin
  3. Check DMS logs for any errors

License

MIT License - Feel free to modify and distribute

Author

Created by rmysore

Acknowledgments

Inspired by psyreactor/dms-kubernetes

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors