Documentation
¶
Overview ¶
Package util holds small, reusable helpers shared by the controllers.
Index ¶
- Constants
- Variables
- func BuildCloudClient(ctx context.Context, k8sClient client.Client, factory cloud.Factory, ...) (cloud.Client, error)
- func CloudFailureResult(conditions *[]metav1.Condition, generation int64, reason string, err error, ...) (ctrl.Result, error)
- func ClusterTags(clusterName, clusterNamespace string, additionalLabels map[string]string) map[string]string
- func CredentialFailureResult(conditions *[]metav1.Condition, generation int64, err error, ...) (ctrl.Result, error)
- func CredentialsSecretKey(stackitCluster *infrav1.StackitCluster) types.NamespacedName
- func ExtractBootstrapData(secret *corev1.Secret) ([]byte, error)
- func MachineTags(clusterName, clusterNamespace, machineName, machineUID string, ...) map[string]string
- func ParseCredentialsSecret(secret *corev1.Secret, specProjectID, region string) (cloud.Credentials, error)
- func ReconciliationPaused(cluster *clusterv1.Cluster, obj client.Object) (bool, string)
- func SetCondition(conditions *[]metav1.Condition, condType string, status metav1.ConditionStatus, ...)
- func SetConditions(conditions *[]metav1.Condition, generation int64, ...)
- func SetPausedCondition(conditions *[]metav1.Condition, generation int64, paused bool, message string)
Constants ¶
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.
const (
BootstrapReasonInvalid = "BootstrapDataInvalid"
)
Reasons returned to callers of ExtractBootstrapData. They map to condition reasons surfaced on StackitMachine.
Variables ¶
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.
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 CloudFailureResult ¶
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 ¶
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 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 ¶
Types ¶
This section is empty.