Documentation
¶
Overview ¶
Package config finds, validates, merges and resolves the clusterctl configuration.
Each file is a stream of YAML documents. A document is decoded into a plain tree first, validated against the schema of its kind, and only then merged, so that a typo is reported at the line it was written on rather than wherever the merged value happens to be used.
Index ¶
- Constants
- func CacheDir() (string, error)
- func ConfigDirs() []string
- func Decode(data map[string]any, target any) error
- func EnvEntries(env func(string) string) []string
- func ExpandEntries(entries []string) ([]string, error)
- func ExpandPath(path, base string) string
- func ExpandSearchDirs(dirs []string) ([]string, error)
- func FormatValue(v any) string
- func ParseSetValue(raw string) (any, error)
- func QuoteYAML(s string) string
- func SchemaJSON(kind string) ([]byte, error)
- func SchemaKinds() []string
- func SearchEntries(env func(string) string) []string
- func SearchPath(env func(string) string) ([]string, error)
- func SecretKeys(doc *Document) []string
- func SecretSections() []string
- func SecretValues(file string, sections map[string]map[string]string) (map[string][]byte, error)
- func StateDir() (string, error)
- func UserConfigDir() (string, error)
- func ValidateDocument(doc *Document) error
- type Bundle
- type Document
- type Origin
- type ResolveOptions
- type Resolved
- type ScaffoldFile
- type ScaffoldOptions
- type Tree
- func (t *Tree) Data() map[string]any
- func (t *Tree) MergeDocument(layer string, doc *Document, from, into string)
- func (t *Tree) MergeDocumentExcept(layer string, doc *Document, from, into string, except ...string)
- func (t *Tree) Origin(path string) (Origin, bool)
- func (t *Tree) Origins() map[string]Origin
- func (t *Tree) Paths() []string
- func (t *Tree) SetPath(layer, path string, value any, o Origin) error
- func (t *Tree) Value(path string) any
Constants ¶
const ( // EnvConfig lists the configuration files or directories to read, most // general first, separated the way PATH is. It replaces the search path // entirely. EnvConfig = "CLUSTERCTL_CONFIG" // EnvContext selects the context, as --context does. EnvContext = "CLUSTERCTL_CONTEXT" // EnvNodes holds the node set commands act on when -n is not given. EnvNodes = "CLUSTERCTL_NODES" // EnvProgress chooses how progress is shown when --progress is not // given. EnvProgress = "CLUSTERCTL_PROGRESS" // EnvProgressLog names the file the progress events of a command are // appended to when --progress-log is not given. EnvProgressLog = "CLUSTERCTL_PROGRESS_LOG" )
Environment variables that steer where configuration and state live, and stand in for global flags that are not given.
Variables ¶
This section is empty.
Functions ¶
func CacheDir ¶
CacheDir returns the directory holding fetched copies of remote files and resolved group listings.
func ConfigDirs ¶
func ConfigDirs() []string
ConfigDirs returns the directories searched for configuration when CLUSTERCTL_CONFIG is not set, most specific last.
func Decode ¶
Decode converts a parsed document into a typed value, rejecting keys the type does not define.
func EnvEntries ¶ added in v0.2.0
EnvEntries returns the files and directories CLUSTERCTL_CONFIG names, or nil when it is not set.
func ExpandEntries ¶
ExpandEntries turns files and directories into the list of files to read, in the order they are layered. A directory contributes its YAML files in name order.
Every entry has to exist. These are the ones named with --config or CLUSTERCTL_CONFIG, and one that is not there is most likely misspelled: leaving it out would take its currentContext and its overrides with it, and the command would run against another context without a word.
func ExpandPath ¶
ExpandPath expands a leading ~ and makes a relative path absolute against base, which is the directory the value was configured in.
func ExpandSearchDirs ¶ added in v0.3.0
ExpandSearchDirs is ExpandEntries for the directories of the built-in search path, which a site may or may not use: one that does not exist is skipped.
func FormatValue ¶
FormatValue renders a merged value the way config view prints it.
func ParseSetValue ¶
ParseSetValue reads the right hand side of a --set assignment. The value is read as YAML, so that "30s" stays a string, "8" becomes a number and "[a,b]" becomes a list.
func QuoteYAML ¶ added in v0.3.0
QuoteYAML writes a string as a double quoted YAML scalar. The escapes Go writes are a subset of the ones YAML reads.
func SchemaJSON ¶
SchemaJSON returns the JSON Schema of one kind, ready to be written to a file an editor can use.
func SchemaKinds ¶
func SchemaKinds() []string
SchemaKinds lists the kinds a schema can be produced for.
func SearchEntries ¶ added in v0.2.0
SearchEntries returns the files and directories configuration is read from when --config is not given: the entries of CLUSTERCTL_CONFIG when it is set, the configuration directories otherwise.
func SearchPath ¶
SearchPath returns the files to read, in the order they are layered. The entries of CLUSTERCTL_CONFIG have to exist; the configuration directories searched without it may not.
func SecretKeys ¶
SecretKeys lists the keys a Secret document holds, which are readable without decrypting it.
func SecretSections ¶ added in v0.3.0
func SecretSections() []string
SecretSections are the top level mappings of a Secret document that hold its values, which is what to ask the decryption for.
func SecretValues ¶
SecretValues turns the decrypted sections of a Secret document into its values by key, decoding binaryData. A value under data is used as written. No error quotes a value.
func StateDir ¶
StateDir returns the directory holding the generated ssh configuration, the control sockets and the BMC certificate pins.
func UserConfigDir ¶ added in v0.2.0
UserConfigDir returns the administrator's own configuration directory, usually ~/.config/clusterctl, which is searched after /etc/clusterctl.
func ValidateDocument ¶
ValidateDocument checks a document against the schema of its kind and reports every problem with the position it was written at.
Types ¶
type Bundle ¶
type Bundle struct {
// Files are the files that were read, in layering order.
Files []string
// Documents are all documents, in the order they were read.
Documents []*Document
// Config is the merged Config document.
Config v1alpha1.Config
// Sites, Clusters, Inventories and Workstations are indexed by name. A
// document without a name is stored under the empty string, which is
// what a single cluster installation usually has.
Sites map[string]*Document
Clusters map[string]*Document
Inventories map[string]*Document
Workstations map[string]*Document
// Secrets are the sops encrypted Secret documents, indexed by name.
// Their values stay encrypted until a command asks for one.
Secrets map[string]*Document
// contains filtered or unexported fields
}
Bundle is everything read from the configuration files, before a context selects what applies.
func Load ¶
Load reads the configuration files, validates every document against the schema of its kind and indexes them by name.
Validation happens per document, before anything is merged, so a mistake is reported at the line it was written on.
func (*Bundle) ContextNames ¶
ContextNames lists the configured contexts in the order they were read.
type Document ¶
type Document struct {
// File is the file the document was read from.
File string
// Index is its position in that file, counted from zero.
Index int
// APIVersion and Kind are taken from the document itself.
APIVersion string
Kind string
// Data is the document as a plain tree of map[string]any, []any and
// scalars.
Data map[string]any
// Positions maps a dotted path to the position its value was written at.
Positions map[string]Origin
}
Document is one YAML document together with the positions of its values.
func ParseDocuments ¶
ParseDocuments reads a YAML stream into documents, recording where every value was written.
type Origin ¶
type Origin struct {
// Layer names the merge layer, "site", "cluster", "context" and so on.
Layer string `json:"layer" yaml:"layer"`
// File is the file the value was written in, empty for values that were
// not read from a file.
File string `json:"file,omitempty" yaml:"file,omitempty"`
// Line and Column locate the value in that file.
Line int `json:"line,omitempty" yaml:"line,omitempty"`
Column int `json:"column,omitempty" yaml:"column,omitempty"`
}
Origin says where a value came from.
type ResolveOptions ¶
type ResolveOptions struct {
// Context selects the context; empty takes the current one.
Context string
// Env reads environment variables; nil reads the process environment.
Env func(string) string
// Set are the --set assignments, applied last.
Set map[string]string
// Fanout is what --fanout gave, zero when it was not given. It is
// applied with the flags, after --set, so that config explain reports
// the value the commands use.
Fanout int
}
ResolveOptions carry the layers that do not come from files.
type Resolved ¶
type Resolved struct {
// Context is the context that was selected.
Context v1alpha1.Context
// SiteName and ClusterName name the documents that were used.
SiteName string
ClusterName string
// Spec is the merged configuration.
Spec v1alpha1.EffectiveSpec
// Tree is the merged tree with the origin of every value.
Tree *Tree
// Bundle is the configuration the resolution started from.
Bundle *Bundle
// BaseDir is the directory relative paths in the configuration resolve
// against, the directory of the Site document.
BaseDir string
}
Resolved is the configuration one command runs against, together with the provenance of every value in it.
func (*Resolved) FromCommandLine ¶ added in v0.3.0
FromCommandLine reports whether the value at a dotted path was given in the environment or on the command line rather than in a document, by the path itself or by a section it is part of. A relative path given there means what it means to the shell it was typed in, not what it means to the site.
type ScaffoldFile ¶ added in v0.2.0
type ScaffoldFile struct {
// Name is the file name, without a directory.
Name string
// Kind and DocName describe the document the file holds.
Kind string
DocName string
// Data is the content to write.
Data []byte
}
ScaffoldFile is one file of a new configuration.
func Scaffold ¶ added in v0.2.0
func Scaffold(opts ScaffoldOptions) ([]ScaffoldFile, error)
Scaffold renders the least configuration that resolves: a Config with one context, a Site, a Cluster and an empty NodeInventory, one document to a file, with comments saying what to fill in.
The files are loaded and resolved the way files read from disk are before they are returned, so a value that would not resolve is reported instead of written.
type ScaffoldOptions ¶ added in v0.2.0
type ScaffoldOptions struct {
// Site names the Site document, and the NodeInventory of its nodes.
Site string
// Cluster names the Cluster document and the context that acts on it.
Cluster string
// Domain is the DNS domain of the cluster nodes, domains.hpc.
Domain string
// Login is the host name of the login node. Empty takes login in
// Domain.
Login string
// User is the remote account of the context. Empty leaves it to ssh.
User string
}
ScaffoldOptions are the values a new configuration is written with.
func ScaffoldDefaults ¶ added in v0.2.0
func ScaffoldDefaults() ScaffoldOptions
ScaffoldDefaults returns the values a scaffold is written with when nothing else is given: those of the example site.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a configuration tree being built up layer by layer, together with the origin of every value in it.
func (*Tree) MergeDocument ¶
MergeDocument merges the body of a document into the tree, attributing every value it sets to the given layer. Only the subtree named by prefix is taken; an empty prefix takes the whole document body.
Mappings merge key by key. Sequences and scalars replace what was there, because a list of naming rules or of protected hosts only makes sense as a whole.
func (*Tree) MergeDocumentExcept ¶
func (t *Tree) MergeDocumentExcept(layer string, doc *Document, from, into string, except ...string)
MergeDocumentExcept is MergeDocument without the named top level keys of the merged subtree.
It keeps a document's own overrides table out of the merged tree: the overrides are applied by path, and mirroring them as data as well would show every override twice, once under its own path and once nested under the table it was written in.
func (*Tree) SetPath ¶
SetPath applies one override, the way an overrides table, an environment variable or --set does. The path is dotted; the value is checked against the schema of the merged configuration before anything is changed.
A mapping value merges key by key, the way a mapping in a document does: an override written as safety: {confirmAbove: 4} changes confirmAbove and leaves the protected hosts alone.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package configtest writes configuration directories for the tests of the packages that read one.
|
Package configtest writes configuration directories for the tests of the packages that read one. |