util

package
v0.1.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package util holds small, reusable helpers shared by the controllers.

Index

Constants

View Source
const (
	LabelClusterName      = "cluster.x-k8s.io/cluster-name"
	LabelClusterNamespace = "cluster.x-k8s.io/cluster-namespace"
	LabelMachineName      = "cluster.x-k8s.io/machine-name"
	LabelMachineUID       = "cluster.x-k8s.io/machine-uid"
	LabelManagedBy        = "cluster.x-k8s.io/managed-by"
	LabelProviderManaged  = "cluster-api-provider-stackit/managed"
	LabelResourceRole     = "cluster-api-provider-stackit/resource-role"
	LabelE2E              = "cluster-api-provider-stackit/e2e"
	LabelTestID           = "cluster-api-provider-stackit/test-id"

	// ManagedByValue identifies resources managed by this provider.
	ManagedByValue       = "cluster-api-provider-stackit"
	ProviderManagedValue = "true"
	ResourceRoleBastion  = "bastion"
	ResourceRoleNodeSSH  = "node-ssh"
	E2EValue             = "true"
)

Label / tag keys applied to provider-managed cloud resources. They mirror the canonical CAPI labels so operators can identify resources by cluster and machine.

View Source
const (
	BootstrapReasonInvalid = "BootstrapDataInvalid"
)

Reasons returned to callers of ExtractBootstrapData. They map to condition reasons surfaced on StackitMachine.

Variables

View Source
var ErrBootstrapDataInvalid = errors.New("bootstrap data invalid: secret has no \"value\" or \"userData\" key")

ErrBootstrapDataInvalid is returned when the bootstrap Secret exists but does not contain one of the expected keys.

View Source
var ErrCredentialsInvalid = errors.New("credentials invalid")

ErrCredentialsInvalid is returned when the Secret is missing required keys or contains a conflicting project ID.

Functions

func BuildCloudClient

func BuildCloudClient(
	ctx context.Context,
	k8sClient client.Client,
	factory cloud.Factory,
	stackitCluster *infrav1.StackitCluster,
) (cloud.Client, error)

func CloudFailureResult

func CloudFailureResult(
	conditions *[]metav1.Condition,
	generation int64,
	reason string,
	err error,
	requeueAfter time.Duration,
	returnError bool,
	conditionTypes ...string,
) (ctrl.Result, error)

func ClusterTags

func ClusterTags(clusterName, clusterNamespace string, additionalLabels map[string]string) map[string]string

ClusterTags returns the canonical tags applied to cluster-wide cloud resources (e.g. the API server load balancer). additionalLabels is merged in last so the provider's own tags cannot be overwritten.

func CredentialFailureResult

func CredentialFailureResult(
	conditions *[]metav1.Condition,
	generation int64,
	err error,
	requeueAfter time.Duration,
	conditionTypes ...string,
) (ctrl.Result, error)

CredentialFailureResult records the failure and decides how to retry.

Invalid credentials need an operator to fix the Secret, so they requeue on a slow timer rather than returning an error and spinning through the controller backoff. The reconcile reads the Secret again, which is what picks up the fix.

func CredentialsSecretKey

func CredentialsSecretKey(stackitCluster *infrav1.StackitCluster) types.NamespacedName

func ExtractBootstrapData

func ExtractBootstrapData(secret *corev1.Secret) ([]byte, error)

ExtractBootstrapData returns the bootstrap payload from a Secret produced by CABPK/KubeadmConfig. Per spec section 13.2 it checks "value" first, then "userData". It returns ErrBootstrapDataInvalid when neither key is present or both are empty.

func MachineTags

func MachineTags(
	clusterName, clusterNamespace, machineName, machineUID string,
	additionalLabels map[string]string,
) map[string]string

MachineTags returns the canonical tags applied to per-machine cloud resources (e.g. VMs). additionalLabels is merged in last so the provider's own tags cannot be overwritten.

func ParseCredentialsSecret

func ParseCredentialsSecret(secret *corev1.Secret, specProjectID, region string) (cloud.Credentials, error)

ParseCredentialsSecret extracts STACKIT credentials from a Secret.

If specProjectID is non-empty it must match the project-id stored in the Secret (if any); otherwise the function returns ErrCredentialsInvalid.

If specProjectID is empty, the function falls back to the value from the Secret. region is taken straight from the spec; the Secret does not carry a region.

func ReconciliationPaused

func ReconciliationPaused(cluster *clusterv1.Cluster, obj client.Object) (bool, string)

func SetCondition

func SetCondition(
	conditions *[]metav1.Condition,
	condType string,
	status metav1.ConditionStatus,
	reason, message string,
	observedGeneration ...int64,
)

SetCondition adds or updates a condition on conditions.

The LastTransitionTime is only refreshed when the status actually changes, so callers can call this unconditionally on every reconcile.

func SetConditions

func SetConditions(
	conditions *[]metav1.Condition,
	generation int64,
	status metav1.ConditionStatus,
	reason, message string,
	conditionTypes ...string,
)

func SetPausedCondition

func SetPausedCondition(conditions *[]metav1.Condition, generation int64, paused bool, message string)

Types

This section is empty.

Jump to

Keyboard shortcuts

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