action

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package action are various actions used by the package

Index

Constants

This section is empty.

Variables

View Source
var ErrNoDistroSelected = errors.New("no distro selected: pass --distro, or set distro.type in the cargoship config file")

ErrNoDistroSelected is returned when an action is built with no distro at all, rather than with one no module claims.

Functions

This section is empty.

Types

type Apply

type Apply struct {
	ApplyOptions
	Phases phase.Phases
	// contains filtered or unexported fields
}

Apply state logic

func NewApply

func NewApply(opts ApplyOptions) (*Apply, error)

NewApply an apply action object

func (Apply) KubeConfigBytes added in v0.35.0

func (a Apply) KubeConfigBytes() ([]byte, error)

KubeConfigBytes is the cluster's admin credentials, serialized, as the run built them.

It is read after Run, and only means anything for a run that enabled UpdateKubeConfig: the phase is skipped otherwise and there is nothing to return. What comes back is cluster-admin, so a caller holding it is holding the cluster.

func (Apply) Run

func (a Apply) Run(ctx context.Context) error

Run the actions

type ApplyOptions

type ApplyOptions struct {
	// Manager is the phase manager
	Manager *phase.Manager
	// AllowDowngrade continues when a host already runs a version newer than the package,
	// rather than refusing the run
	AllowDowngrade bool
	// NoDrain skips draining worker nodes
	NoDrain bool
	// ModifyHosts updates the /etc/hosts file with all the nodes in the cluster
	ModifyHosts bool
	// ModifyFirewall updates the firewall, firewalld, ufw, or nftables, on the nodes
	ModifyFirewall bool
	// WorkerConcurrent number of workers that will be installed or upgraded at a time, as a fixed
	// count ("5") or a percentage of the batch ("25%")
	WorkerConcurrent string
	// UpdateKubeConfig whether to update the config
	UpdateKubeConfig bool
	// KubeConfigPath is the kubeconfig file to merge the admin creds into, the standard
	// location when empty
	KubeConfigPath string
	// NoKubeConfigFile builds the admin credentials without merging them into the operator's
	// kubeconfig, so that a caller can read them through KubeConfigBytes and nothing on the
	// machine running the apply is changed.
	//
	// It is phrased as the negative for the reason KubeConfigOptions.NoWrite is: the zero value
	// writes, which is what every caller before this field existed did. The OpenTofu provider is
	// the caller that sets it -- an apply that merged credentials into ~/.kube/config as a side
	// effect would be changing a machine the resource does not describe.
	NoKubeConfigFile bool
	// LabelNodes whether to check and add the node-role.kubernetes.io/<profile> label on nodes
	LabelNodes bool
	// AllowUnmanagedNodes lets an apply continue when the cluster holds a node no host in the
	// config accounts for, rather than stopping on it
	AllowUnmanagedNodes bool
	// Keyring decrypts encrypted registry credentials, in either supported format
	Keyring *clustercfg.Keyring
}

ApplyOptions struct

type EngineConfigSync

type EngineConfigSync struct {
	EngineConfigSyncOptions
	Phases phase.Phases
}

EngineConfigSync state logic

func NewEngineConfigSync

func NewEngineConfigSync(opts EngineConfigSyncOptions) (*EngineConfigSync, error)

NewEngineConfigSync an engine-config-sync action object

func (EngineConfigSync) Run

Run the actions

type EngineConfigSyncOptions

type EngineConfigSyncOptions struct {
	// Manager is the phase manager
	Manager *phase.Manager
	// WorkerConcurrent number of workers that will be synced at a time, as a fixed
	// count ("5") or a percentage of the batch ("25%")
	WorkerConcurrent string
	// Keyring decrypts encrypted registry credentials, in either supported format
	Keyring *clustercfg.Keyring
	// LabelNodes whether to check and add the node-role.kubernetes.io/<profile> label on nodes
	LabelNodes bool
	// UpdateKubeConfig whether to update a kubeconfig file with the admin creds for the cluster
	UpdateKubeConfig bool
	// KubeConfigPath is the kubeconfig file to merge the admin creds into, the standard
	// location when empty
	KubeConfigPath string
	// AllowDowngrade continues when a host already runs a version newer than the package,
	// rather than refusing the run
	AllowDowngrade bool
}

EngineConfigSyncOptions struct

type KubeConfig

type KubeConfig struct {
	KubeConfigOptions
	Phases phase.Phases
	// contains filtered or unexported fields
}

KubeConfig state logic

func NewKubeConfig

func NewKubeConfig(opts KubeConfigOptions) (*KubeConfig, error)

NewKubeConfig pulls the admin cert from a control-plane node and updates the local kube-config

func (KubeConfig) Bytes added in v0.35.0

func (a KubeConfig) Bytes() ([]byte, error)

Bytes is the kubeconfig the run built, serialized.

It is read after Run, and it is the half of this action that has nothing to do with the operator's own kubeconfig: phase.KubeConfig builds the credentials whether or not it writes them, and #305 separated the two so a caller could have the value without touching ~/.kube/config. Before this, the only way to reach it was to rebuild the phase list by hand.

What comes back is cluster-admin credentials, so a caller holding them is holding the cluster.

func (KubeConfig) Config added in v0.35.0

func (a KubeConfig) Config() *clientcmdapi.Config

Config is the same credentials as a structure, for a caller that wants to read a field rather than a file. Nil until Run has built it.

func (KubeConfig) Run

func (a KubeConfig) Run(ctx context.Context) error

Run the actions

type KubeConfigOptions

type KubeConfigOptions struct {
	// Manager is the phase manager
	Manager *phase.Manager
	// KubeConfigPath is the kubeconfig file to merge the admin creds into, the standard
	// location when empty
	KubeConfigPath string
	// NoWrite leaves the operator's kubeconfig alone, so the credentials are built and returned
	// and nothing on this machine is touched.
	//
	// It is phrased as the negative so that the zero value writes, which is what every caller
	// before this field existed did: `cargoship install kube-config` exists to write the file.
	// A caller that wants the value instead reads Bytes or Config after Run; see
	// docs/agent/choice-tofu-secrets.md for why the OpenTofu provider is that caller and why it
	// does not expose the result unless it is asked to.
	NoWrite bool
}

KubeConfigOptions struct

type Prepare

type Prepare struct {
	PrepareOptions
	Phases phase.Phases
}

Prepare state logic

func NewPrepare

func NewPrepare(opts PrepareOptions) *Prepare

NewPrepare an prepare action object

func (Prepare) Run

func (a Prepare) Run(ctx context.Context) error

Run the actions

type PrepareOptions

type PrepareOptions struct {
	// Manager is the phase manager
	Manager *phase.Manager
	// NoDrain skips draining worker nodes
	NoDrain bool
	// ModifyHosts updates the /etc/hosts file with all the nodes in the cluster
	ModifyHosts bool
	// ModifyFirewall updates the firewall, firewalld, ufw, or nftables, on the nodes
	ModifyFirewall bool
	// ModifyModules whether to update the host kernel modules
	ModifyModules bool
}

PrepareOptions struct

type Refresh added in v0.35.0

type Refresh struct {
	RefreshOptions
	Phases phase.Phases
}

Refresh state logic

func NewRefresh added in v0.35.0

func NewRefresh(opts RefreshOptions) (*Refresh, error)

NewRefresh a refresh action object.

Refresh is the read-only half of an apply: it connects to every host the configuration names, resolves each one's OS, gathers its network facts and reads the engine version already installed on it, and disconnects. Every phase in the list declares ReadOnly(), which is the property that makes the whole action safe to run against a live fleet -- nothing is written, and no cluster lock is taken, because Lock deliberately declares neither interface.

It exists as an action rather than as a phase list each caller assembles because there is now more than one caller. The OpenTofu provider reads a fleet during a plan and during a refresh, and a provider that built its own list would be a second place where "which phases are safe to run" is decided -- which is exactly the question ReadOnly() exists to answer once. The CLI has no command for it yet; see docs/agent/design-tofu-provider-install.md.

What it leaves behind is on the hosts themselves: each phase records what it learned on the Host it ran against, so a caller reads the facts off Manager.Config.Spec.Hosts afterwards rather than out of a return value.

func (Refresh) Run added in v0.35.0

func (a Refresh) Run(ctx context.Context) error

Run the actions

type RefreshOptions added in v0.35.0

type RefreshOptions struct {
	// Manager is the phase manager
	Manager *phase.Manager
}

RefreshOptions struct

type Reset

type Reset struct {
	ResetOptions
	Phases phase.Phases
}

Reset state logic

func NewReset

func NewReset(opts ResetOptions) (*Reset, error)

NewReset an apply action object

func (Reset) Run

func (r Reset) Run(ctx context.Context) error

Run the actions

type ResetOptions

type ResetOptions struct {
	// Manager is the phase manager
	Manager *phase.Manager
	// NoDrain skips draining worker nodes
	NoDrain bool
	// DistroID is the type of Kubernetes engine that will be removed
	DistroID string
	// WorkerConcurrent number of workers that will be installed or upgraded at a time, as a fixed
	// count ("5") or a percentage of the batch ("25%")
	WorkerConcurrent string
	// TargetHosts names the hosts to delete and uninstall, by hostname or by the address the
	// configuration connects through. Empty means every host in the configuration, which is what
	// a reset has always done.
	//
	// The hosts not named still take part: leader selection scans the whole configuration, so a
	// controller that is staying is what the node deletions are driven through. That separation is
	// the whole point -- see #339.
	TargetHosts []string
}

ResetOptions struct

Jump to

Keyboard shortcuts

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