Documentation
¶
Overview ¶
Package common provides shared utilities for infrastructure controllers.
Index ¶
- Constants
- func DetermineAPIEndpoint(service *corev1.Service) (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 GetColonyClusterByName(colony *infrav1.Colony, clusterName string) *infrav1.ColonyCluster
- func GetRegionalClusterClient(ctx context.Context, managementClient client.Client, ...) (client.Client, error)
- 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 ¶
This section is empty.
Functions ¶
func DetermineAPIEndpoint ¶
DetermineAPIEndpoint determines the API endpoint for a control plane service. If the service is a LoadBalancer with an external address, it returns the external address. Otherwise, it returns the ClusterIP. Returns the endpoint in format "host:port" and an error if the endpoint cannot be determined.
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 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 GetRegionalClusterClient ¶ added in v0.8.0
func GetRegionalClusterClient(ctx context.Context, managementClient client.Client, namespace, regionalCDName string, scheme *runtime.Scheme) (client.Client, error)
GetRegionalClusterClient builds a controller-runtime client for a regional cluster. It fetches the regional cluster's kubeconfig secret from the management cluster and creates a client that can talk to the regional cluster's API server.
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.