k3s

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2024 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EtcdRemoveAnnotation      = "etcd.k3s.cattle.io/remove"
	EtcdRemovedNodeAnnotation = "etcd.k3s.cattle.io/removed-node-name"
)
View Source
const DefaultK3sConfigLocation = "/etc/rancher/k3s/config.yaml"
View Source
const (
	// KThreesControlPlaneControllerName defines the controller used when creating clients.
	KThreesControlPlaneControllerName = "kthrees-controlplane-controller"
)

Variables

View Source
var (
	ErrFailedToPickForDeletion   = errors.New("failed to pick machine to mark for deletion")
	ErrFailedToCreatePatchHelper = errors.New("failed to create patch for machine")
)
View Source
var (
	ErrControlPlaneMinNodes = errors.New("cluster has fewer than 2 control plane nodes; removing an etcd member is not supported")
)
View Source
var ErrInvalidCoreDNSVersion = errors.New("invalid CoreDNS version given")

Functions

func ControlPlaneLabelsForCluster

func ControlPlaneLabelsForCluster(clusterName string, machineTemplate controlplanev1.KThreesControlPlaneMachineTemplate) map[string]string

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

Types

type ClusterStatus

type ClusterStatus struct {
	// Nodes are a total count of nodes
	Nodes int32
	// ReadyNodes are the count of nodes that are reporting ready
	ReadyNodes int32
	// HasK3sServingSecret will be true if the k3s-serving secret has been uploaded, false otherwise.
	HasK3sServingSecret bool
}

ClusterStatus holds stats information about the cluster.

type ControlPlane

type ControlPlane struct {
	KCP      *controlplanev1.KThreesControlPlane
	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 *controlplanev1.KThreesControlPlane, 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 KThreesControlPlane.

func (*ControlPlane) EtcdImageData

func (c *ControlPlane) EtcdImageData() (string, string)

EtcdImageData returns the etcd image data embedded in the ClusterConfiguration or empty strings if none are defined.

func (*ControlPlane) FailureDomainWithMostMachines

func (c *ControlPlane) FailureDomainWithMostMachines(ctx context.Context, 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) GenerateKThreesConfig

func (c *ControlPlane) GenerateKThreesConfig(spec *bootstrapv1.KThreesConfigSpec) *bootstrapv1.KThreesConfig

GenerateKThreesConfig generates a new KThreesConfig 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) HasHealthyMachineStillProvisioning

func (c *ControlPlane) HasHealthyMachineStillProvisioning() bool

HasHealthyMachineStillProvisioning returns true if any healthy machine in the control plane is still in the process of being provisioned.

func (*ControlPlane) HasUnhealthyMachine

func (c *ControlPlane) HasUnhealthyMachine() bool

HasUnhealthyMachine returns true if any machine in the control plane is marked as unhealthy by MHC.

func (*ControlPlane) HealthyMachines

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

HealthyMachines returns the list of control plane machines not marked as unhealthy by MHC.

func (*ControlPlane) InfrastructureTemplate

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

InfrastructureTemplate returns the KThreesControlPlane's infrastructure template.

func (*ControlPlane) InitialControlPlaneConfig

func (c *ControlPlane) InitialControlPlaneConfig() *bootstrapv1.KThreesConfigSpec

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

func (*ControlPlane) IsEtcdManaged

func (c *ControlPlane) IsEtcdManaged() bool

IsEtcdManaged returns true if the control plane relies on a managed etcd.

func (*ControlPlane) JoinControlPlaneConfig

func (c *ControlPlane) JoinControlPlaneConfig() *bootstrapv1.KThreesConfigSpec

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

func (*ControlPlane) MachineInFailureDomainWithMostMachines

func (c *ControlPlane) MachineInFailureDomainWithMostMachines(ctx context.Context, 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) 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) NeedsReplacementNode

func (c *ControlPlane) NeedsReplacementNode() bool

NeedsReplacementNode determines if the control plane needs to create a replacement node during upgrade.

func (*ControlPlane) NewMachine

func (c *ControlPlane) NewMachine(infraRef, bootstrapRef *corev1.ObjectReference, failureDomain *string) *clusterv1.Machine

NewMachine returns a machine configured to be a part of the control plane.

func (*ControlPlane) NextFailureDomainForScaleUp

func (c *ControlPlane) NextFailureDomainForScaleUp(ctx context.Context) *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

func (*ControlPlane) UnhealthyMachines

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

UnhealthyMachines returns the list of control plane machines marked as unhealthy by MHC.

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 KThreesControlPlane's version.

type CoreDNSMigrator

type CoreDNSMigrator struct{}

func (*CoreDNSMigrator) Migrate

func (c *CoreDNSMigrator) Migrate(fromCoreDNSVersion, toCoreDNSVersion, corefile string, deprecations bool) (string, error)

type EtcdClientGenerator

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

EtcdClientGenerator generates etcd clients that connect to specific etcd members on particular control plane nodes.

func NewEtcdClientGenerator

func NewEtcdClientGenerator(restConfig *rest.Config, tlsConfig *tls.Config, etcdDialTimeout, etcdCallTimeout time.Duration) *EtcdClientGenerator

NewEtcdClientGenerator returns a new etcdClientGenerator instance.

type K3sAgentConfig

type K3sAgentConfig struct {
	Token           string   `json:"token,omitempty"`
	Server          string   `json:"server,omitempty"`
	KubeletArgs     []string `json:"kubelet-arg,omitempty"`
	NodeLabels      []string `json:"node-label,omitempty"`
	NodeTaints      []string `json:"node-taint,omitempty"`
	PrivateRegistry string   `json:"private-registry,omitempty"`
	KubeProxyArgs   []string `json:"kube-proxy-arg,omitempty"`
	NodeName        string   `json:"node-name,omitempty"`
}

func GenerateWorkerConfig

func GenerateWorkerConfig(serverURL string, token string, serverConfig bootstrapv1.KThreesServerConfig, agentConfig bootstrapv1.KThreesAgentConfig) K3sAgentConfig

type K3sServerConfig

type K3sServerConfig struct {
	DisableCloudController    bool     `json:"disable-cloud-controller,omitempty"`
	KubeAPIServerArgs         []string `json:"kube-apiserver-arg,omitempty"`
	KubeControllerManagerArgs []string `json:"kube-controller-manager-arg,omitempty"`
	KubeSchedulerArgs         []string `json:"kube-scheduler-arg,omitempty"`
	TLSSan                    []string `json:"tls-san,omitempty"`
	BindAddress               string   `json:"bind-address,omitempty"`
	HTTPSListenPort           string   `json:"https-listen-port,omitempty"`
	AdvertiseAddress          string   `json:"advertise-address,omitempty"`
	AdvertisePort             string   `json:"advertise-port,omitempty"`
	ClusterCidr               string   `json:"cluster-cidr,omitempty"`
	ServiceCidr               string   `json:"service-cidr,omitempty"`
	ClusterDNS                string   `json:"cluster-dns,omitempty"`
	ClusterDomain             string   `json:"cluster-domain,omitempty"`
	DisableComponents         []string `json:"disable,omitempty"`
	ClusterInit               bool     `json:"cluster-init,omitempty"`
	SystemDefaultRegistry     string   `json:"system-default-registry,omitempty"`
	K3sAgentConfig            `json:",inline"`
}

func GenerateInitControlPlaneConfig

func GenerateInitControlPlaneConfig(controlPlaneEndpoint string, token string, serverConfig bootstrapv1.KThreesServerConfig, agentConfig bootstrapv1.KThreesAgentConfig) K3sServerConfig

func GenerateJoinControlPlaneConfig

func GenerateJoinControlPlaneConfig(serverURL string, token string, controlplaneendpoint string, serverConfig bootstrapv1.KThreesServerConfig, agentConfig bootstrapv1.KThreesAgentConfig) K3sServerConfig

type Management

type Management struct {
	ManagementCluster

	Client          client.Reader
	EtcdDialTimeout time.Duration
	EtcdCallTimeout time.Duration
}

Management holds operations on the management cluster.

func (*Management) Get

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

Get implements ctrlclient.Reader.

func (*Management) GetMachinesForCluster

func (m *Management) GetMachinesForCluster(ctx context.Context, cluster client.ObjectKey, 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) (*Workload, 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 client.ObjectKey, filters ...collections.Func) (collections.Machines, error)
	GetWorkloadCluster(ctx context.Context, clusterKey client.ObjectKey) (*Workload, 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

func (*RemoteClusterConnectionError) Unwrap

func (e *RemoteClusterConnectionError) Unwrap() error

type Workload

type Workload struct {
	WorkloadCluster

	Client           ctrlclient.Client
	ClientRestConfig *rest.Config

	CoreDNSMigrator coreDNSMigrator
	// contains filtered or unexported fields
}

Workload defines operations on workload clusters.

func (*Workload) ClusterStatus

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

ClusterStatus returns the status of the cluster.

func (*Workload) EtcdMembers

func (w *Workload) EtcdMembers(ctx context.Context) ([]string, error)

EtcdMembers returns the current set of members in an etcd cluster. It will convert the etcd members to a list of node names, and return a list of node names.

NOTE: This methods uses control plane machines/nodes only to get in contact with etcd, but then it relies on etcd as ultimate source of truth for the list of members. This is intended to allow informed decisions on actions impacting etcd quorum.

func (*Workload) ForwardEtcdLeadership

func (w *Workload) ForwardEtcdLeadership(ctx context.Context, machine *clusterv1.Machine, leaderCandidate *clusterv1.Machine) error

ForwardEtcdLeadership forwards etcd leadership to the first follower.

func (*Workload) ReconcileEtcdMembers

func (w *Workload) ReconcileEtcdMembers(ctx context.Context, nodeNames []string) ([]string, error)

ReconcileEtcdMembers iterates over all etcd members and finds members that do not have corresponding nodes. If there are any such members, it deletes them from etcd so that k3s controlplane does not run etcd health checks on them.

func (*Workload) RemoveEtcdMemberForMachine

func (w *Workload) RemoveEtcdMemberForMachine(ctx context.Context, machine *clusterv1.Machine) (bool, error)

RemoveEtcdMemberForMachine removes the etcd member from the target cluster's etcd cluster, and returns true if the member has been removed. Removing the last remaining member of the cluster is not supported.

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. 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) UpdateCoreDNS

func (w *Workload) UpdateCoreDNS(ctx context.Context, kcp *controlplanev1.KThreesControlPlane) error

UpdateCoreDNS updates the coredns corefile and coredns deployment.

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) (ClusterStatus, error)
	UpdateAgentConditions(ctx context.Context, controlPlane *ControlPlane)
	UpdateEtcdConditions(ctx context.Context, controlPlane *ControlPlane)

	// Etcd tasks
	RemoveEtcdMemberForMachine(ctx context.Context, machine *clusterv1.Machine) (bool, error)
	ForwardEtcdLeadership(ctx context.Context, machine *clusterv1.Machine, leaderCandidate *clusterv1.Machine) error
	ReconcileEtcdMembers(ctx context.Context, nodeNames []string) ([]string, error)
}

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