Documentation
¶
Overview ¶
Package distrocfg defines the standard interface that all distro config settings
Index ¶
- Constants
- Variables
- func NodeLabelsMapToList(m map[string]string) []string
- func RemoveStaleFiles(h *cluster.ZarfHost, dirs []ManagedDir, desired map[string]DesiredFile) error
- func StaleFiles(h *cluster.ZarfHost, dirs []ManagedDir, desired map[string]DesiredFile) []string
- type AdminCredentials
- type Common
- func (r *Common) BinaryName() string
- func (r *Common) BinaryPath() string
- func (r *Common) ConfigPath() string
- func (r *Common) DataDirPath() string
- func (r *Common) GetControllerService() string
- func (r *Common) GetWorkerService() string
- func (r *Common) JoinTokenPath() string
- func (r *Common) PackageStagingDir() string
- func (r *Common) SetPath(key string, value string) error
- type DesiredFile
- type Distro
- type K3S
- func (d *K3S) AdminCredentials(host *cluster.ZarfHost, dataDir string) (AdminCredentials, error)
- func (d *K3S) KubeconfigPath(_ *cluster.ZarfHost, _ string) string
- func (d *K3S) KubectlCmdf(host *cluster.ZarfHost, dataDir string, s string, args ...any) string
- func (d *K3S) StopControllerService(h *cluster.ZarfHost) error
- func (d *K3S) StopWorkerService(h *cluster.ZarfHost) error
- type ManagedDir
- type RKE2
- func (d *RKE2) AdminCredentials(host *cluster.ZarfHost, dataDir string) (AdminCredentials, error)
- func (d *RKE2) KubeconfigPath(_ *cluster.ZarfHost, _ string) string
- func (d *RKE2) KubectlCmdf(host *cluster.ZarfHost, dataDir string, s string, args ...any) string
- func (d *RKE2) StopControllerService(h *cluster.ZarfHost) error
- func (d *RKE2) StopWorkerService(h *cluster.ZarfHost) error
- type RancherCommon
- func (d *RancherCommon) CleanupPaths() []string
- func (d *RancherCommon) ConfigureEngine(ctx context.Context, host *cluster.ZarfHost, run cluster.ZarfRuntimeMeta, ...) error
- func (d *RancherCommon) DesiredFiles(host *cluster.ZarfHost, run cluster.ZarfRuntimeMeta, dis distro.ZarfDistro) (map[string]DesiredFile, error)
- func (d *RancherCommon) DistroCmdf(template string, args ...any) string
- func (d *RancherCommon) GetClusterCIDR(dis distro.ZarfDistro) []string
- func (d *RancherCommon) JoinTokenPathAgent() string
- func (d *RancherCommon) ManagedDirs() []ManagedDir
- func (d *RancherCommon) RunningVersion(host *cluster.ZarfHost) (string, error)
- type Upstream
- func (d *Upstream) AdminCredentials(host *cluster.ZarfHost, dataDir string) (AdminCredentials, error)
- func (d *Upstream) CleanupPaths() []string
- func (d *Upstream) ConfigureEngine(_ context.Context, _ *cluster.ZarfHost, _ cluster.ZarfRuntimeMeta, ...) error
- func (d *Upstream) DesiredFiles(_ *cluster.ZarfHost, _ cluster.ZarfRuntimeMeta, _ distro.ZarfDistro) (map[string]DesiredFile, error)
- func (d *Upstream) DistroCmdf(template string, args ...any) string
- func (d *Upstream) GetClusterCIDR(dis distro.ZarfDistro) []string
- func (d *Upstream) JoinTokenPathAgent() string
- func (d *Upstream) KubeconfigPath(_ *cluster.ZarfHost, _ string) string
- func (d *Upstream) KubectlCmdf(host *cluster.ZarfHost, dataDir string, s string, args ...any) string
- func (d *Upstream) ManagedDirs() []ManagedDir
- func (d *Upstream) RunningVersion(host *cluster.ZarfHost) (string, error)
- func (d *Upstream) StopControllerService(h *cluster.ZarfHost) error
- func (d *Upstream) StopWorkerService(h *cluster.ZarfHost) error
Constants ¶
const ( // Binary id string Binary = "Binary" // BinaryDir id string BinaryDir = "BinDir" // Config id string Config = "Config" // Token id string Token = "Token" // Data id string Data = "DataDir" // WorkerService id string WorkerService = "Worker" // ControllerService id string ControllerService = "Control" )
const (
// DistroK3S id
DistroK3S = "k3s"
)
const (
// DistroRKE2 id
DistroRKE2 = "rke2"
)
const DistroReleaseFile = "/etc/cargoship/distro-release.json"
DistroReleaseFile is the metadata file tracking the installed distro package on the host.
const (
// DistroUpstream id
DistroUpstream = "upstream"
)
const StateDir = "/etc/cargoship"
StateDir is where cargoship records state files describing the applied distro package.
Variables ¶
var ( // ErrVersionNotDetected if a version is not detected ErrVersionNotDetected = errors.New("failed to get version from the distro binary") // ErrPathKey if a path key is not used ErrPathKey = errors.New("key for set path does not exist") // ErrNotImplemented is returned by a distro module for capabilities its engine does not // support yet, so a caller sees a clear "not implemented" failure instead of a silent no-op. ErrNotImplemented = errors.New("not implemented for this distro") )
var ErrNoAdminCredentials = errors.New("admin kubeconfig has no admin credentials")
ErrNoAdminCredentials if the admin kubeconfig on the host does not carry a usable CA certificate and admin client key pair
Functions ¶
func NodeLabelsMapToList ¶
NodeLabelsMapToList takes a map and returns a string array for used by Kubernetes labels
func RemoveStaleFiles ¶
func RemoveStaleFiles(h *cluster.ZarfHost, dirs []ManagedDir, desired map[string]DesiredFile) error
RemoveStaleFiles deletes the files StaleFiles finds. It reports the first deletion error, so a file that cannot be removed is surfaced rather than left to be rediscovered on every run.
func StaleFiles ¶
func StaleFiles(h *cluster.ZarfHost, dirs []ManagedDir, desired map[string]DesiredFile) []string
StaleFiles returns the files under dirs that desired no longer names, sorted by path.
A managed directory holds only files cargoship put there, so a file in one that is not in the desired set was written for something the cluster configuration has since dropped -- a registry that no longer has an inline CA, say. Such a file is harmless while it sits there, since nothing references it, but it also never goes away on its own, and a certificate left behind on every node long after the registry is gone is the kind of thing that turns up in an audit rather than in a log.
A directory that does not exist, or that cannot be listed, contributes nothing: pruning is cleanup, and there is no point failing an apply over it.
Types ¶
type AdminCredentials ¶
type AdminCredentials struct {
// CertificateAuthority is the CA certificate the API server's serving cert is signed with
CertificateAuthority []byte
// ClientCertificate is the admin client certificate
ClientCertificate []byte
// ClientKey is the key for ClientCertificate
ClientKey []byte
}
AdminCredentials is the CA certificate and admin client key pair an engine writes on a controller host, in PEM form.
type Common ¶
type Common struct {
// Binary name of the engine binary
Binary string
// BinaryDir where the engine binary is stored in
BinaryDir string
// Config where the engine config is located
Config string
// Data where the engine data is located
Data string
// ID the id used to identify the distro
ID string
// PackageDir where staged .rpm/.deb package files are uploaded to. Empty means DataDirPath
// doubles as the staging directory -- see PackageStagingDir.
PackageDir string
// ServiceController the controller service
ServiceController string
// ServiceWorker the worker service
ServiceWorker string
// Token the token path
Token string
}
Common for all the distro's
func (*Common) BinaryName ¶
BinaryName returns the engine binary name
func (*Common) BinaryPath ¶
BinaryPath returns the full path to the engine binary
func (*Common) ConfigPath ¶
ConfigPath returns the full path for the config directory used by the engine
func (*Common) DataDirPath ¶
DataDirPath returns the full path for the data directory used by the engine
func (*Common) GetControllerService ¶
GetControllerService returns the name of the controller service
func (*Common) GetWorkerService ¶
GetWorkerService returns the name of the worker service
func (*Common) JoinTokenPath ¶
JoinTokenPath returns the path of the token to join the cluster
func (*Common) PackageStagingDir ¶ added in v0.28.1
PackageStagingDir returns the directory staged .rpm/.deb package files are uploaded to. It falls back to DataDirPath when PackageDir is unset, so a distro that never stages package files does not need to set it.
type DesiredFile ¶
type DesiredFile struct {
// Content is the full desired content of the file.
Content []byte
// Mode is the file mode as chmod spells it, e.g. "0600".
Mode string
// NoRestart indicates changes to this file do not require draining or restarting the engine.
NoRestart bool
}
DesiredFile is one engine config file a distro wants on a host: its content, and the mode it is written with. The mode travels with the content because it varies per file -- a file the engine reads as a group member is not written like one holding credentials.
func DistroReleaseDesiredFile ¶
func DistroReleaseDesiredFile(dis distro.ZarfDistro, managedFiles map[string]DesiredFile) (string, DesiredFile, bool, error)
DistroReleaseDesiredFile generates the DesiredFile for the installed distro package metadata and managed files tracking.
type Distro ¶
type Distro interface {
// AdminCredentials returns the cluster CA certificate and the admin client key pair
// for a given controller host and data directory
AdminCredentials(*cluster.ZarfHost, string) (AdminCredentials, error)
// BinaryName returns the engine binary name
BinaryName() string
// BinaryPath returns the full path to the engine binary
BinaryPath() string
// CleanupPaths returns every path on a host the engine owns outright, for an uninstall
// to remove recursively. Paths that are unset or too broad to safely remove are left out.
CleanupPaths() []string
// ConfigPath returns the full path for the config directory used by the engine
ConfigPath() string
// ConfigureEngine does distro specific configuration on a host
ConfigureEngine(context.Context, *cluster.ZarfHost, cluster.ZarfRuntimeMeta, distro.ZarfDistro) error
// DataDirPath returns the full path for the data directory used by the engine
DataDirPath() string
// DesiredFiles returns the full set of engine config files (path -> desired file) this
// distro would write for the given host/run/dis state -- e.g. registries.yaml, audit.yaml,
// pss.yaml -- used both to pre-seed a fresh host and, by the engine-config-sync phases, to
// detect drift on an already-running host.
DesiredFiles(*cluster.ZarfHost, cluster.ZarfRuntimeMeta, distro.ZarfDistro) (map[string]DesiredFile, error)
// ManagedDirs returns the directories on a host cargoship prunes, so that a file in one of
// them that DesiredFiles no longer names can be removed rather than left behind. A
// directory cargoship shares with the engine names the files that are its own. A distro
// that keeps no such directory returns nil.
ManagedDirs() []ManagedDir
// PackageStagingDir returns the directory staged .rpm/.deb package files are uploaded to,
// so the uninstall phase knows where to recover installed package names from. A distro that
// installs from a single binary rather than staged package files shares this with
// DataDirPath, since nothing else uses the value.
PackageStagingDir() string
// DistroCmdf returns a string that can be used to execute commands on the core engine binary
DistroCmdf(string, ...any) string
// GetClusterCIDR returns a string array with the all the known cluster cidr blocks
GetClusterCIDR(distro.ZarfDistro) []string
// GetControllerService returns the name of the controller service
GetControllerService() string
// GetWorkerService returns the name of the worker service
GetWorkerService() string
// JoinTokenPath returns the path of the token to join the cluster
JoinTokenPath() string
// JoinTokenPathAgent returns the path of the token to join the cluster.
// Distro's like RKE2 and K3S allow for agent tokens, so this allows for some level of access control if a node is allowed to be a controller or an agent.
JoinTokenPathAgent() string
// KubeconfigPath returns the path to the admin config for a given
KubeconfigPath(*cluster.ZarfHost, string) string
// KubectlCmdf returns a string with that can be executed to interact with the kubernetes cluster
KubectlCmdf(*cluster.ZarfHost, string, string, ...any) string
// RunningVersion returns the version of the distro being ran, if the engine is not running it throws an "ErrVersionNotDetected" error
RunningVersion(*cluster.ZarfHost) (string, error)
// SetPath takes in a key value pair to change how the distro values are configured, if a key is not valid it will throw an "ErrPathKey" error
SetPath(key string, value string) error
// StopControllerService stops the controller service on the host
StopControllerService(*cluster.ZarfHost) error
// StopWorkerService stops the controller service on the host
StopWorkerService(*cluster.ZarfHost) error
}
Distro interface for any distro object
type K3S ¶
type K3S struct {
RancherCommon
}
K3S distro struct
func (*K3S) AdminCredentials ¶
AdminCredentials returns the cluster CA certificate and the admin client key pair, read out of the admin kubeconfig k3s writes on a controller host.
func (*K3S) KubeconfigPath ¶
KubeconfigPath returns the path to the admin config for a given
func (*K3S) KubectlCmdf ¶
KubectlCmdf returns a string with that can be executed to interact with the kubernetes cluster
func (*K3S) StopControllerService ¶
StopControllerService stops the controller service on the host
type ManagedDir ¶
type ManagedDir struct {
// Path is the directory on the host.
Path string
// Glob limits pruning to the file names it matches, for a directory cargoship shares with
// something else. An empty Glob means every file in the directory is cargoship's.
//
// The engine's manifest directory is the case this exists for: cargoship writes the
// HelmChartConfig files in it, while the engine ships its own charts there, and removing
// those would take the cluster apart.
Glob string
}
ManagedDir is a directory cargoship prunes, and how much of it it is allowed to prune.
type RKE2 ¶
type RKE2 struct {
RancherCommon
}
RKE2 distro struct
func (*RKE2) AdminCredentials ¶
AdminCredentials returns the cluster CA certificate and the admin client key pair, read out of the admin kubeconfig rke2 writes on a controller host.
func (*RKE2) KubeconfigPath ¶
KubeconfigPath returns the path to the admin config for a given distro
func (*RKE2) KubectlCmdf ¶
KubectlCmdf returns a string with that can be executed to interact with the kubernetes cluster
func (*RKE2) StopControllerService ¶
StopControllerService implements Distro.
type RancherCommon ¶
type RancherCommon struct {
Common
}
RancherCommon is a parent object for both RKE2 and k3s distros
func (*RancherCommon) CleanupPaths ¶
func (d *RancherCommon) CleanupPaths() []string
CleanupPaths returns the paths an uninstall removes from a host: the engine data directory and the config directory, both of which rke2 and k3s own outright.
func (*RancherCommon) ConfigureEngine ¶
func (d *RancherCommon) ConfigureEngine(ctx context.Context, host *cluster.ZarfHost, run cluster.ZarfRuntimeMeta, dis distro.ZarfDistro) error
ConfigureEngine does distro specific configuration on a host
func (*RancherCommon) DesiredFiles ¶
func (d *RancherCommon) DesiredFiles(host *cluster.ZarfHost, run cluster.ZarfRuntimeMeta, dis distro.ZarfDistro) (map[string]DesiredFile, error)
DesiredFiles returns the desired content of registries.yaml, audit.yaml, and pss.yaml for the given host/run/dis, keyed by their full destination path. Content is identical across hosts of the same run (no host-varying fields are involved), unlike config.yaml.
func (*RancherCommon) DistroCmdf ¶
func (d *RancherCommon) DistroCmdf(template string, args ...any) string
DistroCmdf returns a string that can be used to execute commands on the core engine binary
func (*RancherCommon) GetClusterCIDR ¶
func (d *RancherCommon) GetClusterCIDR(dis distro.ZarfDistro) []string
GetClusterCIDR returns a string array with the all the known cluster cidr blocks
func (*RancherCommon) JoinTokenPathAgent ¶
func (d *RancherCommon) JoinTokenPathAgent() string
JoinTokenPathAgent returns the path of the token to join the cluster. Distro's like RKE2 and K3S allow for agent tokens, so this allows for some level of access control if a node is allowed to be a controller or an agent.
func (*RancherCommon) ManagedDirs ¶
func (d *RancherCommon) ManagedDirs() []ManagedDir
ManagedDirs returns the directories on a host cargoship prunes. For rke2 and k3s that is the directory holding CA certificates, the one holding state metadata -- every file in both was put there by cargoship, so a file with no entry left behind it can go -- and the engine's manifest directory, which cargoship shares with the engine and where it prunes only the HelmChartConfig files it writes itself.
func (*RancherCommon) RunningVersion ¶
func (d *RancherCommon) RunningVersion(host *cluster.ZarfHost) (string, error)
RunningVersion returns the version of the distro being ran, if the engine is not running it throws an "ErrVersionNotDetected" error
type Upstream ¶
type Upstream struct {
Common
}
Upstream distro struct. It targets a kubeadm-bootstrapped cluster: plain kubelet/kubeadm/ kubectl packages and upstream containerd, none of which share rke2/k3s's single config.yaml or wharfie registries.yaml, so it implements Distro directly rather than embedding RancherCommon.
func (*Upstream) AdminCredentials ¶
func (d *Upstream) AdminCredentials(host *cluster.ZarfHost, dataDir string) (AdminCredentials, error)
AdminCredentials returns the cluster CA certificate and the admin client key pair, read out of the admin kubeconfig kubeadm writes on a controller host.
func (*Upstream) CleanupPaths ¶
CleanupPaths returns the paths an uninstall removes from a host: the kubernetes config directory, the kubelet data directory, and the staged package directory, all of which upstream owns outright.
func (*Upstream) ConfigureEngine ¶
func (d *Upstream) ConfigureEngine(_ context.Context, _ *cluster.ZarfHost, _ cluster.ZarfRuntimeMeta, _ distro.ZarfDistro) error
ConfigureEngine does distro specific configuration on a host. kubeadm has no equivalent of rke2/k3s's single config.yaml write: a controller is bootstrapped with `kubeadm init` and a worker joins with `kubeadm join`, neither of which is implemented yet.
func (*Upstream) DesiredFiles ¶
func (d *Upstream) DesiredFiles(_ *cluster.ZarfHost, _ cluster.ZarfRuntimeMeta, _ distro.ZarfDistro) (map[string]DesiredFile, error)
DesiredFiles returns the full set of engine config files this distro would write. Containerd's config.toml and crictl.yaml land here once upstream owns the container runtime configuration; until then there is honestly nothing to desire, so this returns an empty set rather than an error.
func (*Upstream) DistroCmdf ¶
DistroCmdf returns a string that can be used to execute a command directly. Upstream has no single engine binary to wrap a command through -- kubeadm, kubelet, and kubectl are three separate packages -- so the template is formatted as-is.
func (*Upstream) GetClusterCIDR ¶
func (d *Upstream) GetClusterCIDR(dis distro.ZarfDistro) []string
GetClusterCIDR returns the known cluster CIDR blocks. kubeadm's service subnet defaults to 10.96.0.0/12 when unset, but it has no pod subnet default -- that is entirely CNI dependent -- so one is only returned when the engine config sets podSubnet. Trusting nothing is safer here than inventing a value the firewall phase would treat as authoritative.
func (*Upstream) JoinTokenPathAgent ¶
JoinTokenPathAgent returns the path of the token to join the cluster as a worker. kubeadm has no static agent-join-token file -- tokens are short-lived and minted on demand with `kubeadm token create` -- so there is nothing to point at yet.
func (*Upstream) KubeconfigPath ¶
KubeconfigPath returns the path to the admin config kubeadm writes. Unlike rke2/k3s, this path does not vary by host or data directory.
func (*Upstream) KubectlCmdf ¶
func (d *Upstream) KubectlCmdf(host *cluster.ZarfHost, dataDir string, s string, args ...any) string
KubectlCmdf returns a string that can be executed to interact with the kubernetes cluster. kubectl is a plain host binary here, not reached through an engine wrapper.
func (*Upstream) ManagedDirs ¶
func (d *Upstream) ManagedDirs() []ManagedDir
ManagedDirs returns the directories on a host cargoship prunes. Upstream manages none yet.
func (*Upstream) RunningVersion ¶
RunningVersion returns the version of kubelet running on the host, if the engine is not running it throws an "ErrVersionNotDetected" error
func (*Upstream) StopControllerService ¶
StopControllerService stops the controller service on the host. Controller and worker are the same kubelet service, and unlike rke2/k3s there is no embedded containerd or killall script to account for.