Documentation
¶
Overview ¶
Package runtime provides the runtime implementation for the Deployah application.
Index ¶
- Constants
- func GetValidStorageDrivers() []string
- func ValidateStorageDriver(driver string) bool
- func ValidateTimeout(timeout time.Duration) bool
- func WithRuntime(ctx context.Context, rt *Runtime) context.Context
- type HelmClient
- type KubernetesClient
- type LoggerAdapter
- func (la *LoggerAdapter) Debug(msg string, keyvals ...interface{})
- func (la *LoggerAdapter) Error(msg string, keyvals ...interface{})
- func (la *LoggerAdapter) Fatal(msg string, keyvals ...interface{})
- func (la *LoggerAdapter) Info(msg string, keyvals ...interface{})
- func (la *LoggerAdapter) Warn(msg string, keyvals ...interface{})
- func (la *LoggerAdapter) With(keyvals ...interface{}) LoggerProvider
- type LoggerProvider
- type ManifestLoader
- type Option
- func WithDebug(keep bool) Option
- func WithHelmFactory(factory func(*Runtime) (HelmClient, error)) Option
- func WithKubeconfig(kubeconfig string) Option
- func WithKubernetesFactory(factory func(*Runtime) (KubernetesClient, error)) Option
- func WithLogger(logger LoggerProvider) Option
- func WithManifestPath(manifestPath string) Option
- func WithNamespace(namespace string) Option
- func WithStorageDriver(driver string) Option
- func WithTimeout(timeout time.Duration) Option
- type Runtime
- func (r *Runtime) Close() error
- func (r *Runtime) DebugKeepTempChart() bool
- func (r *Runtime) Helm() (HelmClient, error)
- func (r *Runtime) Kubernetes() (KubernetesClient, error)
- func (r *Runtime) Manifest(ctx context.Context, environment string) (*manifest.Manifest, error)
- func (r *Runtime) Namespace() string
- func (r *Runtime) RESTConfig() (*rest.Config, error)
- func (r *Runtime) Timeout() time.Duration
- type RuntimeProvider
Constants ¶
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
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
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 ¶
ValidateStorageDriver ensures the storage driver is valid.
func ValidateTimeout ¶
ValidateTimeout ensures timeout is within acceptable bounds.
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 WithHelmFactory ¶
func WithHelmFactory(factory func(*Runtime) (HelmClient, error)) Option
WithHelmFactory sets a custom Helm client factory for testing.
func WithKubeconfig ¶
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 WithManifestPath ¶
WithManifestPath sets the manifest file path.
func WithNamespace ¶
WithNamespace sets the Kubernetes namespace.
func WithStorageDriver ¶
WithStorageDriver sets the storage driver (default: "secret").
func WithTimeout ¶
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 ¶
FromRuntime extracts a Runtime from the command context, or nil if absent.
func (*Runtime) Close ¶
Close performs cleanup of resources held by the runtime. It's safe to call multiple times.
func (*Runtime) DebugKeepTempChart ¶
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 ¶
Manifest loads and memoizes the manifest for the configured path and environment.
func (*Runtime) Namespace ¶
Namespace returns the configured namespace, or "default" if none is set.
func (*Runtime) RESTConfig ¶
RESTConfig returns a Kubernetes REST config using the same logic as the runtime's K8s client.
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.