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
- Variables
- func ControlPlaneLabelsForCluster(clusterName string) map[string]string
- func GenerateInitControlPlaneConfig(opts ServerConfigOpts) (*rke2ServerConfig, []bootstrapv1.File, error)
- func GenerateJoinControlPlaneConfig(opts ServerConfigOpts) (*rke2ServerConfig, []bootstrapv1.File, error)
- func GenerateWorkerConfig(opts AgentConfigOpts) (*rke2AgentConfig, []bootstrapv1.File, error)
- type AgentConfigOpts
- type AuthConfig
- type ClusterStatus
- type ControlPlane
- func (c *ControlPlane) AsOwnerReference() *metav1.OwnerReference
- func (c *ControlPlane) FailureDomainWithMostMachines(ctx context.Context, machines collections.Machines) *string
- func (c *ControlPlane) FailureDomains() clusterv1.FailureDomains
- func (c *ControlPlane) GenerateRKE2Config(spec *bootstrapv1.RKE2ConfigSpec) *bootstrapv1.RKE2Config
- func (c *ControlPlane) HasDeletingMachine() bool
- func (c *ControlPlane) HasUnhealthyMachine() bool
- func (c *ControlPlane) HealthyMachines() collections.Machines
- func (c *ControlPlane) InfrastructureRef() *corev1.ObjectReference
- func (c *ControlPlane) InitialControlPlaneConfig() *bootstrapv1.RKE2ConfigSpec
- func (c *ControlPlane) JoinControlPlaneConfig() *bootstrapv1.RKE2ConfigSpec
- func (c *ControlPlane) Logger() logr.Logger
- func (c *ControlPlane) MachineInFailureDomainWithMostMachines(ctx context.Context, machines collections.Machines) (*clusterv1.Machine, error)
- func (c *ControlPlane) MachineWithDeleteAnnotation(machines collections.Machines) collections.Machines
- func (c *ControlPlane) MachinesNeedingRollout() collections.Machines
- func (c *ControlPlane) NeedsReplacementNode() bool
- func (c *ControlPlane) NewMachine(infraRef, bootstrapRef *corev1.ObjectReference, failureDomain *string) *clusterv1.Machine
- func (c *ControlPlane) NextFailureDomainForScaleUp(ctx context.Context) *string
- func (c *ControlPlane) PatchMachines(ctx context.Context) error
- func (c *ControlPlane) UnhealthyMachines() collections.Machines
- func (c *ControlPlane) UpToDateMachines() collections.Machines
- func (c *ControlPlane) Version() *string
- type EtcdMemberStatus
- type Management
- func (m *Management) Get(ctx context.Context, key ctrlclient.ObjectKey, obj ctrlclient.Object, ...) error
- func (m *Management) GetMachinesForCluster(ctx context.Context, cluster ctrlclient.ObjectKey, filters ...collections.Func) (collections.Machines, error)
- func (m *Management) GetWorkloadCluster(ctx context.Context, clusterKey ctrlclient.ObjectKey) (WorkloadCluster, error)
- func (m *Management) List(ctx context.Context, list ctrlclient.ObjectList, opts ...ctrlclient.ListOption) error
- func (m *Management) NewWorkload(ctx context.Context, cl ctrlclient.Client, restConfig *rest.Config, ...) (*Workload, error)
- type ManagementCluster
- type Mirror
- type Registry
- type RegistryConfig
- type RegistryScope
- type RemoteClusterConnectionError
- type ServerConfigOpts
- type TLSConfig
- type Workload
- func (w *Workload) ClusterStatus(ctx context.Context) ClusterStatus
- func (w *Workload) EtcdMembers(ctx context.Context) ([]string, error)
- func (w *Workload) ForwardEtcdLeadership(ctx context.Context, machine *clusterv1.Machine, ...) error
- func (w *Workload) InitWorkload(ctx context.Context, cp *ControlPlane) error
- func (w *Workload) PatchNodes(ctx context.Context, cp *ControlPlane) error
- func (w *Workload) ReconcileEtcdMembers(ctx context.Context, nodeNames []string, version semver.Version) ([]string, error)
- func (w *Workload) RemoveEtcdMemberForMachine(ctx context.Context, machine *clusterv1.Machine) error
- func (w *Workload) UpdateAgentConditions(controlPlane *ControlPlane)
- func (w *Workload) UpdateEtcdConditions(controlPlane *ControlPlane)
- func (w *Workload) UpdateNodeMetadata(ctx context.Context, controlPlane *ControlPlane) error
- type WorkloadCluster
Constants ¶
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 */ )
const ( // DefaultRKE2RegistriesLocation is the default location for the registries.yaml file. DefaultRKE2RegistriesLocation string = "/etc/rancher/rke2/registries.yaml" )
const ( // DefaultWorkloadTimeout is the default timeout for the management cluster. DefaultWorkloadTimeout = 30 * time.Second )
const (
// RKE2ControlPlaneControllerName defines the controller used when creating clients.
RKE2ControlPlaneControllerName = "rke2-controlplane-controller"
)
Variables ¶
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 ¶
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 Version string }
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 // HasRKE2ServingSecret will be true if the rke2-serving secret has been uploaded, false otherwise. HasRKE2ServingSecret bool }
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(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) 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(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
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 EtcdMemberStatus ¶ added in v0.5.0
EtcdMemberStatus contains status information for a single etcd member.
type Management ¶
type Management struct { Client ctrlclient.Client SecretCachingClient ctrlclient.Reader Tracker *remote.ClusterCacheTracker }
Management holds operations on the management cluster.
func (*Management) Get ¶
func (m *Management) Get(ctx context.Context, key ctrlclient.ObjectKey, obj ctrlclient.Object, opts ...ctrlclient.GetOption) error
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 ¶
func (m *Management) List(ctx context.Context, list ctrlclient.ObjectList, opts ...ctrlclient.ListOption) error
List implements ctrlclient.Reader.
func (*Management) NewWorkload ¶ added in v0.5.0
func (m *Management) NewWorkload( ctx context.Context, cl ctrlclient.Client, restConfig *rest.Config, clusterKey ctrlclient.ObjectKey, ) (*Workload, error)
NewWorkload is creating a new ClusterWorkload instance.
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 ¶
RemoteClusterConnectionError represents a failure to connect to a remote cluster.
func (*RemoteClusterConnectionError) Error ¶
func (e *RemoteClusterConnectionError) Error() string
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 Version string }
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,omitempty" toml:"ca_file" yaml:"ca_file,omitempty"` CertFile string `json:"cert_file,omitempty" toml:"cert_file" yaml:"cert_file,omitempty"` KeyFile string `json:"key_file,omitempty" toml:"key_file" yaml:"key_file,omitempty"` InsecureSkipVerify bool `json:"insecure_skip_verify,omitempty" toml:"insecure_skip_verify" yaml:"insecure_skip_verify,omitempty"` }
TLSConfig contains the CA/Cert/Key used for a registry.
type Workload ¶
type Workload struct { ctrlclient.Client Nodes map[string]*corev1.Node // contains filtered or unexported fields }
Workload defines operations on workload clusters.
func (*Workload) ClusterStatus ¶
func (w *Workload) ClusterStatus(ctx context.Context) ClusterStatus
ClusterStatus returns the status of the cluster.
func (*Workload) EtcdMembers ¶ added in v0.5.0
EtcdMembers returns the current set of members in an etcd cluster.
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 ¶ added in v0.5.0
func (w *Workload) ForwardEtcdLeadership(ctx context.Context, machine *clusterv1.Machine, leaderCandidate *clusterv1.Machine) error
ForwardEtcdLeadership forwards etcd leadership to the first follower.
func (*Workload) InitWorkload ¶
func (w *Workload) InitWorkload(ctx context.Context, cp *ControlPlane) error
InitWorkload prepares workload for evaluating status conditions.
func (*Workload) PatchNodes ¶
func (w *Workload) PatchNodes(ctx context.Context, cp *ControlPlane) error
PatchNodes patches the nodes in the workload cluster.
func (*Workload) ReconcileEtcdMembers ¶ added in v0.5.0
func (w *Workload) ReconcileEtcdMembers(ctx context.Context, nodeNames []string, version semver.Version) ([]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 etcd does not run etcd health checks on them.
func (*Workload) RemoveEtcdMemberForMachine ¶ added in v0.5.0
func (w *Workload) RemoveEtcdMemberForMachine(ctx context.Context, machine *clusterv1.Machine) error
RemoveEtcdMemberForMachine removes the etcd member from the target cluster's etcd cluster. Removing the last remaining member of the cluster is not supported.
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 ¶
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(ctx context.Context) ClusterStatus UpdateAgentConditions(controlPlane *ControlPlane) UpdateEtcdConditions(controlPlane *ControlPlane) // State recovery tasks. RemoveEtcdMemberForMachine(ctx context.Context, machine *clusterv1.Machine) error ForwardEtcdLeadership(ctx context.Context, machine *clusterv1.Machine, leaderCandidate *clusterv1.Machine) error ReconcileEtcdMembers(ctx context.Context, nodeNames []string, version semver.Version) ([]string, error) EtcdMembers(ctx context.Context) ([]string, error) }
WorkloadCluster defines all behaviors necessary to upgrade kubernetes on a workload cluster.