rke2

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Copyright 2022 SUSE.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	// DefaultRKE2ConfigLocation is the default location for the RKE2 config file.
	DefaultRKE2ConfigLocation = "/etc/rancher/rke2/config.yaml"

	// DefaultRKE2CloudProviderConfigLocation is the default location for the RKE2 cloud provider config file.
	DefaultRKE2CloudProviderConfigLocation = "/etc/rancher/rke2/cloud-provider-config"

	// DefaultRKE2JoinPort is the default port used for joining nodes to the cluster. It is open on the control plane nodes.
	DefaultRKE2JoinPort = 9345

	// CISNodePreparationScript is the script that is used to prepare a node for CIS compliance.
	CISNodePreparationScript = `` /* 858-byte string literal not displayed */

)
View Source
const (
	// DefaultRKE2RegistriesLocation is the default location for the registries.yaml file.
	DefaultRKE2RegistriesLocation string = "/etc/rancher/rke2/registries.yaml"
)
View Source
const (
	// DefaultWorkloadTimeout is the default timeout for the management cluster.
	DefaultWorkloadTimeout = 30 * time.Second
)
View Source
const (
	// RKE2ControlPlaneControllerName defines the controller used when creating clients.
	RKE2ControlPlaneControllerName = "rke2-controlplane-controller"
)

Variables

View Source
var ErrControlPlaneMinNodes = errors.New("cluster has fewer than 2 control plane nodes; removing an etcd member is not supported")

ErrControlPlaneMinNodes is returned when the control plane has fewer than 2 nodes.

Functions

func ControlPlaneLabelsForCluster

func ControlPlaneLabelsForCluster(clusterName string) map[string]string

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

func GenerateInitControlPlaneConfig

func GenerateInitControlPlaneConfig(opts ServerConfigOpts) (*rke2ServerConfig, []bootstrapv1.File, error)

GenerateInitControlPlaneConfig generates the rke2 server and agent config for the init control plane node.

func GenerateJoinControlPlaneConfig

func GenerateJoinControlPlaneConfig(opts ServerConfigOpts) (*rke2ServerConfig, []bootstrapv1.File, error)

GenerateJoinControlPlaneConfig generates the rke2 agent config for joining a control plane node.

func GenerateWorkerConfig

func GenerateWorkerConfig(opts AgentConfigOpts) (*rke2AgentConfig, []bootstrapv1.File, error)

GenerateWorkerConfig generates the rke2 agent config and files.

Types

type AgentConfigOpts

type AgentConfigOpts struct {
	ServerURL              string
	Token                  string
	AgentConfig            bootstrapv1.RKE2AgentConfig
	Ctx                    context.Context
	Client                 client.Client
	CloudProviderName      string
	CloudProviderConfigMap *corev1.ObjectReference
}

AgentConfigOpts is a struct that holds the information needed to generate the rke2 server config.

type AuthConfig

type AuthConfig struct {
	// Username is the username to login the registry.
	Username string `json:"username,omitempty" toml:"username" yaml:"username,omitempty"`
	// Password is the password to login the registry.
	Password string `json:"password,omitempty" toml:"password" yaml:"password,omitempty"`
	// Auth is a base64 encoded string from the concatenation of the username,
	// a colon, and the password.
	Auth string `json:"auth,omitempty" toml:"auth" yaml:"auth,omitempty"`
	// IdentityToken is used to authenticate the user and get
	// an access token for the registry.
	IdentityToken string `json:"identity_token,omitempty" toml:"identitytoken" yaml:"identity_token,omitempty"`
}

AuthConfig contains the config related to authentication to a specific registry.

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
}

ClusterStatus holds stats information about the cluster.

type ControlPlane

type ControlPlane struct {
	RCP      *controlplanev1.RKE2ControlPlane
	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,
	rcp *controlplanev1.RKE2ControlPlane,
	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 RKE2ControlPlane.

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

func (c *ControlPlane) GenerateRKE2Config(spec *bootstrapv1.RKE2ConfigSpec) *bootstrapv1.RKE2Config

GenerateRKE2Config generates a new RKE2 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) 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) InfrastructureRef

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

InfrastructureRef returns the RKE2ControlPlane's infrastructure template.

func (*ControlPlane) InitialControlPlaneConfig

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

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

func (*ControlPlane) JoinControlPlaneConfig

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

JoinControlPlaneConfig returns a new RKE2ConfigSpec 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) 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() *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 the machines in the control plane.

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

type Management

type Management struct {
	Client ctrlclient.Reader
}

Management holds operations on the management cluster.

func (*Management) Get

Get implements ctrlclient.Reader.

func (*Management) GetMachinesForCluster

func (m *Management) GetMachinesForCluster(
	ctx context.Context,
	cluster ctrlclient.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 ctrlclient.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

List implements ctrlclient.Reader.

type ManagementCluster

type ManagementCluster interface {
	ctrlclient.Reader

	GetMachinesForCluster(ctx context.Context, cluster ctrlclient.ObjectKey, filters ...collections.Func) (collections.Machines, error)
	GetWorkloadCluster(ctx context.Context, clusterKey ctrlclient.ObjectKey) (WorkloadCluster, error)
}

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

type Mirror

type Mirror struct {
	// Endpoints are endpoints for a namespace. CRI plugin will try the endpoints
	// one by one until a working one is found. The endpoint must be a valid url
	// with host specified.
	// The scheme, host and path from the endpoint URL will be used.
	Endpoint []string `json:"endpoint" toml:"endpoint" yaml:"endpoint"`

	// Rewrites are repository rewrite rules for a namespace. When fetching image resources
	// from an endpoint and a key matches the repository via regular expression matching
	// it will be replaced with the corresponding value from the map in the resource request.
	Rewrite map[string]string `json:"rewrite,omitempty" toml:"rewrite" yaml:"rewrite,omitempty"`
}

Mirror contains the config related to the registry mirror.

type Registry

type Registry struct {
	// Mirrors are namespace to mirror mapping for all namespaces.
	Mirrors map[string]Mirror `json:"mirrors" toml:"mirrors" yaml:"mirrors"`
	// Configs are configs for each registry.
	// The key is the FDQN or IP of the registry.
	Configs map[string]RegistryConfig `json:"configs" toml:"configs" yaml:"configs"`
}

Registry is registry settings including mirrors, TLS, and credentials.

func GenerateRegistries

func GenerateRegistries(rke2ConfigRegistry RegistryScope) (*Registry, []bootstrapv1.File, error)

GenerateRegistries generates the registries.yaml file and the corresponding files for the TLS certificates.

type RegistryConfig

type RegistryConfig struct {
	// Auth contains information to authenticate to the registry.
	Auth *AuthConfig `json:"auth,omitempty" toml:"auth" yaml:"auth,omitempty"`
	// TLS is a pair of CA/Cert/Key which then are used when creating the transport
	// that communicates with the registry.
	TLS *TLSConfig `json:"tls,omitempty" toml:"tls" yaml:"tls,omitempty"`
}

RegistryConfig contains configuration used to communicate with the registry.

type RegistryScope

type RegistryScope struct {
	Registry bootstrapv1.Registry
	Client   client.Client
	Ctx      context.Context
	Logger   logr.Logger
}

RegistryScope is a wrapper around the Registry struct to provide the client, context and a logger to the Registry struct.

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 ServerConfigOpts

type ServerConfigOpts struct {
	Cluster              clusterv1.Cluster
	ControlPlaneEndpoint string
	Token                string
	ServerURL            string
	ServerConfig         controlplanev1.RKE2ServerConfig
	AgentConfig          bootstrapv1.RKE2AgentConfig
	Ctx                  context.Context
	Client               client.Client
}

ServerConfigOpts is a struct that contains the information needed to generate a RKE2 server config.

type TLSConfig

type TLSConfig struct {
	CAFile             string `json:"ca_file"              toml:"ca_file"              yaml:"ca_file"`
	CertFile           string `json:"cert_file"            toml:"cert_file"            yaml:"cert_file"`
	KeyFile            string `json:"key_file"             toml:"key_file"             yaml:"key_file"`
	InsecureSkipVerify bool   `json:"insecure_skip_verify" toml:"insecure_skip_verify" yaml:"insecure_skip_verify"`
}

TLSConfig contains the CA/Cert/Key used for a registry.

type Workload

type Workload struct {
	client.Client

	Nodes map[string]*corev1.Node
	// contains filtered or unexported fields
}

Workload defines operations on workload clusters.

func NewWorkload added in v0.2.0

func NewWorkload(cl client.Client) *Workload

NewWorkload is creating a new ClusterWorkload instance.

func (*Workload) ClusterStatus

func (w *Workload) ClusterStatus() ClusterStatus

ClusterStatus returns the status of the cluster.

func (*Workload) InitWorkload added in v0.2.0

func (w *Workload) InitWorkload(ctx context.Context, cp *ControlPlane) error

InitWorkload prepares workload for evaluating status conditions.

func (*Workload) PatchNodes added in v0.2.0

func (w *Workload) PatchNodes(ctx context.Context, cp *ControlPlane) error

PatchNodes patches the nodes in the workload cluster.

func (*Workload) UpdateAgentConditions

func (w *Workload) UpdateAgentConditions(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 RKE2. 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(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.

func (*Workload) UpdateNodeMetadata added in v0.2.0

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

UpdateNodeMetadata is responsible for populating node metadata after it is referenced from machine object.

type WorkloadCluster

type WorkloadCluster interface {
	// Basic health and status checks.
	InitWorkload(ctx context.Context, controlPlane *ControlPlane) error
	UpdateNodeMetadata(ctx context.Context, controlPlane *ControlPlane) error

	ClusterStatus() ClusterStatus
	UpdateAgentConditions(controlPlane *ControlPlane)
	UpdateEtcdConditions(controlPlane *ControlPlane)
}

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

Jump to

Keyboard shortcuts

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