Documentation
¶
Overview ¶
Package cli implements the diverge command-line interface, providing commands for creating, listing, deleting, and managing preview environments.
Index ¶
- Variables
- func Execute(version, commit, date string)
- func NewRootCmd(app *App) *cobra.Command
- func RenderDot(g *topology.ServiceGraph, w io.Writer) error
- func RenderJSON(g *topology.ServiceGraph, w io.Writer) error
- func RenderMermaid(g *topology.ServiceGraph, w io.Writer) error
- func RootCmd() *cobra.Command
- type App
- type ConfigWatcher
- type ConfigWatcherOption
- type DefaultEnvironmentDetector
- func (d *DefaultEnvironmentDetector) DetectGitBranch(ctx context.Context) (string, error)
- func (d *DefaultEnvironmentDetector) DetectLocalIP(ctx context.Context) (string, error)
- func (d *DefaultEnvironmentDetector) DetectServiceName(ctx context.Context) (string, error)
- func (d *DefaultEnvironmentDetector) DetectUsername(ctx context.Context) (string, error)
- type DevOption
- type DevOptions
- type EnvironmentDetector
- type GraphFormat
- type PluginInfo
- type ProviderInfo
- type Supervisor
- type TunnelClient
Constants ¶
This section is empty.
Variables ¶
var ( // ErrTailscaleNotFound indicates that no suitable local network interface could be found during detector fallback. ErrTailscaleNotFound = errors.New("tailscale interface not found: make sure tailscale is running or pass --endpoint") // ErrNoGitRepo indicates that the detector failed to find a git repository in the current directory. ErrNoGitRepo = errors.New("not in a git repository") )
var ErrBaselinePodNotFound = errors.New("no baseline pod found")
ErrBaselinePodNotFound is returned when no baseline pod can be found for the given service name and namespace.
var ErrCollision = errors.New("preview group collision")
ErrCollision indicates that a preview group with the same name already exists but belongs to a different owner.
var ErrInvalidServiceName = errors.New("invalid service name")
ErrInvalidServiceName is returned when the service name is not a valid Kubernetes label value.
var ErrNamedTargetPortNotFound = fmt.Errorf("named target port not found in pod containers")
var ErrNoTunnelCredential = errors.New("no credential available for the diverge server")
ErrNoTunnelCredential is returned when no credential can be resolved for the tunnel. The server authenticates every Tunnel RPC by Kubernetes TokenReview, so connecting without one only ever yields 401.
var ErrServerNotFound = fmt.Errorf("diverge server not found in cluster")
Functions ¶
func Execute ¶
func Execute(version, commit, date string)
Execute is the main entry point for the diverge CLI. It injects version metadata into the App, initializes the root command if needed, and runs it.
func NewRootCmd ¶
NewRootCmd constructs the root cobra.Command with persistent flags for kubeconfig, namespace, and context, and registers all subcommands (create, delete, init, list, logs, open, status, validate, version).
func RenderJSON ¶ added in v0.8.0
func RenderJSON(g *topology.ServiceGraph, w io.Writer) error
func RenderMermaid ¶ added in v0.8.0
func RenderMermaid(g *topology.ServiceGraph, w io.Writer) error
Types ¶
type App ¶
type App struct {
Kubeconfig string
Namespace string
Context string
NoColor bool
Version string
Commit string
Date string
Client client.Client // For testing
Clientset kubernetes.Interface // For testing (logs needs CoreV1)
}
App holds shared CLI state including Kubernetes connection details, version metadata, and optional API clients supplied by tests.
func (*App) KubeClient ¶
KubeClient returns a controller-runtime client and a kubernetes.Clientset. It returns injected clients when app.Client is non-nil; otherwise it creates both clients from kubeconfig.
func (*App) ResolveNamespace ¶
ResolveNamespace resolves the namespace from the kubeconfig if not explicitly set via --namespace flag.
type ConfigWatcher ¶ added in v0.7.0
type ConfigWatcher struct {
// contains filtered or unexported fields
}
func NewConfigWatcher ¶ added in v0.7.0
func NewConfigWatcher(crdClient client.Client, pgName string, envFile string, opts ...ConfigWatcherOption) *ConfigWatcher
func (*ConfigWatcher) LatestEnvMap ¶ added in v0.7.0
func (cw *ConfigWatcher) LatestEnvMap() map[string]string
LatestEnvMap returns a copy of the most recently computed env map. Thread-safe — called by Supervisor's envBuilder on each restart.
func (*ConfigWatcher) SetOnEnvChange ¶ added in v0.7.0
func (cw *ConfigWatcher) SetOnEnvChange(fn func(diff map[string]string))
SetOnEnvChange registers an env change callback after construction. Must be called before Watch() starts.
type ConfigWatcherOption ¶ added in v0.7.0
type ConfigWatcherOption func(*ConfigWatcher)
ConfigWatcherOption configures optional behavior for a ConfigWatcher.
func WithOnEnvChange ¶ added in v0.7.0
func WithOnEnvChange(fn func(diff map[string]string)) ConfigWatcherOption
WithOnEnvChange registers a callback invoked when env vars change. The diff map contains changed keys with "old → new" descriptions.
func WithOnUpdate ¶ added in v0.7.0
func WithOnUpdate(fn func([]divergev1alpha1.PreviewGroupServiceStatus)) ConfigWatcherOption
WithOnUpdate registers a callback invoked when PreviewGroup service status changes.
func WithProxyAddr ¶ added in v0.7.0
func WithProxyAddr(addr string) ConfigWatcherOption
WithProxyAddr sets the loopback proxy address for .env.diverge output.
func WithProxyMode ¶ added in v0.7.0
func WithProxyMode(mode string) ConfigWatcherOption
WithProxyMode sets the loopback proxy mode for .env.diverge output.
type DefaultEnvironmentDetector ¶
type DefaultEnvironmentDetector struct{}
DefaultEnvironmentDetector provides actual OS/network detection implementations.
func (*DefaultEnvironmentDetector) DetectGitBranch ¶
func (d *DefaultEnvironmentDetector) DetectGitBranch(ctx context.Context) (string, error)
DetectGitBranch performs its designated operation.
func (*DefaultEnvironmentDetector) DetectLocalIP ¶
func (d *DefaultEnvironmentDetector) DetectLocalIP(ctx context.Context) (string, error)
DetectLocalIP performs its designated operation.
func (*DefaultEnvironmentDetector) DetectServiceName ¶
func (d *DefaultEnvironmentDetector) DetectServiceName(ctx context.Context) (string, error)
DetectServiceName performs its designated operation.
func (*DefaultEnvironmentDetector) DetectUsername ¶
func (d *DefaultEnvironmentDetector) DetectUsername(ctx context.Context) (string, error)
DetectUsername performs its designated operation.
type DevOption ¶
type DevOption func(*DevOptions)
DevOption configures DevOptions (e.g. WithDetector, WithPort, WithService).
func WithEnvironmentDetector ¶
func WithEnvironmentDetector(d EnvironmentDetector) DevOption
WithEnvironmentDetector allows injecting a custom EnvironmentDetector for testing.
type DevOptions ¶
type DevOptions struct {
Detector EnvironmentDetector
// contains filtered or unexported fields
}
DevOptions holds optional configuration for the dev command.
type EnvironmentDetector ¶
type EnvironmentDetector interface {
// DetectLocalIP returns the developer's routable IP (e.g., Tailscale).
DetectLocalIP(ctx context.Context) (string, error)
// DetectGitBranch returns the current git branch name.
DetectGitBranch(ctx context.Context) (string, error)
// DetectServiceName returns the service name from .diverge.yaml or cwd.
DetectServiceName(ctx context.Context) (string, error)
// DetectUsername returns the current OS username.
DetectUsername(ctx context.Context) (string, error)
}
EnvironmentDetector abstracts OS/network dependencies for testability.
type GraphFormat ¶ added in v0.8.0
type GraphFormat string
const ( FormatText GraphFormat = "text" FormatMermaid GraphFormat = "mermaid" FormatDot GraphFormat = "dot" FormatJSON GraphFormat = "json" )
type PluginInfo ¶ added in v0.3.0
type PluginInfo struct {
Kind string `json:"kind"`
Name string `json:"name"`
Description string `json:"description"`
}
PluginInfo contains details about a single registered plugin provider.
type ProviderInfo ¶ added in v0.3.0
type ProviderInfo struct {
Kind string `json:"kind"`
Name string `json:"name"`
Description string `json:"description"`
}
ProviderInfo contains details about a single registered provider.
type Supervisor ¶ added in v0.7.0
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor manages the lifecycle of a child process, supporting safe restarts when environment configuration changes. It owns the signal loop and ensures proper process group reaping between restarts.
func NewSupervisor ¶ added in v0.7.0
func NewSupervisor(args []string, envBuilder func() map[string]string) *Supervisor
NewSupervisor creates a supervisor for the given command args. envBuilder is called fresh on each (re)start to produce a clean env map.
func (*Supervisor) RecordChildExit ¶ added in v0.7.0
func (s *Supervisor) RecordChildExit(startTime time.Time)
RecordChildExit records a child exit for circuit breaker tracking. Called after cmd.Wait() returns in the Run loop.
func (*Supervisor) RequestRestart ¶ added in v0.7.0
func (s *Supervisor) RequestRestart(reason string, envDiff map[string]string)
RequestRestart sends a non-blocking restart request to the supervisor.
type TunnelClient ¶ added in v0.7.0
type TunnelClient struct {
Ready chan struct{}
// contains filtered or unexported fields
}
func NewTunnelClient ¶ added in v0.7.0
func (*TunnelClient) Connect ¶ added in v0.7.0
func (tc *TunnelClient) Connect(ctx context.Context) error
func (*TunnelClient) ConnectWithRetry ¶ added in v0.7.0
func (tc *TunnelClient) ConnectWithRetry(ctx context.Context)