common

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package common provides shared utilities for infrastructure controllers.

Index

Constants

View Source
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"
)

Variables

This section is empty.

Functions

func DetermineAPIEndpoint

func DetermineAPIEndpoint(service *corev1.Service) (string, error)

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

func ExtractClusterNameFromDeploymentName(deploymentName, colonyName string) string

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 GetAPIServerPort

func GetAPIServerPort(service *corev1.Service) int32

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

func GetServiceExternalAddress(service *corev1.Service) (string, bool)

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

func ValidateControlPlanePorts(service *corev1.Service) error

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.

Jump to

Keyboard shortcuts

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