Documentation
¶
Overview ¶
Package common provides shared utilities for infrastructure controllers.
Index ¶
- Constants
- Variables
- func DetermineAPIEndpoint(service *corev1.Service, capiCluster *clusterv1.Cluster) (string, error)
- func DiscoverControlPlaneService(ctx context.Context, c client.Client, ...) (*corev1.Service, error)
- func ExtractClusterNameFromDeploymentName(deploymentName, colonyName string) string
- func FindRegionalClusterDeployment(ctx context.Context, c client.Client, namespace, regionalClusterName string) (*k0rdentv1beta1.ClusterDeployment, error)
- func FindRegionalClusterDeploymentsByRole(ctx context.Context, c client.Client, namespace string) ([]k0rdentv1beta1.ClusterDeployment, error)
- func GetAPIServerPort(service *corev1.Service) int32
- func GetCAPICluster(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Cluster, error)
- func GetClusterClientForCD(ctx context.Context, managementClient client.Client, namespace, cdName string, ...) (client.Client, error)
- func GetColonyClusterByName(colony *infrav1.Colony, clusterName string) *infrav1.ColonyCluster
- func GetServiceExternalAddress(service *corev1.Service) (string, bool)
- func IsRegionalChild(colonyCluster *infrav1.ColonyCluster) (bool, string)
- func ResolveRegionalClient(ctx context.Context, managementClient client.Client, colony *infrav1.Colony, ...) (client.Client, bool, error)
- func ValidateControlPlanePorts(service *corev1.Service) error
Constants ¶
const ( // LabelKOFRegionalClusterName is the label on a ColonyCluster that indicates // it is a child of a regional cluster. The value is the regional cluster's name. LabelKOFRegionalClusterName = "k0rdent.mirantis.com/kof-regional-cluster-name" // LabelKOFClusterName is the label on a ClusterDeployment that identifies // the cluster by its logical name (used to find the regional ClusterDeployment). LabelKOFClusterName = "k0rdent.mirantis.com/kof-cluster-name" )
const ( // LabelKOFClusterRole is the label on a ClusterDeployment that identifies // the cluster's role. Regional clusters have the value "regional". LabelKOFClusterRole = "k0rdent.mirantis.com/kof-cluster-role" )
Variables ¶
var ErrControlPlaneEndpointNotReady = errors.New("control plane endpoint not published yet")
ErrControlPlaneEndpointNotReady is returned by DetermineAPIEndpoint when the control plane is exposed via NodePort but the CAPI Cluster has not published a worker-reachable controlPlaneEndpoint yet. Callers should treat it as "retry later", not as a failure.
Functions ¶
func DetermineAPIEndpoint ¶
DetermineAPIEndpoint determines the API server endpoint that child-cluster workloads (Cilium's k8sServiceHost) must dial to reach the hosted control plane.
- LoadBalancer with an external address: that address.
- NodePort: the CAPI Cluster's controlPlaneEndpoint. The Service's ClusterIP is unreachable from a remote worker's host network, so when the endpoint is not published yet the function returns ErrControlPlaneEndpointNotReady rather than falling back to the ClusterIP.
- Anything else (ClusterIP, LoadBalancer still pending): the ClusterIP.
capiCluster may be nil (not created yet). Returns the endpoint as "host:port".
func DiscoverControlPlaneService ¶
func DiscoverControlPlaneService(ctx context.Context, c client.Client, namespace, colonyName, clusterName string) (*corev1.Service, error)
DiscoverControlPlaneService discovers the k0smotron control plane Service for a cluster. Uses label selectors to find services, supporting name variations like -nodeport or -loadbalancer suffixes. Returns the service with validated ClusterIP and ports 30443, 30132.
func ExtractClusterNameFromDeploymentName ¶
ExtractClusterNameFromDeploymentName extracts the cluster name from a ClusterDeployment name. ClusterDeployment names follow the pattern: <colony-name>-<cluster-name>
func FindRegionalClusterDeployment ¶ added in v0.8.0
func FindRegionalClusterDeployment(ctx context.Context, c client.Client, namespace, regionalClusterName string) (*k0rdentv1beta1.ClusterDeployment, error)
FindRegionalClusterDeployment finds the ClusterDeployment for a regional cluster by matching the label k0rdent.mirantis.com/kof-cluster-name=<regionalClusterName>.
func FindRegionalClusterDeploymentsByRole ¶ added in v0.8.2
func FindRegionalClusterDeploymentsByRole(ctx context.Context, c client.Client, namespace string) ([]k0rdentv1beta1.ClusterDeployment, error)
FindRegionalClusterDeploymentsByRole finds all regional ClusterDeployments in a namespace by matching the label k0rdent.mirantis.com/kof-cluster-role=regional.
func GetAPIServerPort ¶
GetAPIServerPort returns the API server port from the service. Checks by port name first, then falls back to common port numbers.
func GetCAPICluster ¶ added in v0.11.2
func GetCAPICluster(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Cluster, error)
GetCAPICluster fetches the Cluster API Cluster backing a ClusterDeployment. k0rdent names the CAPI Cluster after the ClusterDeployment, and k0smotron publishes the address workers dial (its externalAddress, explicit or auto-detected, plus the API port) in spec.controlPlaneEndpoint. Returns (nil, nil) while the Cluster does not exist yet.
func GetClusterClientForCD ¶ added in v0.9.0
func GetClusterClientForCD(ctx context.Context, managementClient client.Client, namespace, cdName string, scheme *runtime.Scheme) (client.Client, error)
GetClusterClientForCD builds a controller-runtime client for the cluster behind a ClusterDeployment, from its `<cd-name>-kubeconfig` secret on the management cluster. It is generic: the same helper serves both regional and child ClusterDeployments — the caller decides which CD to target. (It was formerly named GetRegionalClusterClient, which misleadingly implied regional-only; workspace feasibility/gating uses it against child clusters.)
func GetColonyClusterByName ¶ added in v0.8.0
func GetColonyClusterByName(colony *infrav1.Colony, clusterName string) *infrav1.ColonyCluster
GetColonyClusterByName looks up a ColonyCluster from the Colony spec by clusterName.
func GetServiceExternalAddress ¶
GetServiceExternalAddress extracts the external address from a LoadBalancer service. Returns the hostname or IP and a boolean indicating if an external address was found.
func IsRegionalChild ¶ added in v0.8.0
func IsRegionalChild(colonyCluster *infrav1.ColonyCluster) (bool, string)
IsRegionalChild checks if a ColonyCluster is a child of a regional cluster. Returns (true, regionalName) if the cluster has the regional cluster label, (false, "") otherwise. This is the sole detection mechanism — no label means legacy behavior, full backward compatibility.
func ResolveRegionalClient ¶ added in v0.8.0
func ResolveRegionalClient( ctx context.Context, managementClient client.Client, colony *infrav1.Colony, clusterName string, scheme *runtime.Scheme, ) (client.Client, bool, error)
ResolveRegionalClient checks if a cluster is a regional child and, if so, builds a client for the regional cluster. Returns (regionalClient, isRegional, error). If the cluster is not a regional child, returns (nil, false, nil).
func ValidateControlPlanePorts ¶
ValidateControlPlanePorts validates that required ports exist in the service. Checks by port name (more reliable) and falls back to common port numbers.
Types ¶
This section is empty.