cluster

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 10 Imported by: 0

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) 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) 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, 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

	// WaitForNodesReboot waits for nodes to go offline (reboot started) then come back healthy.
	// Phase 1 polls the Talos version endpoint until all nodes are unreachable (offlineTimeout caps this phase).
	// Phase 2 polls until all nodes are healthy again within the remaining context deadline.
	WaitForNodesReboot(ctx context.Context, nodeAddresses []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

	// 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
	WaitForNodesRebootFunc          func(ctx context.Context, nodeAddresses []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
	CloseFunc                       func()
}

MockClusterClient is a mock implementation of the ClusterClient interface

func NewMockClusterClient

func NewMockClusterClient() *MockClusterClient

NewMockClusterClient is a constructor for MockClusterClient

func (*MockClusterClient) Close

func (m *MockClusterClient) Close()

Close calls the mock CloseFunc if set

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, expectedVersion string, skipServices []string, offlineTimeout time.Duration) error

WaitForNodesReboot calls the mock WaitForNodesRebootFunc if set, otherwise returns nil

type Shims

type Shims struct {
	// 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
	TalosServiceList func(ctx context.Context, client *client.Client) (*machine.ServiceListResponse, error)
	TalosUpgrade     func(ctx context.Context, client *client.Client, image string, powercycle bool) error
	TalosClose       func(client *client.Client)

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

Shims provides testable interfaces for external dependencies

func NewShims

func NewShims() *Shims

NewShims creates a new Shims instance with default implementations

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) 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) 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. 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, expectedVersion string, skipServices []string, offlineTimeout time.Duration) error

WaitForNodesReboot waits for nodes to go offline (reboot started) then come back online healthy. Phase 1 polls the Talos version endpoint per node until all nodes are unreachable, confirming the reboot has begun. 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