config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const Selector = annotations.Config + "=true"

Selector label selector for installer configuration.

Variables

View Source
var (
	// ErrInvalidConfig indicates the configuration content is invalid.
	ErrInvalidConfig = errors.New("invalid configuration")
	// ErrEmptyConfig indicates the configuration file is empty.
	ErrEmptyConfig = errors.New("empty configuration")
	// ErrUnmarshalConfig indicates the configuration file structure is invalid.
	ErrUnmarshalConfig = errors.New("failed to unmarshal configuration")
)
View Source
var (
	// ErrConfigMapNotFound when the configmap isn't created in the cluster.
	ErrConfigMapNotFound = errors.New("cluster configmap not found")
	// ErrMultipleConfigMapFound when the label selector find multiple resources.
	ErrMultipleConfigMapFound = errors.New("multiple cluster configmaps found")
	// ErrIncompleteConfigMap when the ConfigMap exists, but doesn't contain the
	// expected payload.
	ErrIncompleteConfigMap = errors.New("invalid configmap found in the cluster")
)
View Source
var DefaultRelativeConfigPath = constants.ConfigFilename

DefaultRelativeConfigPath default relative path to YAML configuration file.

Functions

func ConvertStringMapToAny

func ConvertStringMapToAny(m map[string]string) map[string]any

ConvertStringMapToAny converts a map[string]string to a map[string]any.

func FindNode

func FindNode(node *yaml.Node, key string) (*yaml.Node, error)

FindNode searches for a specific key within a YAML node structure.

It traverses the YAML node structure:

  • If the node is a DocumentNode, it unwraps to its first content node and recurses.
  • If the node is a MappingNode, it first checks if the key exists directly within the current mapping. If not found, it recursively searches within the values of the current mapping.
  • For any other node kind, it returns an error.

Returns the yaml.Node corresponding to the found key's value, or an error if the key is not found, or the node kind is unsupported.

func FlattenMap

func FlattenMap(input any, prefix string) (map[string]interface{}, error)

FlattenMap flattens a given input into a single-level map. If the input is a map[string]any, it calls FlattenMapRecursive to flatten it, using the provided prefix for keys. If the input is not a map, it treats the entire input as a single value and assigns it to the given prefix.

func FlattenMapRecursive

func FlattenMapRecursive(
	input map[string]any,
	prefix string,
	output map[string]any,
)

FlattenMapRecursive recursively flattens a nested map[string]any into a single-level map. Keys are concatenated with dots to represent their original hierarchy ("key path").

func UpdateMappingValue

func UpdateMappingValue(node *yaml.Node, key string, newValue any) error

UpdateMappingValue updates a key's value within a YAML mapping node.

It traverses the YAML node structure:

  • If the node is a DocumentNode, it delegates to its first content node. If the DocumentNode is empty, it creates a root mapping node.
  • If the node is a MappingNode, it searches for the specified key. If found, it marshals the newValue to YAML and unmarshals it back into a new yaml.Node to preserve type fidelity, then replaces the existing value node. If the key is not found, it returns nil.
  • For any other node kind, it returns an error.

func UpdateNestedValue

func UpdateNestedValue(node *yaml.Node, keyPath []string, newValue any) error

UpdateNestedValue updates a value deep within a YAML node structure by traversing a given path of keys. The path of keys represents the hierarchy of the yaml.Node structure.

It handles different node kinds and path lengths:

  • If the path is empty, it returns an error.
  • If the path contains only one key, it delegates to UpdateMappingValue.
  • If the node is a DocumentNode, it unwraps to its first content node and recurses.
  • If the node is a MappingNode, it iterates through its content to find the first key in the path. If found, it recursively calls itself on the corresponding value node with the rest of the path. If the key is not found, it returns an error.
  • For any other node kind, it returns an error, as navigation is not possible.

Types

type Config

type Config struct {
	Installer Spec `yaml:"-"` // root configuration for the installer
	// contains filtered or unexported fields
}

Config root configuration structure.

func NewConfigDefault

func NewConfigDefault(
	cfs *chartfs.ChartFS,
	namespace string,
	appName string,
) (*Config, error)

NewConfigDefault returns a new Config instance with default values, i.e. the configuration payload is loading embedded data.

func NewConfigFromBytes

func NewConfigFromBytes(
	payload []byte,
	namespace string,
	appName string,
) (*Config, error)

NewConfigFromBytes instantiates a new Config from the bytes payload informed.

func NewConfigFromFile

func NewConfigFromFile(
	cfs *chartfs.ChartFS,
	configPath string,
	namespace string,
	appName string,
) (*Config, error)

NewConfigFromFile returns a new Config instance based on the informed file.

func (*Config) ApplyDefaults

func (c *Config) ApplyDefaults()

ApplyDefaults applies default values to the configuration.

func (*Config) DecodeNode

func (c *Config) DecodeNode() error

DecodeNode returns a struct converted from *yaml.Node.

func (*Config) GetEnabledProducts

func (c *Config) GetEnabledProducts() Products

GetEnabledProducts returns a map of enabled products.

func (*Config) GetProduct

func (c *Config) GetProduct(name string) (*Product, error)

GetProduct returns a product by name, or an error if the product is not found.

func (*Config) MarshalYAML

func (c *Config) MarshalYAML() ([]byte, error)

MarshalYAML marshals the Config into a YAML byte array.

func (*Config) Namespace

func (c *Config) Namespace() string

Namespace returns the installer's namespace.

func (*Config) Set

func (c *Config) Set(key string, configData any) error

Set returns new configuration with updates.

func (*Config) SetProduct

func (c *Config) SetProduct(name string, spec Product) error

SetProduct updates an existing product specification in the configuration. It searches for a product by its name and, if found, replaces its specification with the provided `spec`. The configuration is then re-decoded to reflect the changes.

func (*Config) String

func (c *Config) String() string

String returns this configuration as string, indented with two spaces.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(payload []byte) error

UnmarshalYAML Un-marshals the YAML payload into the Config struct, checking the validity of the configuration.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates the configuration, checking for missing fields.

type ConfigMapManager

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

ConfigMapManager the actor responsible for managing installer configuration in the cluster.

func NewConfigMapManager

func NewConfigMapManager(kube k8s.Interface, appName string) *ConfigMapManager

NewConfigMapManager instantiates the ConfigMapManager. The appName parameter is used to generate the ConfigMap name as "{appName}-config" and, with hyphens replaced by underscores, as the YAML root key for config decoding.

func (*ConfigMapManager) Create

func (m *ConfigMapManager) Create(ctx context.Context, cfg *Config) error

Create Bootstrap a ConfigMap with the provided configuration.

func (*ConfigMapManager) Delete

func (m *ConfigMapManager) Delete(ctx context.Context) error

Delete find and delete the ConfigMap from the cluster.

func (*ConfigMapManager) GetConfig

func (m *ConfigMapManager) GetConfig(ctx context.Context) (*Config, error)

GetConfig retrieves configuration from a cluster's ConfigMap.

func (*ConfigMapManager) GetConfigMap

func (m *ConfigMapManager) GetConfigMap(
	ctx context.Context,
) (*corev1.ConfigMap, error)

GetConfigMap retrieves the ConfigMap from the cluster, checking if a single resource is present.

func (*ConfigMapManager) Name

func (m *ConfigMapManager) Name() string

Name returns the ConfigMap name.

func (*ConfigMapManager) Update

func (m *ConfigMapManager) Update(ctx context.Context, cfg *Config) error

Update updates a ConfigMap with informed configuration.

type Product

type Product struct {
	// Name of the product.
	Name string `yaml:"name"`
	// Enabled product toggle.
	Enabled bool `yaml:"enabled"`
	// Namespace target namespace for product's dependency (Helm chart). If empty,
	// it defaults to the installer's namespace.
	Namespace *string `yaml:"namespace,omitempty"`
	// Properties contains the product specific configuration.
	Properties map[string]interface{} `yaml:"properties"`
}

ProductSpec contains the configuration for a specific product.

func (*Product) GetNamespace

func (p *Product) GetNamespace() string

GetNamespace returns the product namespace, or an empty string if not set.

func (*Product) KeyName

func (p *Product) KeyName() string

KeyName returns a sanitized key name for the product.

func (*Product) Validate

func (p *Product) Validate() error

Validate validates the product configuration, checking for missing fields.

type Products

type Products []Product

ProductSpec represents a map of product name and specification.

type Settings

type Settings map[string]interface{}

Settings represents a map of configuration settings.

type Spec

type Spec struct {
	// Settings contains the configuration for the installer settings.
	Settings Settings `yaml:"settings"`
	// Products contains the configuration for the installer products.
	Products Products `yaml:"products"`
}

Spec contains all configuration sections.

Jump to

Keyboard shortcuts

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