Documentation
¶
Overview ¶
Package config provides functionality for managing cluster configurations.
This package defines the data structures for the cluster configuration, as well as functions for loading, saving, and validating configurations. It also includes functionality for generating a JSON schema for the configuration.
When to use ¶
This package is used internally by opencenter to manage cluster configurations. It is not intended for direct use by end-users.
Configuration structure ¶
The main data structure in this package is the `Config` struct, which represents the root configuration for a cluster. It groups GitOps, Kubernetes, and Cloud configuration under nested fields.
Index ¶
- Constants
- Variables
- func DefaultCLIConfigPath() (string, error)
- func DefaultConfigDir() string
- func DefaultStateDir() string
- func GetBlueprintsDir() string
- func GetClusterStateDir() string
- func GetClustersDir() string
- func GetConfigDir() string
- func GetGitOpsDir() string
- func GetPluginsDir() string
- func GetSecretsDir() string
- func GetStateDir() string
- func NewPathResolverFromConfig() *corePaths.PathResolver
- func ParseClusterIdentifier(identifier string) (organization string, clusterName string, err error)
- func ResolveClustersDir() string
- func ResolveConfigDir() (string, error)
- func ResolveStateDir() (string, error)
- func UpdateStatus(clusterName, stage, status string) error
- func ValidateBehaviorValidationMode(mode string) error
- func ValidateGitopsAuthMethod(method string) error
- type BehaviorConfig
- type CLIConfig
- type ClusterDefaultsConfig
- type ConfigError
- type ConfigManager
- func (cm *ConfigManager) GetConfig() *CLIConfig
- func (cm *ConfigManager) GetConfigPath() string
- func (cm *ConfigManager) GetValidationSummary() string
- func (cm *ConfigManager) GetValue(key string) (interface{}, error)
- func (cm *ConfigManager) Load() error
- func (cm *ConfigManager) LoadWithConfig(config *CLIConfig) error
- func (cm *ConfigManager) RepairConfig() (*ValidationResult, error)
- func (cm *ConfigManager) Reset() error
- func (cm *ConfigManager) Save() error
- func (cm *ConfigManager) SetValue(key string, value interface{}) error
- func (cm *ConfigManager) ValidateConfig() *ValidationResult
- type ConfigValidator
- type ConfigurationManager
- type FileConfig
- type LoggingConfig
- type PathsConfig
- type ValidationResult
Constants ¶
const ( ValidationModeOffline = "offline" ValidationModeOnline = "online" GitopsAuthMethodSSH = "ssh" GitopsAuthMethodToken = "token" )
Variables ¶
var NewConfigurationManagerWithDeps = v2.NewConfigurationManagerWithDeps
NewConfigurationManagerWithDeps re-exported from v2.
Functions ¶
func DefaultCLIConfigPath ¶
DefaultCLIConfigPath returns the default path for the CLI settings file.
func DefaultConfigDir ¶
func DefaultConfigDir() string
DefaultConfigDir returns the side-effect-free default configuration directory path.
func DefaultStateDir ¶
func DefaultStateDir() string
DefaultStateDir returns the side-effect-free default runtime state directory path.
func GetBlueprintsDir ¶
func GetBlueprintsDir() string
GetBlueprintsDir returns the cluster blueprints root using the precedence: OPENCENTER_BLUEPRINTS_DIR, CLI settings paths.blueprintsDir, then clustersDir/blueprints.
func GetClusterStateDir ¶
func GetClusterStateDir() string
GetClusterStateDir returns the per-cluster state root using the precedence: OPENCENTER_CLUSTER_STATE_DIR, CLI settings paths.clusterStateDir, then clustersDir/state.
func GetClustersDir ¶
func GetClustersDir() string
GetClustersDir returns the clusters directory from the CLI config. OPENCENTER_CLUSTERS_DIR overrides the CLI config. If the CLI config cannot be loaded or clustersDir is not set, it returns the default. This function is safe to call from anywhere and will not cause circular dependencies.
func GetConfigDir ¶
func GetConfigDir() string
GetConfigDir returns the settings directory from the CLI config. If the CLI config cannot be loaded or settingsDir is not set, it returns the default.
func GetGitOpsDir ¶
func GetGitOpsDir() string
GetGitOpsDir returns the GitOps repository root using the precedence: OPENCENTER_GITOPS_DIR, CLI settings paths.gitopsDir, then clustersDir/gitops.
func GetPluginsDir ¶
func GetPluginsDir() string
GetPluginsDir returns the plugins directory from the CLI config. If the CLI config cannot be loaded or pluginsDir is not set, it returns the default.
func GetSecretsDir ¶
func GetSecretsDir() string
GetSecretsDir returns the per-cluster secrets root using the precedence: OPENCENTER_SECRETS_DIR, CLI config paths.secretsDir, then clustersDir/secrets.
func GetStateDir ¶
func GetStateDir() string
GetStateDir returns the runtime state directory using the precedence: OPENCENTER_STATE_DIR, CLI config paths.stateDir, then the platform default.
func NewPathResolverFromConfig ¶
func NewPathResolverFromConfig() *corePaths.PathResolver
NewPathResolverFromConfig returns a secure zone-aware path resolver using the current CLI settings and environment variable precedence.
func ParseClusterIdentifier ¶
ParseClusterIdentifier parses a cluster identifier which can be in one of two formats: 1. "cluster" - just the cluster name (uses default "opencenter" organization) 2. "organization/cluster" - organization and cluster name
Inputs:
- identifier: The cluster identifier to parse.
Outputs:
- organization: The organization name (or "opencenter" if not specified).
- clusterName: The cluster name.
- error: An error if the identifier is invalid.
func ResolveClustersDir ¶
func ResolveClustersDir() string
ResolveClustersDir returns the runtime clusters directory. If OPENCENTER_CLUSTERS_DIR is set, it is used as the cluster storage root. Otherwise, the CLI config clustersDir value is used, falling back to OPENCENTER_CONFIG_DIR/clusters or the default clusters path.
func ResolveConfigDir ¶
ResolveConfigDir resolves the configuration directory based on the OPENCENTER_CONFIG_DIR environment variable. If the variable is not set, it falls back to the user's standard config directory (e.g., ~/.config/opencenter on Linux). The directory is created if it does not exist.
func ResolveStateDir ¶
ResolveStateDir resolves the runtime state directory based on OPENCENTER_STATE_DIR, CLI config, or the platform default and creates it if needed.
func UpdateStatus ¶
UpdateStatus updates the cluster's stage and status in the configuration file. It loads the configuration, updates the values, and saves it back.
Types ¶
type BehaviorConfig ¶
type BehaviorConfig struct {
AutoConfirm bool `yaml:"autoConfirm"`
DryRun bool `yaml:"dryRun"`
Validation string `yaml:"validation"`
}
BehaviorConfig controls CLI behavior settings.
type CLIConfig ¶
type CLIConfig struct {
Logging LoggingConfig `yaml:"logging"`
Paths PathsConfig `yaml:"paths"`
Behavior BehaviorConfig `yaml:"behavior"`
ClusterDefaults ClusterDefaultsConfig `yaml:"cluster_defaults"`
}
CLIConfig represents the global CLI configuration system that controls CLI behavior, logging, and default paths.
func DefaultCLIConfig ¶
func DefaultCLIConfig() *CLIConfig
DefaultCLIConfig returns the default CLI configuration.
type ClusterDefaultsConfig ¶
type ClusterDefaultsConfig struct {
Organization string `yaml:"organization,omitempty"`
Provider string `yaml:"provider"`
Region string `yaml:"region"`
Environment string `yaml:"environment"`
GitopsAuthMethod string `yaml:"gitops_auth_method"`
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
BaseDomain string `yaml:"base_domain,omitempty"`
AdminEmail string `yaml:"admin_email,omitempty"`
KubernetesVersion string `yaml:"kubernetes_version,omitempty"`
CNI string `yaml:"cni,omitempty"`
SSHUser string `yaml:"ssh_user,omitempty"`
}
ClusterDefaultsConfig contains default values applied when generating new cluster configurations via "opencenter cluster init". These values are injected into the cluster config YAML when the corresponding field is not already set.
type ConfigError ¶
type ConfigError struct {
Type string // validation, permission, path, format
Field string // dot notation path to problematic field
Value interface{}
Message string
Repaired bool // indicates if the error was automatically repaired
}
ConfigError represents configuration-related errors with actionable messages.
func (*ConfigError) Error ¶
func (ce *ConfigError) Error() string
func (*ConfigError) Suggestions ¶
func (ce *ConfigError) Suggestions() []string
Suggestions returns actionable suggestions for fixing the configuration error.
type ConfigManager ¶
type ConfigManager struct {
// contains filtered or unexported fields
}
ConfigManager handles CLI configuration loading, validation, and merging.
func NewConfigManager ¶
func NewConfigManager(configPath string) (*ConfigManager, error)
NewConfigManager creates a new configuration manager with the specified config path. If configPath is empty, it uses the default CLI configuration location.
func NewConfigManagerWithConfig ¶
func NewConfigManagerWithConfig(config *CLIConfig) (*ConfigManager, error)
NewConfigManagerWithConfig creates a new configuration manager with an existing configuration. This is useful for creating temporary managers for applying overrides.
func (*ConfigManager) GetConfig ¶
func (cm *ConfigManager) GetConfig() *CLIConfig
GetConfig returns the current configuration.
func (*ConfigManager) GetConfigPath ¶
func (cm *ConfigManager) GetConfigPath() string
GetConfigPath returns the path to the configuration file.
func (*ConfigManager) GetValidationSummary ¶
func (cm *ConfigManager) GetValidationSummary() string
GetValidationSummary returns a human-readable summary of validation results.
func (*ConfigManager) GetValue ¶
func (cm *ConfigManager) GetValue(key string) (interface{}, error)
GetValue gets a configuration value using dot notation.
func (*ConfigManager) Load ¶
func (cm *ConfigManager) Load() error
Load loads the CLI configuration from the file system. If the file doesn't exist, it creates it with default values.
func (*ConfigManager) LoadWithConfig ¶
func (cm *ConfigManager) LoadWithConfig(config *CLIConfig) error
LoadWithConfig loads the configuration manager with an existing configuration. This is useful for applying runtime overrides without modifying the file.
func (*ConfigManager) RepairConfig ¶
func (cm *ConfigManager) RepairConfig() (*ValidationResult, error)
RepairConfig attempts to repair configuration issues and returns the results.
func (*ConfigManager) Reset ¶
func (cm *ConfigManager) Reset() error
Reset resets the configuration to default values.
func (*ConfigManager) Save ¶
func (cm *ConfigManager) Save() error
Save saves the current configuration to the file system.
func (*ConfigManager) SetValue ¶
func (cm *ConfigManager) SetValue(key string, value interface{}) error
SetValue sets a configuration value using dot notation.
func (*ConfigManager) ValidateConfig ¶
func (cm *ConfigManager) ValidateConfig() *ValidationResult
ValidateConfig performs comprehensive validation and returns detailed results.
type ConfigValidator ¶
type ConfigValidator struct {
// contains filtered or unexported fields
}
ConfigValidator validates configuration values and structure.
func (*ConfigValidator) Validate ¶
func (cv *ConfigValidator) Validate(config *CLIConfig) error
Validate validates the CLI configuration and returns the first error found.
func (*ConfigValidator) ValidateWithResult ¶
func (cv *ConfigValidator) ValidateWithResult(config *CLIConfig) *ValidationResult
ValidateWithResult performs comprehensive validation and returns detailed results.
type ConfigurationManager ¶
type ConfigurationManager = v2.ConfigurationManager
ConfigurationManager re-exported from v2.
func NewConfigurationManager ¶
func NewConfigurationManager() (*ConfigurationManager, error)
NewConfigurationManager creates a ConfigurationManager with default dependencies resolved from CLI configuration.
type FileConfig ¶
type FileConfig = logging.FileConfig
FileConfig controls file logging rotation settings. Deprecated: Use logging.FileConfig directly.
type LoggingConfig ¶
type LoggingConfig = logging.LoggingConfig
LoggingConfig controls logging behavior including level, format, output, and file rotation. Deprecated: Use logging.LoggingConfig directly.
type PathsConfig ¶
type PathsConfig struct {
SettingsDir string `yaml:"settingsDir"`
ClustersDir string `yaml:"clustersDir"`
BlueprintsDir string `yaml:"blueprintsDir"`
GitOpsDir string `yaml:"gitopsDir"`
ClusterStateDir string `yaml:"clusterStateDir"`
SecretsDir string `yaml:"secretsDir"`
PluginsDir string `yaml:"pluginsDir"`
StateDir string `yaml:"stateDir"`
}
PathsConfig controls default paths for configuration and clusters.
type ValidationResult ¶
type ValidationResult struct {
Valid bool
Errors []*ConfigError
Warnings []*ConfigError
Repaired []*ConfigError
}
ValidationResult contains the results of configuration validation.