cluster

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

Package cluster contains internal implementation details for the k3s Control Plane.

Index

Constants

View Source
const (
	// K3ssControlPlaneControllerName defines the controller used when creating clients.
	K3ssControlPlaneControllerName = "k3s-controlplane-controller"
)

Variables

View Source
var Log = klogr.New()

Log is the global logger for the internal package.

Functions

func ControlPlaneMachineLabelsForCluster

func ControlPlaneMachineLabelsForCluster(kcp *infracontrolplanev1.K3sControlPlane, clusterName string) map[string]string

ControlPlaneMachineLabelsForCluster returns a set of labels to add to a control plane machine for this specific cluster.

func MatchesK3sBootstrapConfig

func MatchesK3sBootstrapConfig(machineConfigs map[string]*infrabootstrapv1.K3sConfig, kcp *infracontrolplanev1.K3sControlPlane) collections.Func

MatchesK3sBootstrapConfig checks if machine's K3sConfigSpec is equivalent with KCP's K3sConfigSpec.

func MatchesMachineSpec

func MatchesMachineSpec(infraConfigs map[string]*unstructured.Unstructured, machineConfigs map[string]*infrabootstrapv1.K3sConfig, kcp *infracontrolplanev1.K3sControlPlane) func(machine *clusterv1.Machine) bool

MatchesMachineSpec returns a filter to find all machines that matches with KCP config and do not require any rollout. Kubernetes version, infrastructure template, and K3sConfig field need to be equivalent.

func MatchesTemplateClonedFrom

func MatchesTemplateClonedFrom(infraConfigs map[string]*unstructured.Unstructured, kcp *infracontrolplanev1.K3sControlPlane) collections.Func

MatchesTemplateClonedFrom returns a filter to find all machines that match a given KCP infra template.

Types

type ControlPlane

type ControlPlane struct {
	KCP      *infracontrolplanev1.K3sControlPlane
	Cluster  *clusterv1.Cluster
	Machines collections.Machines
	// contains filtered or unexported fields
}

ControlPlane holds business logic around control planes. It should never need to connect to a service, that responsibility lies outside of this struct. Going forward we should be trying to add more logic to here and reduce the amount of logic in the reconciler.

func NewControlPlane

func NewControlPlane(ctx context.Context, client client.Client, cluster *clusterv1.Cluster, kcp *infracontrolplanev1.K3sControlPlane, ownedMachines collections.Machines) (*ControlPlane, error)

NewControlPlane returns an instantiated ControlPlane.

func (*ControlPlane) AsOwnerReference

func (c *ControlPlane) AsOwnerReference() *metav1.OwnerReference

AsOwnerReference returns an owner reference to the K3sControlPlane.

func (*ControlPlane) FailureDomainWithMostMachines

func (c *ControlPlane) FailureDomainWithMostMachines(machines collections.Machines) *string

FailureDomainWithMostMachines returns a fd which exists both in machines and control-plane machines and has the most control-plane machines on it.

func (*ControlPlane) FailureDomains

func (c *ControlPlane) FailureDomains() clusterv1.FailureDomains

FailureDomains returns a slice of failure domain objects synced from the infrastructure provider into Cluster.Status.

func (*ControlPlane) GenerateK3sConfig

GenerateK3sConfig generates a new k3s config for creating new control plane nodes.

func (*ControlPlane) HasDeletingMachine

func (c *ControlPlane) HasDeletingMachine() bool

HasDeletingMachine returns true if any machine in the control plane is in the process of being deleted.

func (*ControlPlane) InitialControlPlaneConfig

func (c *ControlPlane) InitialControlPlaneConfig() *infrabootstrapv1.K3sConfigSpec

InitialControlPlaneConfig returns a new K3sConfigSpec that is to be used for an initializing control plane.

func (*ControlPlane) JoinControlPlaneConfig

func (c *ControlPlane) JoinControlPlaneConfig() *infrabootstrapv1.K3sConfigSpec

JoinControlPlaneConfig returns a new K3sConfigSpec that is to be used for joining control planes.

func (*ControlPlane) Logger

func (c *ControlPlane) Logger() logr.Logger

Logger returns a logger with useful context.

func (*ControlPlane) MachineInFailureDomainWithMostMachines

func (c *ControlPlane) MachineInFailureDomainWithMostMachines(machines collections.Machines) (*clusterv1.Machine, error)

MachineInFailureDomainWithMostMachines returns the first matching failure domain with machines that has the most control-plane machines on it.

func (*ControlPlane) MachineInfrastructureTemplateRef

func (c *ControlPlane) MachineInfrastructureTemplateRef() *corev1.ObjectReference

MachineInfrastructureTemplateRef returns the K3sControlPlane's infrastructure template for Machines.

func (*ControlPlane) MachineWithDeleteAnnotation

func (c *ControlPlane) MachineWithDeleteAnnotation(machines collections.Machines) collections.Machines

MachineWithDeleteAnnotation returns a machine that has been annotated with DeleteMachineAnnotation key.

func (*ControlPlane) MachinesNeedingRollout

func (c *ControlPlane) MachinesNeedingRollout() collections.Machines

MachinesNeedingRollout return a list of machines that need to be rolled out.

func (*ControlPlane) NextFailureDomainForScaleUp

func (c *ControlPlane) NextFailureDomainForScaleUp() *string

NextFailureDomainForScaleUp returns the failure domain with the fewest number of up-to-date machines.

func (*ControlPlane) PatchMachines

func (c *ControlPlane) PatchMachines(ctx context.Context) error

PatchMachines patches all the machines conditions.

func (*ControlPlane) UpToDateMachines

func (c *ControlPlane) UpToDateMachines() collections.Machines

UpToDateMachines returns the machines that are up to date with the control plane's configuration and therefore do not require rollout.

func (*ControlPlane) Version

func (c *ControlPlane) Version() *string

Version returns the K3sControlPlane's version.

type Management

type Management struct {
	Client  client.Reader
	Tracker *remote.ClusterCacheTracker
}

Management holds operations on the management cluster.

func (*Management) Get

func (m *Management) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error

Get implements ctrlclient.Reader

func (*Management) GetMachinePoolsForCluster

func (m *Management) GetMachinePoolsForCluster(ctx context.Context, cluster *clusterv1.Cluster) (*expv1.MachinePoolList, error)

GetMachinePoolsForCluster returns a list of machine pools owned by the cluster.

func (*Management) GetMachinesForCluster

func (m *Management) GetMachinesForCluster(ctx context.Context, cluster *clusterv1.Cluster, filters ...collections.Func) (collections.Machines, error)

GetMachinesForCluster returns a list of machines that can be filtered or not. If no filter is supplied then all machines associated with the target cluster are returned.

func (*Management) GetWorkloadCluster

func (m *Management) GetWorkloadCluster(ctx context.Context, clusterKey client.ObjectKey) (WorkloadCluster, error)

GetWorkloadCluster builds a cluster object. The cluster comes with an etcd client generator to connect to any etcd pod living on a managed machine.

func (*Management) List

func (m *Management) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List implements ctrlclient.Reader

type ManagementCluster

type ManagementCluster interface {
	client.Reader

	GetMachinesForCluster(ctx context.Context, cluster *clusterv1.Cluster, filters ...collections.Func) (collections.Machines, error)
	GetMachinePoolsForCluster(ctx context.Context, cluster *clusterv1.Cluster) (*expv1.MachinePoolList, error)
	GetWorkloadCluster(ctx context.Context, clusterKey client.ObjectKey) (WorkloadCluster, error)
}

ManagementCluster defines all behaviors necessary for something to function as a management cluster.

type RemoteClusterConnectionError

type RemoteClusterConnectionError struct {
	Name string
	Err  error
}

RemoteClusterConnectionError represents a failure to connect to a remote cluster.

func (*RemoteClusterConnectionError) Error

Error satisfies the error interface.

func (*RemoteClusterConnectionError) Unwrap

func (e *RemoteClusterConnectionError) Unwrap() error

Unwrap satisfies the unwrap error inteface.

type Status

type Status struct {
	// Nodes are a total count of nodes
	Nodes int32
	// ReadyNodes are the count of nodes that are reporting ready
	ReadyNodes int32
}

Status holds stats information about the cluster.

type Workload

type Workload struct {
	Client ctrlclient.Client
}

Workload defines operations on workload clusters.

func (*Workload) ClusterStatus

func (w *Workload) ClusterStatus(ctx context.Context) (Status, error)

ClusterStatus returns the status of the cluster.

func (*Workload) UpdateAgentConditions

func (w *Workload) UpdateAgentConditions(ctx context.Context, controlPlane *ControlPlane)

UpdateAgentConditions is responsible for updating machine conditions reflecting the status of all the control plane components running in a static pod generated by kubeadm. This operation is best effort, in the sense that in case of problems in retrieving the pod status, it sets the condition to Unknown state without returning any error.

func (*Workload) UpdateEtcdConditions

func (w *Workload) UpdateEtcdConditions(ctx context.Context, controlPlane *ControlPlane)

UpdateEtcdConditions is responsible for updating machine conditions reflecting the status of all the etcd members. This operation is best effort, in the sense that in case of problems in retrieving member status, it sets the condition to Unknown state without returning any error.

type WorkloadCluster

type WorkloadCluster interface {
	// Basic health and status checks.
	ClusterStatus(ctx context.Context) (Status, error)
	UpdateAgentConditions(ctx context.Context, controlPlane *ControlPlane)
	UpdateEtcdConditions(ctx context.Context, controlPlane *ControlPlane)
}

WorkloadCluster defines all behaviors necessary to upgrade kubernetes on a workload cluster

TODO: Add a detailed description to each of these method definitions.

Jump to

Keyboard shortcuts

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