common

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 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"
)
View Source
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

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

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

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