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
- func ConfigDirs() []string
- func Decode(data map[string]any, target any) error
- func EnvEntries(env func(string) string) []string
- func EnvOverrides() map[string]string
- func ExpandEntries(entries []string) ([]string, error)
- func ExpandPath(path, base string) string
- func FormatValue(v any) string
- func ParseSetValue(raw string) (any, error)
- 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 SecretValues(file string, plaintext []byte) (map[string][]byte, error)
- func StateDir() string
- 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) MergeMap(layer string, value map[string]any)
- 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
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" )
Environment variables that steer where configuration and state live.
Variables ¶
This section is empty.
Functions ¶
func CacheDir ¶
func CacheDir() string
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 EnvOverrides ¶
EnvOverrides lists the environment variables that override configuration, for the documentation and for doctor.
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; an entry that does not exist is skipped, because the search path names places a site may or may not use.
func ExpandPath ¶
ExpandPath expands a leading ~ and makes a relative path absolute against base, which is the directory the value was configured in.
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 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.
func SecretKeys ¶
SecretKeys lists the keys a Secret document holds, which are readable without decrypting it.
func SecretValues ¶
SecretValues reads the values out of the decrypted form of a Secret document, decoding binaryData.
func StateDir ¶
func StateDir() string
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
}
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 LoadDefault ¶
LoadDefault reads the configuration from the search path.
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
}
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.
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.