cluster

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseClusterClient

type BaseClusterClient struct {
	// contains filtered or unexported fields
}

BaseClusterClient provides a base implementation of ClusterClient.

func NewBaseClusterClient

func NewBaseClusterClient() *BaseClusterClient

NewBaseClusterClient creates a new BaseClusterClient with default timeouts.

func (*BaseClusterClient) CaptureNodeBootIDs added in v0.9.1

func (c *BaseClusterClient) CaptureNodeBootIDs(ctx context.Context, nodeAddresses []string) map[string]string

CaptureNodeBootIDs is a stub that returns an empty map. Provider-specific implementations should override this.

func (*BaseClusterClient) Close

func (c *BaseClusterClient) Close()

Close is a no-op in the base implementation. Provider-specific implementations should override this to close their connections.

func (*BaseClusterClient) GetNodeVersion added in v0.10.0

func (c *BaseClusterClient) GetNodeVersion(ctx context.Context, nodeAddress string) (string, error)

GetNodeVersion is a stub that returns an error indicating the method is not implemented. Provider-specific implementations should override this.

func (*BaseClusterClient) UpgradeNodes added in v0.9.0

func (c *BaseClusterClient) UpgradeNodes(ctx context.Context, nodeAddresses []string, image string, powercycle bool) error

UpgradeNodes is a stub that returns an error indicating the method is not implemented. Provider-specific implementations should override this to perform node upgrades.

func (*BaseClusterClient) WaitForControlPlaneAPIReady added in v0.9.0

func (c *BaseClusterClient) WaitForControlPlaneAPIReady(ctx context.Context, nodeAddress string, outputFunc func(string)) error

WaitForControlPlaneAPIReady is a stub that returns an error indicating the method is not implemented. Provider-specific implementations should override this.

func (*BaseClusterClient) WaitForNodesHealthy

func (c *BaseClusterClient) WaitForNodesHealthy(ctx context.Context, nodeAddresses []string, expectedVersion string, skipServices []string) error

WaitForNodesHealthy implements the default polling behavior for node health and version checks

func (*BaseClusterClient) WaitForNodesReboot added in v0.9.0

func (c *BaseClusterClient) WaitForNodesReboot(ctx context.Context, nodeAddresses []string, preActionBootIDs map[string]string, expectedVersion string, skipServices []string, offlineTimeout time.Duration) error

WaitForNodesReboot implements the default reboot-wait behavior

type ClusterClient

type ClusterClient interface {
	// WaitForNodesHealthy waits for nodes to be healthy and optionally match a specific version
	// Polls until all nodes are healthy (and correct version if specified) or timeout
	// skipServices is a list of service names to ignore during health checks
	WaitForNodesHealthy(ctx context.Context, nodeAddresses []string, expectedVersion string, skipServices []string) error

	// CaptureNodeBootIDs reads each node's current kernel boot ID, for later comparison
	// by WaitForNodesReboot. A node whose boot ID can't be read (e.g. permission denied,
	// unreachable) is simply omitted from the result; WaitForNodesReboot skips the
	// per-node check for any node missing from preActionBootIDs.
	CaptureNodeBootIDs(ctx context.Context, nodeAddresses []string) map[string]string

	// WaitForNodesReboot waits for nodes to reboot (confirmed by each node's kernel boot ID
	// changing from preActionBootIDs) then come back healthy. Phase 1 polls each node's
	// boot ID until it differs from before or offlineTimeout elapses; a node missing from
	// preActionBootIDs is treated as already satisfied. Phase 2 polls until all nodes are
	// healthy again within the remaining context deadline.
	WaitForNodesReboot(ctx context.Context, nodeAddresses []string, preActionBootIDs map[string]string, expectedVersion string, skipServices []string, offlineTimeout time.Duration) error

	// UpgradeNodes upgrades the specified nodes to the specified image. powercycle requests
	// a full ACPI reboot instead of the default kexec.
	UpgradeNodes(ctx context.Context, nodeAddresses []string, image string, powercycle bool) error

	// WaitForControlPlaneAPIReady waits for the kube-apiserver on a control-plane node
	// to accept TCP connections on port 6443. Returns nil immediately when the node is
	// not a control-plane (i.e. no etcd service present). outputFunc, when non-nil,
	// receives status messages during the polling loop. Returns an error if the node
	// role cannot be determined or the apiserver does not become reachable before the
	// context deadline.
	WaitForControlPlaneAPIReady(ctx context.Context, nodeAddress string, outputFunc func(string)) error

	// GetNodeVersion returns the Talos version a node is running, without the leading "v".
	// It returns an error when the node cannot be reached or reports no version.
	GetNodeVersion(ctx context.Context, nodeAddress string) (string, error)

	// Close closes any open connections.
	Close()
}

ClusterClient defines the interface for cluster operations

type MockClusterClient

type MockClusterClient struct {
	BaseClusterClient
	WaitForNodesHealthyFunc         func(ctx context.Context, nodeAddresses []string, expectedVersion string, skipServices []string) error
	CaptureNodeBootIDsFunc          func(ctx context.Context, nodeAddresses []string) map[string]string
	WaitForNodesRebootFunc          func(ctx context.Context, nodeAddresses []string, preActionBootIDs map[string]string, expectedVersion string, skipServices []string, offlineTimeout time.Duration) error
	UpgradeNodesFunc                func(ctx context.Context, nodeAddresses []string, image string, powercycle bool) error
	WaitForControlPlaneAPIReadyFunc func(ctx context.Context, nodeAddress string, outputFunc func(string)) error
	GetNodeVersionFunc              func(ctx context.Context, nodeAddress string) (string, error)
	CloseFunc                       func()
}

MockClusterClient is a mock implementation of the ClusterClient interface

func NewMockClusterClient

func NewMockClusterClient() *MockClusterClient

NewMockClusterClient is a constructor for MockClusterClient

func (*MockClusterClient) CaptureNodeBootIDs added in v0.9.1

func (m *MockClusterClient) CaptureNodeBootIDs(ctx context.Context, nodeAddresses []string) map[string]string

CaptureNodeBootIDs calls the mock CaptureNodeBootIDsFunc if set, otherwise returns nil

func (*MockClusterClient) Close

func (m *MockClusterClient) Close()

Close calls the mock CloseFunc if set

func (*MockClusterClient) GetNodeVersion added in v0.10.0

func (m *MockClusterClient) GetNodeVersion(ctx context.Context, nodeAddress string) (string, error)

GetNodeVersion calls the mock GetNodeVersionFunc if set, otherwise returns an empty version and nil

func (*MockClusterClient) UpgradeNodes added in v0.9.0

func (m *MockClusterClient) UpgradeNodes(ctx context.Context, nodeAddresses []string, image string, powercycle bool) error

UpgradeNodes calls the mock UpgradeNodesFunc if set, otherwise returns nil

func (*MockClusterClient) WaitForControlPlaneAPIReady added in v0.9.0

func (m *MockClusterClient) WaitForControlPlaneAPIReady(ctx context.Context, nodeAddress string, outputFunc func(string)) error

WaitForControlPlaneAPIReady calls the mock WaitForControlPlaneAPIReadyFunc if set, otherwise returns nil

func (*MockClusterClient) WaitForNodesHealthy

func (m *MockClusterClient) WaitForNodesHealthy(ctx context.Context, nodeAddresses []string, expectedVersion string, skipServices []string) error

WaitForNodesHealthy calls the mock WaitForNodesHealthyFunc if set, otherwise returns nil

func (*MockClusterClient) WaitForNodesReboot added in v0.9.0

func (m *MockClusterClient) WaitForNodesReboot(ctx context.Context, nodeAddresses []string, preActionBootIDs map[string]string, expectedVersion string, skipServices []string, offlineTimeout time.Duration) error

WaitForNodesReboot calls the mock WaitForNodesRebootFunc if set, otherwise returns nil

type Shims

type Shims struct {
	shims.Shims

	// Talos client operations
	TalosConfigOpen  func(configPath string) (*clientconfig.Config, error)
	TalosNewClient   func(ctx context.Context, opts ...client.OptionFunc) (*client.Client, error)
	TalosVersion     func(ctx context.Context, client *client.Client) (*machine.VersionResponse, error)
	TalosWithNodes   func(ctx context.Context, nodes ...string) context.Context
	TalosWithNode    func(ctx context.Context, node string) context.Context
	TalosServiceList func(ctx context.Context, client *client.Client) (*machine.ServiceListResponse, error)
	TalosUpgrade     func(ctx context.Context, client *client.Client, image string, powercycle bool) error
	TalosRead        func(ctx context.Context, client *client.Client, path string) (io.ReadCloser, error)
	TalosClose       func(client *client.Client)

	// Network operations
	NetDialTimeout func(network, address string, timeout time.Duration) (net.Conn, error)
}

Shims holds the shared system call primitives and the Talos client operations.

func NewShims

func NewShims() *Shims

NewShims returns a Shims with every field set to its real implementation.

type TalosClusterClient

type TalosClusterClient struct {
	*BaseClusterClient
	// contains filtered or unexported fields
}

TalosClusterClient implements ClusterClient for Talos clusters

func NewTalosClusterClient

func NewTalosClusterClient() *TalosClusterClient

NewTalosClusterClient creates a new TalosClusterClient instance with default configuration

func (*TalosClusterClient) CaptureNodeBootIDs added in v0.9.1

func (c *TalosClusterClient) CaptureNodeBootIDs(ctx context.Context, nodeAddresses []string) map[string]string

CaptureNodeBootIDs reads each node's current kernel boot ID through the talosconfig endpoints. A node whose boot ID can't be read (permission denied, unreachable) is omitted from the result rather than failing the capture outright. If the client itself can't be initialized (e.g. TALOSCONFIG unset), every node is omitted.

func (*TalosClusterClient) Close

func (c *TalosClusterClient) Close()

Close releases resources held by the TalosClusterClient. It safely closes the underlying Talos gRPC client connection if one exists and sets the client reference to nil to prevent further use. This method is safe to call multiple times and handles the case where no client connection was established.

func (*TalosClusterClient) GetNodeVersion added in v0.10.0

func (c *TalosClusterClient) GetNodeVersion(ctx context.Context, nodeAddress string) (string, error)

GetNodeVersion returns the Talos version of one node, without the leading "v". It loads the talosconfig first, so it works as the first call on a new client. It returns an error when the talosconfig cannot be loaded, the node cannot be reached, or it reports no version.

func (*TalosClusterClient) UpgradeNodes added in v0.9.0

func (c *TalosClusterClient) UpgradeNodes(ctx context.Context, nodeAddresses []string, image string, powercycle bool) error

UpgradeNodes upgrades the specified nodes to the specified image. It iterates through each node address and initiates an upgrade using the Talos Upgrade API. powercycle requests a full ACPI reboot instead of the default kexec, needed on platforms (e.g. nested virtualization) where kexec doesn't reliably register as an offline transition. Returns an error if any node upgrade fails or if the Talos client cannot be initialized.

func (*TalosClusterClient) WaitForControlPlaneAPIReady added in v0.9.0

func (c *TalosClusterClient) WaitForControlPlaneAPIReady(ctx context.Context, nodeAddress string, outputFunc func(string)) error

WaitForControlPlaneAPIReady waits for the kube-apiserver on a control-plane node to accept TCP connections on port 6443. It first queries the Talos ServiceList to determine the node's role: nodes that do not run the etcd service are treated as workers and the method returns nil immediately. For control-plane nodes, it polls a TCP dial to the apiserver port until a connection succeeds or the context deadline is reached. The per-dial timeout is half the health check poll interval so a slow dial does not starve polling. outputFunc, when non-nil, receives a status message on each failed poll attempt. Returns an error if the role cannot be determined or the apiserver does not become reachable in time.

func (*TalosClusterClient) WaitForNodesHealthy

func (c *TalosClusterClient) WaitForNodesHealthy(ctx context.Context, nodeAddresses []string, expectedVersion string, skipServices []string) error

WaitForNodesHealthy waits for nodes to be healthy and optionally match a specific version. It polls each node continuously, checking service health and version status until all nodes meet the criteria or timeout occurs. For each node, it validates that all critical services are running and healthy, and if expectedVersion is provided, verifies the node is running that specific version. Services listed in skipServices are ignored during health checks. Each node is reached through the talosconfig endpoints, so a node address need not be dialable. The method provides detailed status output for each node during polling, showing healthy/unhealthy services and version information. Returns an error with specific details about which nodes failed health checks or version validation if timeout is reached.

func (*TalosClusterClient) WaitForNodesReboot added in v0.9.0

func (c *TalosClusterClient) WaitForNodesReboot(ctx context.Context, nodeAddresses []string, preActionBootIDs map[string]string, expectedVersion string, skipServices []string, offlineTimeout time.Duration) error

WaitForNodesReboot waits for nodes to reboot then come back online healthy. Phase 1 polls each node's kernel boot ID until it differs from preActionBootIDs, confirming a genuine reboot occurred; unlike watching for the node to become unreachable, this can't miss a reboot that completes between polls, and isn't fooled by transient connectivity blips that were never a real reboot. A node missing from preActionBootIDs (its boot ID couldn't be captured beforehand) is treated as already satisfied. offlineTimeout caps phase 1; zero uses the context deadline. Phase 2 re-initializes the client and delegates to WaitForNodesHealthy to wait for all nodes to return to a healthy state within the remaining context deadline. Returns an error if either phase times out or if the client cannot be initialized.

Jump to

Keyboard shortcuts

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