runtime

package
v0.0.0-...-a5a3bde Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package runtime provides the runtime implementation for the Deployah application.

Index

Constants

View Source
const (
	// DefaultTimeout is the default timeout for Helm operations
	DefaultTimeout = 10 * time.Minute

	// DefaultStorageDriver is the default Helm storage driver
	DefaultStorageDriver = "secret"

	// DefaultNamespace is used when no namespace is specified
	DefaultNamespace = "default"
)

Runtime Defaults

View Source
const (
	// HelmStorageDriverSecret uses Kubernetes secrets for Helm storage
	HelmStorageDriverSecret = "secret"

	// HelmStorageDriverConfigMap uses Kubernetes ConfigMaps for Helm storage
	HelmStorageDriverConfigMap = "configmap"

	// HelmStorageDriverMemory uses in-memory storage for Helm (testing only)
	HelmStorageDriverMemory = "memory"

	// HelmTimeoutMin is the minimum allowed timeout for Helm operations
	HelmTimeoutMin = 30 * time.Second

	// HelmTimeoutMax is the maximum allowed timeout for Helm operations
	HelmTimeoutMax = 60 * time.Minute
)

Helm Configuration

View Source
const (
	// KubeConfigEnvVar is the environment variable for kubeconfig path
	KubeConfigEnvVar = "KUBECONFIG"

	// NamespaceEnvVar is the environment variable for default namespace
	NamespaceEnvVar = "DPY_NAMESPACE"

	// DebugEnvVar is the environment variable for enabling debug mode
	DebugEnvVar = "DPY_DEBUG"
)

Environment Variables

Variables

This section is empty.

Functions

func GetValidStorageDrivers

func GetValidStorageDrivers() []string

GetValidStorageDrivers returns a list of valid storage drivers.

func ValidateStorageDriver

func ValidateStorageDriver(driver string) bool

ValidateStorageDriver ensures the storage driver is valid.

func ValidateTimeout

func ValidateTimeout(timeout time.Duration) bool

ValidateTimeout ensures timeout is within acceptable bounds.

func WithRuntime

func WithRuntime(ctx context.Context, rt *Runtime) context.Context

WithRuntime returns a new context carrying the provided runtime.

Types

type HelmClient

type HelmClient interface {
	// InstallApp installs or upgrades an application using Helm
	InstallApp(ctx context.Context, manifest *manifest.Manifest, environment string, dryRun bool) error

	// DeleteRelease uninstalls a Helm release
	DeleteRelease(ctx context.Context, project, environment string) error

	// GetRelease retrieves information about a specific release
	GetRelease(ctx context.Context, project, environment string) (*v1.Release, error)

	// ListReleases returns a list of releases matching the given selector
	ListReleases(ctx context.Context, selector labels.Selector) ([]*v1.Release, error)

	// GetReleaseHistory returns the history of a specific release
	GetReleaseHistory(ctx context.Context, project, environment string) ([]*v1.Release, error)

	// RollbackRelease rolls back a release to a previous revision
	RollbackRelease(ctx context.Context, releaseName string, revision int, timeout time.Duration) error
}

HelmClient defines the interface for Helm operations. This abstraction allows for easier testing and potential alternative implementations.

type KubernetesClient

type KubernetesClient interface {
	kubernetes.Interface
}

KubernetesClient defines the interface for Kubernetes operations. This abstraction enables testing with mock Kubernetes clients.

type LoggerAdapter

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

LoggerAdapter adapts the charmbracelet log.Logger to implement the LoggerProvider interface for compatibility with the charmbracelet/log.Logger.

func (*LoggerAdapter) Debug

func (la *LoggerAdapter) Debug(msg string, keyvals ...interface{})

Debug implements LoggerProvider for compatibility with the charmbracelet/log.Logger.

func (*LoggerAdapter) Error

func (la *LoggerAdapter) Error(msg string, keyvals ...interface{})

Error implements LoggerProvider for compatibility with the charmbracelet/log.Logger.

func (*LoggerAdapter) Fatal

func (la *LoggerAdapter) Fatal(msg string, keyvals ...interface{})

Fatal implements LoggerProvider for compatibility with the charmbracelet/log.Logger.

func (*LoggerAdapter) Info

func (la *LoggerAdapter) Info(msg string, keyvals ...interface{})

Info implements LoggerProvider for compatibility with the charmbracelet/log.Logger.

func (*LoggerAdapter) Warn

func (la *LoggerAdapter) Warn(msg string, keyvals ...interface{})

Warn implements LoggerProvider for compatibility with the charmbracelet/log.Logger.

func (*LoggerAdapter) With

func (la *LoggerAdapter) With(keyvals ...interface{}) LoggerProvider

With implements LoggerProvider for compatibility with the charmbracelet/log.Logger.

type LoggerProvider

type LoggerProvider interface {
	// Debug logs a debug-level message
	Debug(msg string, keyvals ...interface{})

	// Info logs an info-level message
	Info(msg string, keyvals ...interface{})

	// Warn logs a warning-level message
	Warn(msg string, keyvals ...interface{})

	// Error logs an error-level message
	Error(msg string, keyvals ...interface{})

	// Fatal logs a fatal-level message and exits
	Fatal(msg string, keyvals ...interface{})

	// With returns a new logger with the given key-value pairs
	With(keyvals ...interface{}) LoggerProvider
}

LoggerProvider defines the interface for logging operations. This enables structured logging with different implementations and levels.

func NewLoggerAdapter

func NewLoggerAdapter(logger *log.Logger) LoggerProvider

NewLoggerAdapter creates a new adapter for the LoggerProvider interface for compatibility with the charmbracelet/log.Logger.

type ManifestLoader

type ManifestLoader interface {
	// Load reads and parses a manifest file
	Load(ctx context.Context, path string, envName string) (*manifest.Manifest, error)

	// Save writes a manifest to a file
	Save(manifest *manifest.Manifest, path string) error

	// Validate validates a manifest against its schema
	Validate(manifest *manifest.Manifest) error
}

ManifestLoader defines the interface for manifest loading operations. This enables testing with mock manifest loaders and different loading strategies.

type Option

type Option func(*Runtime)

Option defines a functional option for configuring Runtime.

func WithDebug

func WithDebug(keep bool) Option

WithDebug controls whether to keep temporary chart directories.

func WithHelmFactory

func WithHelmFactory(factory func(*Runtime) (HelmClient, error)) Option

WithHelmFactory sets a custom Helm client factory for testing.

func WithKubeconfig

func WithKubeconfig(kubeconfig string) Option

WithKubeconfig sets the kubeconfig file path.

func WithKubernetesFactory

func WithKubernetesFactory(factory func(*Runtime) (KubernetesClient, error)) Option

WithKubernetesFactory sets a custom Kubernetes client factory for testing.

func WithLogger

func WithLogger(logger LoggerProvider) Option

WithLogger sets a custom logger.

func WithManifestPath

func WithManifestPath(manifestPath string) Option

WithManifestPath sets the manifest file path.

func WithNamespace

func WithNamespace(namespace string) Option

WithNamespace sets the Kubernetes namespace.

func WithStorageDriver

func WithStorageDriver(driver string) Option

WithStorageDriver sets the storage driver (default: "secret").

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout sets the timeout for Helm operations.

type Runtime

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

Runtime holds per-invocation state and lazily initialized clients/resources. It implements the RuntimeProvider interface for dependency injection.

func FromRuntime

func FromRuntime(ctx context.Context) *Runtime

FromRuntime extracts a Runtime from the command context, or nil if absent.

func New

func New(options ...Option) *Runtime

New constructs a Runtime with functional options.

func (*Runtime) Close

func (r *Runtime) Close() error

Close performs cleanup of resources held by the runtime. It's safe to call multiple times.

func (*Runtime) DebugKeepTempChart

func (r *Runtime) DebugKeepTempChart() bool

DebugKeepTempChart returns whether temporary chart directories should be kept.

func (*Runtime) Helm

func (r *Runtime) Helm() (HelmClient, error)

Helm returns a memoized Helm client configured for this runtime.

func (*Runtime) Kubernetes

func (r *Runtime) Kubernetes() (KubernetesClient, error)

Kubernetes returns a memoized Kubernetes clientset configured for this runtime.

func (*Runtime) Manifest

func (r *Runtime) Manifest(ctx context.Context, environment string) (*manifest.Manifest, error)

Manifest loads and memoizes the manifest for the configured path and environment.

func (*Runtime) Namespace

func (r *Runtime) Namespace() string

Namespace returns the configured namespace, or "default" if none is set.

func (*Runtime) RESTConfig

func (r *Runtime) RESTConfig() (*rest.Config, error)

RESTConfig returns a Kubernetes REST config using the same logic as the runtime's K8s client.

func (*Runtime) Timeout

func (r *Runtime) Timeout() time.Duration

Timeout returns the configured timeout for Helm operations.

type RuntimeProvider

type RuntimeProvider interface {
	// Helm returns a configured Helm client for Kubernetes operations
	Helm() (HelmClient, error)

	// Kubernetes returns a configured Kubernetes clientset
	Kubernetes() (KubernetesClient, error)

	// Manifest loads and returns the parsed manifest for the given environment
	Manifest(ctx context.Context, environment string) (*manifest.Manifest, error)

	// DebugKeepTempChart returns whether temporary chart directories should be kept
	DebugKeepTempChart() bool

	// Close performs cleanup of resources held by the runtime
	Close() error
}

RuntimeProvider defines the interface for runtime dependency management. This interface enables better testability by allowing mock implementations and provides a clear contract for runtime services.

Jump to

Keyboard shortcuts

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