shell

package
v0.0.0-...-567bd04 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecCommand

func ExecCommand(ctx context.Context, config *Config, command []string, stopCh chan struct{}, stopOnce *sync.Once) error

execCommand is the internal implementation that executes a command directly with KUBECONFIG environment set, following the same patterns as spawnShell.

func ExecCommandString

func ExecCommandString(ctx context.Context, config *Config, commandStr string, stopCh chan struct{}, stopOnce *sync.Once) error

ExecCommandString executes a command string directly with KUBECONFIG environment set. This is a convenience function that parses a command string and calls ExecCommand.

The command string is parsed using shell-like parsing with support for quoted arguments.

This function blocks until the command exits or the context is cancelled.

func Spawn

func Spawn(ctx context.Context, config *Config) error

Spawn spawns an interactive shell with KUBECONFIG environment set. This is a convenience function for simple use cases that handles cleanup coordination internally.

The shell will run with the specified kubeconfig and custom prompt. This function blocks until the shell exits or the context is cancelled.

func SpawnWithCleanup

func SpawnWithCleanup(ctx context.Context, config *Config, stopCh chan struct{}, stopOnce *sync.Once) error

SpawnWithCleanup spawns an interactive shell with advanced cleanup coordination. This function provides full control over the shell lifecycle and coordination with other background operations (like port forwarding).

The stopCh channel is used to signal when cleanup should begin, and stopOnce ensures cleanup operations only happen once. This is essential for scenarios where multiple goroutines need to coordinate shutdown.

This function blocks until the shell exits or the context is cancelled.

Types

type Config

type Config struct {
	// KubeconfigPath is the path to the kubeconfig file to set as KUBECONFIG
	KubeconfigPath string

	// ClusterName is the display name of the cluster for prompts
	ClusterName string

	// ClusterID is the unique identifier of the cluster (used in HCP scenarios)
	ClusterID string

	// PromptInfo is the formatted prompt information to display in the shell
	// Examples: "[MC: cluster-name]" or "[cluster-id:cluster-name]"
	PromptInfo string

	// Privileged indicates whether the shell is running with privileged access
	// This affects the prompt color: blue for non-privileged, red for privileged
	Privileged bool
}

Config represents the configuration for spawning a shell with kubeconfig access.

type PowerShell

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

func NewPowerShell

func NewPowerShell(executable string) *PowerShell

func (*PowerShell) CreateCommand

func (p *PowerShell) CreateCommand(ctx context.Context, config *Config, kubeconfigPath string) *exec.Cmd

func (*PowerShell) Name

func (p *PowerShell) Name() string

type Shell

type Shell interface {
	// Name returns the display name of the shell type
	Name() string

	// CreateCommand creates the exec.Cmd for the shell with appropriate configuration
	// including environment setup and I/O redirection
	CreateCommand(ctx context.Context, config *Config, kubeconfigPath string) *exec.Cmd
}

Shell is the interface that all shell implementations must satisfy. It provides methods for creating and configuring shell commands with kubeconfig access.

type UnixShell

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

func NewUnixShell

func NewUnixShell(executable string) *UnixShell

func (*UnixShell) CreateCommand

func (u *UnixShell) CreateCommand(ctx context.Context, config *Config, kubeconfigPath string) *exec.Cmd

func (*UnixShell) Name

func (u *UnixShell) Name() string

Jump to

Keyboard shortcuts

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