Documentation
¶
Overview ¶
Package cluster defines the API types for a cluster configuration.
Index ¶
- Constants
- Variables
- type ZarfCluster
- type ZarfClusterConfig
- type ZarfClusterFiles
- type ZarfClusterMetadata
- type ZarfClusterProfiles
- type ZarfClusterRegistries
- type ZarfClusterRegistryAuth
- type ZarfClusterRegistryProxy
- type ZarfClusterSpec
- type ZarfFirewallPolicyConfig
- type ZarfFirewallPort
- type ZarfFirewallZone
- type ZarfHost
- func (h *ZarfHost) Arch() (string, error)
- func (h *ZarfHost) CheckHTTPStatus(url string, expected ...int) error
- func (h *ZarfHost) DeleteFile(path string) error
- func (h *ZarfHost) Dir(path string) (string, error)
- func (h *ZarfHost) FileChanged(lpath, rpath string) bool
- func (h *ZarfHost) FileExist(path string) bool
- func (h *ZarfHost) IsController() bool
- func (h *ZarfHost) KubeRole() string
- func (h *ZarfHost) OSKind() (string, error)
- func (h *ZarfHost) ReadFile(path string) (string, error)
- func (h *ZarfHost) ResolveConfigurer() error
- func (h *ZarfHost) ServiceName() string
- func (h *ZarfHost) String() string
- func (h *ZarfHost) Touch(path string, modTime time.Time, opts ...exec.Option) error
- func (h *ZarfHost) WriteFile(path string, data string, permissions string) error
- type ZarfHostConfig
- type ZarfHostEngine
- type ZarfHostMetadata
- type ZarfHostPort
- type ZarfHosts
- func (hosts ZarfHosts) BatchedParallelEach(ctx context.Context, batchSize int, ...) error
- func (hosts ZarfHosts) Controllers() ZarfHosts
- func (hosts ZarfHosts) Each(ctx context.Context, filters ...func(context.Context, *ZarfHost) error) error
- func (hosts ZarfHosts) Filter(filter func(h *ZarfHost) bool) ZarfHosts
- func (hosts ZarfHosts) Find(filter func(h *ZarfHost) bool) *ZarfHost
- func (hosts ZarfHosts) First() *ZarfHost
- func (hosts ZarfHosts) Last() *ZarfHost
- func (hosts ZarfHosts) ParallelEach(ctx context.Context, filters ...func(context.Context, *ZarfHost) error) error
- func (hosts ZarfHosts) WithRole(s string) ZarfHosts
- func (hosts ZarfHosts) Workers() ZarfHosts
- type ZarfRuntimeMeta
Constants ¶
const ( // RoleController marks a host as a control-plane node. RoleController = "controller" // RoleControllerWorker marks a host as both a control-plane node and a worker node. RoleControllerWorker = "controller+worker" // RoleSingle marks a host as a single-node cluster: both control plane and worker on one host. RoleSingle = "single" // RoleWorker marks a host as a worker node. RoleWorker = "worker" // RoleError is a sentinel value returned when a role or service lookup fails. RoleError = "error" )
Variables ¶
var ErrCommandFailed = errors.New("command failed")
ErrCommandFailed is returned when a command fails
Functions ¶
This section is empty.
Types ¶
type ZarfCluster ¶
type ZarfCluster struct {
// APIVersion identifies the API group and version of this configuration document.
APIVersion string `json:"apiVersion,omitempty" jsonschema:"enum=zarf.dev/v1alpha1"`
// Kind identifies the document type. The value must be ZarfCluster.
Kind v1alpha1.ZarfDistroKind `json:"kind" jsonschema:"enum=ZarfCluster"`
// Metadata holds identifying information for the cluster.
Metadata ZarfClusterMetadata `json:"metadata"`
// Spec holds the configuration and hosts for the cluster.
Spec ZarfClusterSpec `json:"spec"`
// RuntimeMetadata stores data gathered while the phases run.
RuntimeMetadata ZarfRuntimeMeta `json:"-"`
}
ZarfCluster is the root object of a cluster configuration document.
type ZarfClusterConfig ¶
type ZarfClusterConfig struct {
// LoadBalancer is the hostname clients use to reach the cluster control plane.
LoadBalancer string `json:"loadbalancer" jsonschema:"format=hostname"`
// Registries lists the container registries the cluster uses.
Registries []ZarfClusterRegistries `json:"registries,omitempty"`
// Profiles maps a profile name to host and engine overrides that a host can select.
Profiles map[string]ZarfClusterProfiles `json:"profiles,omitempty"`
}
ZarfClusterConfig holds cluster-wide configuration.
type ZarfClusterFiles ¶
type ZarfClusterFiles struct {
// Name identifies the file in the cluster configuration.
Name string `json:"name"`
// Source is the local path or URL cargoship reads the file from.
Source string `json:"src,omitempty"`
// Destination is the path on the host where cargoship writes the file.
Destination string `json:"dst,omitempty"`
// DestinationDirectory is the directory on the host where cargoship writes the file.
DestinationDirectory string `json:"dstDir,omitempty"`
// Permission sets the file mode cargoship applies on the host.
Permission string `json:"perm,omitempty"`
// User identifies the file owner on the host.
User string `json:"user,omitempty" jsonschema:"example=root"`
// Group identifies the file group on the host.
Group string `json:"group,omitempty" jsonschema:"example=root"`
// Data holds inline content for the file, as an alternative to Source.
Data string `json:"data,omitempty"`
}
ZarfClusterFiles defines a file to write to a host.
type ZarfClusterMetadata ¶
type ZarfClusterMetadata struct {
// Name sets the cluster name. If you allow cargoship to update the kubeconfig, cargoship uses this name there.
Name string `json:"name" jsonschema:"pattern=^[a-z0-9][a-z0-9\\-]*$"`
}
ZarfClusterMetadata holds identifying information for a cluster.
type ZarfClusterProfiles ¶
type ZarfClusterProfiles struct {
// Host holds the configuration overrides applied to a host that selects this profile.
Host ZarfHostConfig `json:"host,omitempty"`
// Engine holds the node label and taint overrides applied to a host that selects this profile.
Engine ZarfHostEngine `json:"engine,omitempty"`
}
ZarfClusterProfiles holds the host and engine overrides for one profile.
type ZarfClusterRegistries ¶
type ZarfClusterRegistries struct {
// Name identifies the registry.
Name string `json:"name"`
// Authentication holds the credentials for the registry.
Authentication ZarfClusterRegistryAuth `json:"auth,omitempty"`
// Proxy holds the pull redirect settings for the registry.
Proxy ZarfClusterRegistryProxy `json:"proxy"`
}
ZarfClusterRegistries holds the credentials and pull proxy for one container registry.
type ZarfClusterRegistryAuth ¶
type ZarfClusterRegistryAuth struct {
// Username is the login name for the remote registry.
Username string `json:"user,omitempty"`
// Password is the login secret for the remote registry.
Password string `json:"pass,omitempty"`
// Token authenticates to the remote registry instead of a username and password.
Token string `json:"token,omitempty"`
}
ZarfClusterRegistryAuth holds the credentials for a container registry.
type ZarfClusterRegistryProxy ¶
type ZarfClusterRegistryProxy struct {
// URL is the registry address the engine pulls from instead of the original registry.
URL string `json:"url"`
}
ZarfClusterRegistryProxy redirects pulls for a registry to a different URL.
type ZarfClusterSpec ¶
type ZarfClusterSpec struct {
// Config holds the cluster-wide configuration.
Config ZarfClusterConfig `json:"config"`
// Hosts lists the hosts that make up the cluster.
Hosts ZarfHosts `json:"hosts" jsonschema:"minItems=1"`
}
ZarfClusterSpec holds the configuration and hosts for a cluster.
type ZarfFirewallPolicyConfig ¶ added in v0.6.0
type ZarfFirewallPolicyConfig struct {
// XMLName sets the element name cargoship uses when it marshals this policy to firewalld XML.
XMLName xml.Name `xml:"policy" json:"-"`
// Short is a human-readable description of the policy.
Short string `xml:"short,omitempty" json:"-"`
// Target is the action taken on traffic that matches the policy.
Target string `xml:"target,attr,omitempty" json:"target" jsonschema:"enum=CONTINUE,enum=ACCEPT,enum=REJECT,enum=DROP"`
// Ingress is the zone the policy allows traffic from.
Ingress ZarfFirewallZone `xml:"ingress-zone"`
// Egress is the zone the policy allows traffic to.
Egress ZarfFirewallZone `xml:"egress-zone"`
// Ports lists the ports this policy allows.
Ports []ZarfFirewallPort `xml:"port,omitempty" json:"ports,omitempty"`
}
ZarfFirewallPolicyConfig configures a firewalld policy that opens ports from one zone to another.
type ZarfFirewallPort ¶ added in v0.6.0
type ZarfFirewallPort struct {
// Protocol is the type of allowed traffic.
Protocol string `xml:"protocol,attr" json:"protocol" jsonschema:"enum=tcp,enum=udp,enum=sctp,enum=dccp"`
// Port is the port number, or port range, cargoship opens.
Port string `xml:"port,attr" json:"port" jsonschema:"oneof_type=string;integer"`
}
ZarfFirewallPort defines a port allowed through the firewalld policy.
type ZarfFirewallZone ¶ added in v0.6.0
type ZarfFirewallZone struct {
// Name identifies the firewalld zone.
Name string `xml:"name,attr" jsonschema:"example=trusted,example=public"`
}
ZarfFirewallZone is the name of either the ingress or egress zone for a policy.
type ZarfHost ¶
type ZarfHost struct {
// Connection embeds rig's connection type. It gives ZarfHost multi-protocol connectivity to a remote host.
rig.Connection `json:",inline"`
// Environment maps environment variables cargoship sets on the host.
Environment map[string]string `json:"environment,omitempty"`
// Files lists files cargoship uploads to the host.
Files []ZarfClusterFiles `json:"files,omitempty"`
// Hostname overrides the discovered name of the node.
Hostname string `json:"hostname,omitempty"`
// PrivateAddress overrides the discovered private address of the node.
PrivateAddress string `json:"privateAddress,omitempty"`
// PrivateInterface overrides the discovered private interface of the node.
PrivateInterface string `json:"privateInterface,omitempty"`
// Profile selects a profile by name from the cluster config's Profiles map.
Profile string `json:"profile,omitempty"`
// Role sets the node role when cargoship adds this host to the cluster. It must be controller or worker.
Role string `json:"role" jsonschema:"required,enum=controller,enum=worker"`
// Host holds the host-level configuration overrides for this node.
Host ZarfHostConfig `json:"host,omitempty"`
// Engine holds the node label and taint overrides for this node.
Engine ZarfHostEngine `json:"engine,omitempty"`
// Configurer is the per-host operations implementation cargoship uses to manage this host.
Configurer os.Configurer `json:"-"`
// Metadata holds values cargoship discovers about this host at runtime.
Metadata ZarfHostMetadata `json:"-"`
}
ZarfHost is a remote connection to a node
func (*ZarfHost) CheckHTTPStatus ¶
CheckHTTPStatus requests url and returns an error if the response status is not one of expected.
func (*ZarfHost) DeleteFile ¶
DeleteFile removes a file via the resolved configurer.
func (*ZarfHost) FileChanged ¶
FileChanged compares the local file at lpath to the remote file at rpath by sha256 checksum. It returns true if the checksums differ or if either checksum cannot be computed.
func (*ZarfHost) IsController ¶
IsController returns true for the controller, controller+worker, and single roles.
func (*ZarfHost) KubeRole ¶
KubeRole returns the Kubernetes role for this host. It maps controller+worker and single to controller.
func (*ZarfHost) ReadFile ¶
ReadFile returns the contents of path on the host, or an error if the file does not exist.
func (*ZarfHost) ResolveConfigurer ¶
ResolveConfigurer detects the host OS version and assigns the matching configurer to Configurer.
func (*ZarfHost) ServiceName ¶
ServiceName returns the name of the distro service that runs on this host.
type ZarfHostConfig ¶ added in v0.10.0
type ZarfHostConfig struct {
// Policy maps a policy name to a firewalld policy that allows traffic from one interface to another.
Policy map[string]ZarfFirewallPolicyConfig `json:"policy,omitempty"`
// Ports lists the ports and protocols cargoship opens on the node.
Ports []ZarfHostPort `json:"ports,omitempty" xml:"port"`
}
ZarfHostConfig defines the configuration for a specific host, including firewall policies and the ports cargoship opens on the node.
func (*ZarfHostConfig) Merge ¶ added in v0.10.0
func (c *ZarfHostConfig) Merge(update ZarfHostConfig)
Merge copies Policy and Ports from update into c, for whichever of those fields are empty in c.
type ZarfHostEngine ¶ added in v0.10.0
type ZarfHostEngine struct {
// NodeLabels maps Kubernetes node label keys to their values.
NodeLabels map[string]string `json:"labels,omitempty"`
// NodeTaints lists the Kubernetes node taints cargoship applies to the node.
NodeTaints []string `json:"taints,omitempty"`
}
ZarfHostEngine defines configuration options for node-level metadata, specifically Kubernetes node labels and taints applied to a cluster host.
func (*ZarfHostEngine) Merge ¶ added in v0.10.0
func (c *ZarfHostEngine) Merge(update ZarfHostEngine)
Merge copies NodeLabels and NodeTaints from update into c, for whichever of those fields are empty in c.
type ZarfHostMetadata ¶
type ZarfHostMetadata struct {
// Arch is the CPU architecture detected on the host.
Arch string
// BinaryTempFile lists temporary paths on the host cargoship uses to stage the engine binary during install.
BinaryTempFile []string
// DistroVersion is the version of the distro engine detected on the host.
DistroVersion string
// EngineUploaded indicates whether cargoship has already uploaded the distro engine binary to the host.
EngineUploaded bool
// ExistingConfig is the engine configuration currently present on the host.
ExistingConfig string
// Hostname is the hostname the host reports.
Hostname string
// Install is the function cargoship calls to install the distro engine on the host.
Install func(context.Context, *ZarfHost) error
// Installed indicates whether a distro engine is already installed on the host.
Installed bool
// IsLeader indicates whether this host is the cluster's control-plane leader.
IsLeader bool
// MachineID identifies the node to the distro engine.
MachineID string
// ModulesAdded indicates whether cargoship added a new kernel module to the host.
ModulesAdded bool
// NeedsUpgrade indicates whether the host needs the distro engine upgraded.
NeedsUpgrade bool
// NewConfig is the engine configuration cargoship will write to the host.
NewConfig string
// Ready indicates whether the distro service is up and running.
Ready bool
}
ZarfHostMetadata holds values cargoship discovers about a host at runtime.
type ZarfHostPort ¶
type ZarfHostPort struct {
// Protocol is the type of allowed traffic.
Protocol string `json:"protocol" xml:"protocol,attr" jsonschema:"enum=tcp,enum=udp"`
// Port is the port number, or port range, cargoship opens.
Port string `json:"port" xml:"port,attr" jsonschema:"oneof_type=string;integer"`
}
ZarfHostPort is a port cargoship opens on the public side of the firewall.
type ZarfHosts ¶
type ZarfHosts []*ZarfHost
ZarfHosts is an ordered list of hosts that cargoship manages together.
func (ZarfHosts) BatchedParallelEach ¶
func (hosts ZarfHosts) BatchedParallelEach(ctx context.Context, batchSize int, filter ...func(context.Context, *ZarfHost) error) error
BatchedParallelEach runs each filter on every host in parallel, in groups of batchSize hosts. It completes one group before it starts the next. It stops and returns the error if ctx is canceled or a group returns an error.
func (ZarfHosts) Controllers ¶
Controllers returns the hosts that act as a controller. This includes hosts with role controller, controller+worker, or single.
func (ZarfHosts) Each ¶
func (hosts ZarfHosts) Each(ctx context.Context, filters ...func(context.Context, *ZarfHost) error) error
Each runs each filter on every host, in the order given. It stops and returns the error if ctx is canceled or a filter returns an error.
func (ZarfHosts) Find ¶
Find returns the first host for which filter returns true. It returns nil if no host matches.
func (ZarfHosts) ParallelEach ¶
func (hosts ZarfHosts) ParallelEach(ctx context.Context, filters ...func(context.Context, *ZarfHost) error) error
ParallelEach runs each filter on every host in parallel. It runs the filters in the order given, completing one filter across all hosts before it starts the next. It collects every error and returns them combined.
type ZarfRuntimeMeta ¶
type ZarfRuntimeMeta struct {
// ControllerTLS lists the names and addresses on the controller TLS certificate.
ControllerTLS []string
// ControllerToken authorizes a worker node to join the cluster as a controller.
ControllerToken string
// AgentToken authorizes a worker node to join the cluster as an agent.
AgentToken string
// LoadBalancer is the hostname clients use to reach the cluster control plane.
LoadBalancer string
// Leader is the controller host that stores the cluster join tokens.
Leader *ZarfHost
}
ZarfRuntimeMeta stores data gathered while the phases run.