util

package
v1.10.6 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Copyright 2026.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2026.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2026.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2026.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2026.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

View Source
const (
	ComponentBootstrap     = "bootstrap"
	ComponentClusterConfig = "cluster-config"
	ComponentConfig        = "config"
	ComponentControlPlane  = "control-plane"
	ComponentEntrypoint    = "entrypoint"
	ComponentEtcd          = "etcd"
	ComponentIngress       = "ingress"
	ComponentJointoken     = "jointoken"
	ComponentKubeconfig    = "kubeconfig"
	ComponentMonitoring    = "monitoring"
	ComponentTunneling     = "tunneling"
)

Component label values for app.kubernetes.io/component (and legacy "component"). Use these constants so component names are defined in one place.

Variables

This section is empty.

Functions

func AddToExistingSans added in v1.5.4

func AddToExistingSans(existing []string, newSan []string) []string

AddToExistingSans merges original sans list with a new sans slice avoiding duplicated values.

func AnnotationsForK0smotronCluster added in v1.4.0

func AnnotationsForK0smotronCluster(kmc *km.Cluster) map[string]string

AnnotationsForK0smotronCluster returns annotations for K0smotron cluster resources, including user-defined annotations from the cluster spec.

func DefaultK0smotronClusterLabels added in v1.4.0

func DefaultK0smotronClusterLabels(kmc *km.Cluster) map[string]string

DefaultK0smotronClusterLabels returns the default labels (app, cluster).

func DownloadCommands added in v1.5.4

func DownloadCommands(preInstalledK0s bool, downloadURL string, version string, k0sInstallPath string) ([]string, error)

DownloadCommands constructs the download commands for a given URL and version.

func EnsureExternalOwner added in v1.7.0

func EnsureExternalOwner(ctx context.Context, name, namespace string, c client.Client) (client.Object, error)

EnsureExternalOwner ensures that an external owner resource with the given name exists in the specified namespace. An external owner resource is used as owner reference for objects that are not in the management cluster. That way we can garbage collect all objects related to a k0smotron cluster deployed in an external cluster by deleting the external owner.

func EnsureFinalizer added in v1.5.4

func EnsureFinalizer(ctx context.Context, c client.Client, o client.Object, finalizer string) (finalizerAdded bool, err error)

EnsureFinalizer adds a finalizer if the object doesn't have a deletionTimestamp set and if the finalizer is not already set. This util is usually used in reconcilers directly after the reconciled object was retrieved and before pause is handled or "defer patch" with the patch helper.

TODO: This function is copied from https://github.com/kubernetes-sigs/cluster-api/blob/v1.9.0/util/finalizers/finalizers.go. Use it once the CAPI dependency is bumped to >=v1.9.0.

func EnsureNamespaceExists added in v1.10.3

func EnsureNamespaceExists(ctx context.Context, c client.Client, namespace string) error

EnsureNamespaceExists ensures that a namespace exists in the remote cluster. It first checks if the namespace exists by calling Get. If the namespace is not found, it creates the namespace. If Get returns Forbidden, it returns an error as we cannot verify the namespace existence or create it.

func FindNodeAddress added in v0.7.0

func FindNodeAddress(ctx context.Context, client client.Client) (string, error)

FindNodeAddress returns a random node address preferring external address if one is found

func FindStatefulSetPod

func FindStatefulSetPod(ctx context.Context, clientSet *kubernetes.Clientset, statefulSet string, namespace string) (*v1.Pod, error)

FindStatefulSetPod returns a first running pod from a StatefulSet

func GetExternalControllerRef added in v1.7.0

func GetExternalControllerRef(externalOwner metav1.Object) *metav1.OwnerReference

GetExternalControllerRef returns the controller reference for the given external owner object.

func GetExternalOwner added in v1.7.0

func GetExternalOwner(ctx context.Context, name, namespace string, c client.Client) (client.Object, error)

GetExternalOwner retrieves the external owner used in the external cluster for the given name and namespace.

func GetKmcClientFromClusterKubeconfigSecret added in v1.7.0

func GetKmcClientFromClusterKubeconfigSecret(ctx context.Context, managementClusterClient client.Client, kubeconfigRef *kapi.KubeconfigRef) (client.Client, *kubernetes.Clientset, *rest.Config, error)

GetKmcClientFromClusterKubeconfigSecret retrieves a client for the K0smotron cluster using the kubeconfig stored in a secret.

func GetKubeClient added in v1.0.2

func GetKubeClient(ctx context.Context, client client.Client, cluster *clusterv1.Cluster) (*kubernetes.Clientset, error)

GetKubeClient returns a Kubernetes clientset for the given cluster.

func LabelsForEtcdK0smotronCluster added in v1.4.0

func LabelsForEtcdK0smotronCluster(kmc *km.Cluster) map[string]string

LabelsForEtcdK0smotronCluster returns labels for K0smotron etcd resources (selector-safe, same as main).

func LabelsForK0smotronCluster added in v1.4.0

func LabelsForK0smotronCluster(kmc *km.Cluster) map[string]string

LabelsForK0smotronCluster returns base labels (app, cluster, user labels) with legacy component=cluster. Use when building custom label sets or for immutable selectors (StatefulSet, Deployment). For component-specific metadata (ConfigMap, Secret, etc.), use LabelsForK0smotronComponent.

func LabelsForK0smotronComponent added in v1.10.3

func LabelsForK0smotronComponent(kmc *km.Cluster, component string) map[string]string

LabelsForK0smotronComponent adds app.kubernetes.io/component to base labels. The legacy "component" label value from LabelsForK0smotronCluster is preserved. Do not use for immutable selectors (StatefulSet, Deployment); use LabelsForK0smotronControlPlane or LabelsForEtcdK0smotronCluster for those.

func LabelsForK0smotronControlPlane added in v1.4.0

func LabelsForK0smotronControlPlane(kmc *km.Cluster) map[string]string

LabelsForK0smotronControlPlane returns labels for K0smotron control plane resources (selector-safe, same as main).

func SetExternalOwnerReference added in v1.7.0

func SetExternalOwnerReference(owner metav1.Object, controlled metav1.Object, scheme *runtime.Scheme, externalOwner metav1.Object) error

SetExternalOwnerReference sets the owner reference for the given object trying to use the external owner if provided.

Types

This section is empty.

Jump to

Keyboard shortcuts

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