Documentation
¶
Overview ¶
Package config provides global configuration management via context propagation.
Index ¶
- Variables
- func AnalyzeMigration(path string) (string, error)
- func ConvertV1ToV2(v1Cfg *v1.CaproniConfig) (*v2.CaproniConfig, error)
- func FindConfigFile() (string, error)
- func LoadCaproniConfig(gc *GlobalConfig) (*v2.CaproniConfig, error)
- func PreviewMigration(path string) (string, error)
- func RequireV2OrMigrate(path string) error
- func ValidateSemantics(cfg *v2.CaproniConfig) error
- func WithContext(ctx context.Context, cfg *GlobalConfig) context.Context
- type ConfigVersion
- type GlobalConfig
- type MigrationOptions
- type MigrationResult
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConfigFileNotFound is returned when the configuration file is not found. ErrConfigFileNotFound = errors.New("configuration file not found") // ErrNoConfigFileFound is returned when no config file is found in the directory tree. ErrNoConfigFileFound = errors.New("no caproni.yaml found in current directory or any parent directory up to home directory") // ErrInvalidYAML is returned when the YAML syntax is invalid. ErrInvalidYAML = errors.New("invalid YAML syntax") // ErrSchemaValidation is returned when schema validation fails. ErrSchemaValidation = errors.New("configuration does not match schema") // ErrSemanticValidation is returned when semantic validation fails. ErrSemanticValidation = errors.New("configuration semantic validation failed") // ErrReferenceNotFound is returned when a referenced item is not found. ErrReferenceNotFound = errors.New("referenced item not found") // ErrPathNotFound is returned when a referenced file path does not exist. ErrPathNotFound = errors.New("referenced file path not found") // ErrDeprecatedVersion is returned when a deprecated configuration version is used. ErrDeprecatedVersion = errors.New("deprecated configuration version") // ErrInvalidClusterDriver is returned when the cluster driver is invalid. ErrInvalidClusterDriver = errors.New("invalid cluster driver") // ErrInvalidMemoryFormat is returned when the memory format is invalid. ErrInvalidMemoryFormat = errors.New("invalid memory format") // ErrInvalidNamespace is returned when the namespace format is invalid. ErrInvalidNamespace = errors.New("invalid namespace format") // ErrInvalidRepoType is returned when the repository type is invalid. ErrInvalidRepoType = errors.New("invalid repository type") // ErrInvalidKubeType is returned when the kubernetes type is invalid. ErrInvalidKubeType = errors.New("invalid kubernetes type") )
var ( // ErrLegacyConfig is returned when a v1 config is detected and migration is required. ErrLegacyConfig = errors.New("legacy configuration format detected") // ErrUnsupportedVersion is returned when the config version is not supported. ErrUnsupportedVersion = errors.New("unsupported config version") )
var ( // ErrAlreadyMigrated is returned when attempting to migrate a config that's already v2. ErrAlreadyMigrated = errors.New("config is already migrated, no migration needed") )
var ErrConfigNotFound = errors.New("GlobalConfig not found in context")
ErrConfigNotFound is returned when GlobalConfig is not found in context.
var ( // ErrUnknownRepositoryType is returned when a v1 repository has an unknown type. ErrUnknownRepositoryType = errors.New("unknown repository type") )
Functions ¶
func AnalyzeMigration ¶
AnalyzeMigration analyzes a v1 config and returns a human-readable summary of what would be migrated.
func ConvertV1ToV2 ¶
func ConvertV1ToV2(v1Cfg *v1.CaproniConfig) (*v2.CaproniConfig, error)
ConvertV1ToV2 converts a v1 CaproniConfig to v2 format. This is used during migration and when loading v1 configs. Returns error if the conversion encounters issues (e.g., conflicting repository definitions).
func FindConfigFile ¶
FindConfigFile searches for a caproni.yaml file starting from the current directory and walking up the directory tree until it reaches either the root directory or the user's home directory. Returns the absolute path to the first caproni.yaml found, or an error if none is found.
func LoadCaproniConfig ¶
func LoadCaproniConfig(gc *GlobalConfig) (*v2.CaproniConfig, error)
LoadCaproniConfig loads and parses the caproni.yaml configuration file. Returns a v2 CaproniConfig regardless of input version. V1 configs are automatically converted to v2 format. The config file path and version defaults (such as CopySleepImage) are read from gc.
func PreviewMigration ¶
PreviewMigration generates a preview of what the migrated config would look like.
func RequireV2OrMigrate ¶
RequireV2OrMigrate checks if a config file is v2, and if not, returns an error with migration instructions.
func ValidateSemantics ¶
func ValidateSemantics(cfg *v2.CaproniConfig) error
ValidateSemantics performs semantic validation on a v2 configuration. This checks referential integrity, file paths, and other semantic constraints beyond what the JSON schema enforces.
func WithContext ¶
func WithContext(ctx context.Context, cfg *GlobalConfig) context.Context
WithContext returns a new context with the GlobalConfig stored in it.
Types ¶
type ConfigVersion ¶
type ConfigVersion int
ConfigVersion represents a configuration version.
const ( // VersionUnknown indicates the version could not be determined. VersionUnknown ConfigVersion = 0 // Version1 indicates v1 configuration format (repositories with type field). Version1 ConfigVersion = 1 // Version2 indicates v2 configuration format (separate deployers/reloaders). Version2 ConfigVersion = 2 )
func DetectVersionFromBytes ¶
func DetectVersionFromBytes(data []byte) (ConfigVersion, error)
DetectVersionFromBytes detects the configuration version from raw YAML bytes.
func DetectVersionFromFile ¶
func DetectVersionFromFile(path string) (ConfigVersion, error)
DetectVersionFromFile detects the configuration version from a file path.
func (ConfigVersion) String ¶
func (v ConfigVersion) String() string
String returns a string representation of the version.
type GlobalConfig ¶
type GlobalConfig struct {
// ConfigFile is the path to the caproni.yaml configuration file
ConfigFile string
// ProfileName is the name of the cluster profile to use.
// This allows multiple isolated cluster instances.
ProfileName string
// contains filtered or unexported fields
}
GlobalConfig holds all global configuration options that can be set via persistent flags on the root command.
func FromContext ¶
func FromContext(ctx context.Context) *GlobalConfig
FromContext retrieves the GlobalConfig from the context. Returns nil if no config is found.
func MustFromContext ¶
func MustFromContext(ctx context.Context) *GlobalConfig
MustFromContext retrieves the GlobalConfig from the context. Panics if no config is found. This should only be used in command RunE functions where we're guaranteed the config exists.
func NewGlobalConfig ¶
func NewGlobalConfig(embeddedVersions map[string]string) *GlobalConfig
NewGlobalConfig creates a new GlobalConfig with sensible defaults.
func (*GlobalConfig) GetToolVersion ¶
func (gc *GlobalConfig) GetToolVersion(key string) (string, bool)
GetToolVersion retrieves a tool version from the embedded CI version files. It lazy-loads and parses the YAML files on first call, then caches the results. Returns the version string and true if found, or empty string and false if not found. Panics if YAML parsing fails, as this indicates a build-time issue with embedded files.
type MigrationOptions ¶
type MigrationOptions struct {
// DryRun performs the migration without writing files.
DryRun bool
// BackupSuffix is the suffix to append to the backup file (default: .bak).
BackupSuffix string
// SkipBackup skips creating a backup file (use with caution).
SkipBackup bool
}
MigrationOptions contains options for the migration.
func DefaultMigrationOptions ¶
func DefaultMigrationOptions() *MigrationOptions
DefaultMigrationOptions returns default migration options.
type MigrationResult ¶
type MigrationResult struct {
OriginalFile string
BackupFile string
Version ConfigVersion
Repositories int
Deployers int
Reloaders int
}
MigrationResult contains the results of a migration operation.
func MigrateConfig ¶
func MigrateConfig(path string, opts *MigrationOptions) (*MigrationResult, error)
MigrateConfig migrates a v1 configuration file to v2 format. Returns the migration result and any error encountered.
type ValidationError ¶
type ValidationError struct {
Errors []error
}
ValidationError aggregates multiple validation errors.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package types contains shared configuration types used across config versions.
|
Package types contains shared configuration types used across config versions. |
|
Package v1 provides configuration structures for Caproni v1 format.
|
Package v1 provides configuration structures for Caproni v1 format. |
|
Package v2 provides configuration structures for Caproni v2 format.
|
Package v2 provides configuration structures for Caproni v2 format. |