ck8s

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2024 License: Apache-2.0 Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CK8sControlPlaneControllerName defines the controller used when creating clients.
	CK8sControlPlaneControllerName = "ck8s-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")
)

Functions

func ControlPlaneLabelsForCluster

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

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

func GenerateInitControlPlaneConfig

func GenerateInitControlPlaneConfig(cfg InitControlPlaneConfig) (apiv1.BootstrapConfig, error)

func GenerateJoinWorkerConfig

func GenerateJoinWorkerConfig(cfg JoinWorkerConfig) apiv1.WorkerNodeJoinConfig

func NewK8sdClientGenerator

func NewK8sdClientGenerator(restConfig *rest.Config, proxyClientTimeout time.Duration) (*k8sdClientGenerator, error)

func RenderK8sdProxyDaemonSetManifest

func RenderK8sdProxyDaemonSetManifest(input K8sdProxyDaemonSetInput) ([]byte, error)

RenderK8sdProxyDaemonSet renders the manifest for the k8sd-proxy daemonset based on supplied configuration.

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
	// HasK8sdConfigMap will be true if the k8sd-config configmap has been uploaded, false otherwise.
	HasK8sdConfigMap bool
}

ClusterStatus holds stats information about the cluster.

type ControlPlane

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

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

func (c *ControlPlane) GenerateCK8sConfig(spec *bootstrapv1.CK8sConfigSpec) *bootstrapv1.CK8sConfig

GenerateCK8sConfig generates a new CK8sConfig 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 CK8sControlPlane's infrastructure template.

func (*ControlPlane) InitialControlPlaneConfig

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

InitialControlPlaneConfig returns a new CK8sConfigSpec 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 k8s-dqlite.

func (*ControlPlane) JoinControlPlaneConfig

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

JoinControlPlaneConfig returns a new CK8sConfigSpec 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 CK8sControlPlane's version.

type InitControlPlaneConfig

type InitControlPlaneConfig struct {
	ControlPlaneEndpoint  string
	ControlPlaneConfig    bootstrapv1.CK8sControlPlaneConfig
	InitConfig            bootstrapv1.CK8sInitConfiguration
	PopulatedCertificates secret.Certificates

	ClusterNetwork *clusterv1.ClusterNetwork
}

type JoinControlPlaneConfig

type JoinControlPlaneConfig struct {
	ControlPlaneEndpoint string
	ControlPlaneConfig   bootstrapv1.CK8sControlPlaneConfig

	ExtraKubeAPIServerArgs map[string]*string
}

type JoinWorkerConfig

type JoinWorkerConfig struct {
}

type K8sdClient

type K8sdClient struct {
	NodeIP string
	Client *http.Client
}

type K8sdProxyDaemonSetInput

type K8sdProxyDaemonSetInput struct {
	K8sdPort int
}

type Management

type Management struct {
	ManagementCluster

	Client client.Client

	K8sdDialTimeout 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, microclusterPort int) (*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, microclusterPort int) (*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
	K8sdClientGenerator *k8sdClientGenerator
	// 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) GetK8sdProxyForControlPlane

func (w *Workload) GetK8sdProxyForControlPlane(ctx context.Context, options k8sdProxyOptions) (*K8sdClient, error)

GetK8sdProxyForControlPlane returns a k8sd proxy client for the control plane.

func (*Workload) NewControlPlaneJoinToken

func (w *Workload) NewControlPlaneJoinToken(ctx context.Context, name string) (string, error)

NewControlPlaneJoinToken creates a new join token for a control plane node. NewControlPlaneJoinToken reaches out to the control-plane of the workload cluster via k8sd-proxy client.

func (*Workload) NewWorkerJoinToken

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

NewWorkerJoinToken creates a new join token for a worker node. NewWorkerJoinToken reaches out to the control-plane of the workload cluster via k8sd-proxy client.

func (*Workload) RemoveMachineFromCluster

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

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) 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)
	NewControlPlaneJoinToken(ctx context.Context, name string) (string, error)
	NewWorkerJoinToken(ctx context.Context) (string, error)

	RemoveMachineFromCluster(ctx context.Context, machine *clusterv1.Machine) error
}

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

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

Directories

Path Synopsis
Package apiv1 contains types that are copied from https://github.com/canonical/k8s-snap/tree/release-1.30/src/k8s/api/v1
Package apiv1 contains types that are copied from https://github.com/canonical/k8s-snap/tree/release-1.30/src/k8s/api/v1

Jump to

Keyboard shortcuts

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