k9s

package
v1.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

README

pkg/k9s

This package provides a k9s client implementation for KSail.

Purpose

Provides a wrapper around the k9s terminal UI tool using its native Go packages, allowing KSail to launch k9s with appropriate configuration.

Features

  • Native k9s Integration: Uses k9s's Go packages directly (no subprocess execution)
  • Kubeconfig Support: Automatically configures k9s with the appropriate kubeconfig
  • Argument Pass-through: All k9s arguments are passed through to the native k9s execution

Usage

import "github.com/devantler-tech/ksail-go/pkg/k9s"

// Create a k9s client
client := k9s.NewClient()

// Create a connect command that launches k9s
cmd := client.CreateConnectCommand("/path/to/kubeconfig")

// Execute the command (this will launch k9s)
err := cmd.Execute()
if err != nil {
    log.Fatal("Failed to launch k9s:", err)
}

Command Behavior

The CreateConnectCommand method creates a Cobra command that:

  1. Launches k9s using its native Go packages
  2. Automatically passes the kubeconfig path via --kubeconfig flag
  3. Passes through all user-provided arguments to k9s
  4. Connects k9s to the terminal for interactive use

Native Integration

This package integrates k9s using its exported cmd.Execute() function from github.com/derailed/k9s/cmd. This provides:

  • Direct integration without subprocess overhead
  • Full access to k9s's native flags and features
  • Consistent behavior with standalone k9s

Testing

The package includes comprehensive tests that verify:

  • Client creation
  • Command structure and metadata
  • Proper kubeconfig handling

⬅️ Go Back

Documentation

Overview

Package k9s provides a k9s client implementation.

Coverage Note: The DefaultK9sExecutor.Execute() method (line 20) and parts of the HandleConnectRunE execution path cannot be fully tested in unit tests because they require launching k9s which needs an actual terminal UI. These paths are validated through: - Integration testing with actual k9s installation - Manual verification of the connect command - Mock-based testing of all logic leading up to k9s execution

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps k9s command functionality.

func NewClient

func NewClient() *Client

NewClient creates a new k9s client instance with the default executor.

func NewClientWithExecutor

func NewClientWithExecutor(executor Executor) *Client

NewClientWithExecutor creates a new k9s client with a custom executor for testing.

func (*Client) CreateConnectCommand

func (c *Client) CreateConnectCommand(kubeConfigPath, context string) *cobra.Command

CreateConnectCommand creates a k9s command with all its flags and behavior.

type DefaultK9sExecutor

type DefaultK9sExecutor struct{}

DefaultK9sExecutor is the default implementation that calls k9s directly.

func (*DefaultK9sExecutor) Execute

func (e *DefaultK9sExecutor) Execute()

Execute calls the k9s cmd.Execute function.

type Executor

type Executor interface {
	Execute()
}

Executor defines the interface for executing k9s.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL