collector

package
v2.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package configcollector can be used to merge configuration from different sources into one YAML.

Index

Constants

View Source
const DefaultHeader = "#cloud-config"

Variables

View Source
var MergeBootLine = func(o *Options) error {
	o.MergeBootCMDLine = true
	return nil
}
View Source
var ValidFileHeaders = []string{
	"#cloud-config",
	"#kairos-config",
	"#node-config",
}

Functions

func DeepMerge added in v2.0.3

func DeepMerge(a, b interface{}) (interface{}, error)

DeepMerge takes two data structures and merges them together deeply. The results can vary depending on how the arguments are passed since structure B will always overwrite what's on A.

func HasValidHeader

func HasValidHeader(data string) bool

Types

type Config

type Config map[string]interface{}

We don't allow yamls that are plain arrays because is has no use in Kairos and there is no way to merge an array yaml with a "map" yaml.

func ParseCmdLine

func ParseCmdLine(file string, filter func(d []byte) ([]byte, error)) (*Config, error)

ParseCmdLine reads options from the kernel cmdline and returns the equivalent Config.

func Scan

func Scan(o *Options, filter func(d []byte) ([]byte, error)) (*Config, error)

func (Config) ConfigURL

func (c Config) ConfigURL() string

ConfigURL returns the value of config_url if set or empty string otherwise.

func (*Config) MergeConfig

func (c *Config) MergeConfig(newConfig *Config) error

MergeConfig merges the config passed as parameter back to the receiver Config.

func (*Config) MergeConfigURL

func (c *Config) MergeConfigURL() error

MergeConfigURL looks for the "config_url" key and if it's found it downloads the remote config and merges it with the current one. If the remote config also has config_url defined, it is also fetched recursively until a remote config no longer defines a config_url. NOTE: The "config_url" value of the final result is the value of the last config file in the chain because we replace values when we merge.

func (Config) Query

func (c Config) Query(s string) (res string, err error)

func (*Config) String

func (c *Config) String() (string, error)

String returns a string which is a Yaml representation of the Config.

type Configs

type Configs []*Config

func (Configs) Merge

func (cs Configs) Merge() (*Config, error)

type Option

type Option func(o *Options) error
var NoLogs Option = func(o *Options) error {
	o.NoLogs = true
	return nil
}

func Directories

func Directories(d ...string) Option

func StrictValidation

func StrictValidation(v bool) Option

func WithBootCMDLineFile

func WithBootCMDLineFile(s string) Option

type Options

type Options struct {
	ScanDir          []string
	BootCMDLineFile  string
	MergeBootCMDLine bool
	NoLogs           bool
	StrictValidation bool
}

func (*Options) Apply

func (o *Options) Apply(opts ...Option) error

func (*Options) SoftErr

func (o *Options) SoftErr(message string, err error)

SoftErr prints a warning if err is no nil and NoLogs is not true. It's use to wrap the same handling happening in multiple places.

TODO: Switch to a standard logging library (e.g. verbose, silent mode etc).

Jump to

Keyboard shortcuts

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