cluster-api: sigs.k8s.io/cluster-api/util Index | Files | Directories

package util

import "sigs.k8s.io/cluster-api/util"

Index

Package Files

retry.go util.go

Constants

const (
    // CharSet defines the alphanumeric set for random string generation
    CharSet = "0123456789abcdefghijklmnopqrstuvwxyz"
    // MachineListFormatDeprecationMessage notifies the user that the old
    // MachineList format is no longer supported
    MachineListFormatDeprecationMessage = "Your MachineList items must include Kind and APIVersion"
)

Variables

var (
    ErrNoCluster                 = fmt.Errorf("no %q label present", clusterv1.ClusterLabelName)
    ErrUnstructuredFieldNotFound = fmt.Errorf("field not found")
)
var (
    // IsPaused returns true if the Cluster is paused or the object has the `paused` annotation.
    // Deprecated: use util/annotations/IsPaused instead
    IsPaused = annotations.IsPaused

    // HasPausedAnnotation returns true if the object has the `paused` annotation.
    // Deprecated: use util/annotations/HasPausedAnnotation instead
    HasPausedAnnotation = annotations.HasPausedAnnotation
)

func ClusterToInfrastructureMapFunc Uses

func ClusterToInfrastructureMapFunc(gvk schema.GroupVersionKind) handler.ToRequestsFunc

ClusterToInfrastructureMapFunc returns a handler.ToRequestsFunc that watches for Cluster events and returns reconciliation requests for an infrastructure provider object.

func ClusterToObjectsMapper Uses

func ClusterToObjectsMapper(c client.Client, ro runtime.Object, scheme *runtime.Scheme) (handler.Mapper, error)

ClusterToObjectsMapper returns a mapper function that gets a cluster and lists all objects for the object passed in and returns a list of requests. NB: The objects are required to have `clusterv1.ClusterLabelName` applied.

func EnsureOwnerRef Uses

func EnsureOwnerRef(ownerReferences []metav1.OwnerReference, ref metav1.OwnerReference) []metav1.OwnerReference

EnsureOwnerRef makes sure the slice contains the OwnerReference.

func GetCRDWithContract Uses

func GetCRDWithContract(ctx context.Context, c client.Client, gvk schema.GroupVersionKind, contract string) (*apiextensionsv1.CustomResourceDefinition, error)

GetCRDWithContract retrieves a list of CustomResourceDefinitions from using controller-runtime Client, filtering with the `contract` label passed in. Returns the first CRD in the list that matches the GroupVersionKind, otherwise returns an error.

func GetClusterByName Uses

func GetClusterByName(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Cluster, error)

GetClusterByName finds and return a Cluster object using the specified params.

func GetClusterFromMetadata Uses

func GetClusterFromMetadata(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.Cluster, error)

GetClusterFromMetadata returns the Cluster object (if present) using the object metadata.

func GetControlPlaneMachines Uses

func GetControlPlaneMachines(machines []*clusterv1.Machine) (res []*clusterv1.Machine)

GetControlPlaneMachines returns a slice containing control plane machines.

func GetControlPlaneMachinesFromList Uses

func GetControlPlaneMachinesFromList(machineList *clusterv1.MachineList) (res []*clusterv1.Machine)

GetControlPlaneMachinesFromList returns a slice containing control plane machines.

func GetMachineByName Uses

func GetMachineByName(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Machine, error)

GetMachineByName finds and return a Machine object using the specified params.

func GetMachineIfExists Uses

func GetMachineIfExists(c client.Client, namespace, name string) (*clusterv1.Machine, error)

GetMachineIfExists gets a machine from the API server if it exists.

func GetMachinesForCluster Uses

func GetMachinesForCluster(ctx context.Context, c client.Client, cluster *clusterv1.Cluster) (*clusterv1.MachineList, error)

GetMachinesForCluster returns a list of machines associated with the cluster.

func GetOwnerCluster Uses

func GetOwnerCluster(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.Cluster, error)

GetOwnerCluster returns the Cluster object owning the current resource.

func GetOwnerMachine Uses

func GetOwnerMachine(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.Machine, error)

GetOwnerMachine returns the Machine object owning the current resource.

func HasOwner Uses

func HasOwner(refList []metav1.OwnerReference, apiVersion string, kinds []string) bool

HasOwner checks if any of the references in the passed list match the given apiVersion and one of the given kinds

func HasOwnerRef Uses

func HasOwnerRef(ownerReferences []metav1.OwnerReference, ref metav1.OwnerReference) bool

HasOwnerRef returns true if the OwnerReference is already in the slice.

func ImageTagIsValid Uses

func ImageTagIsValid(tagName string) bool

ImageTagIsValid ensures that a given image tag is compliant with the OCI spec Deprecated: Please use the functions in util/container

func IsControlPlaneMachine Uses

func IsControlPlaneMachine(machine *clusterv1.Machine) bool

IsControlPlaneMachine checks machine is a control plane node.

func IsControlledBy Uses

func IsControlledBy(obj metav1.Object, owner controllerutil.Object) bool

IsControlledBy differs from metav1.IsControlledBy in that it checks the group (but not version), kind, and name vs uid.

func IsNodeReady Uses

func IsNodeReady(node *v1.Node) bool

IsNodeReady returns true if a node is ready.

func IsOwnedByObject Uses

func IsOwnedByObject(obj metav1.Object, target controllerutil.Object) bool

IsOwnedByObject returns true if any of the owner references point to the given target.

func IsSupportedVersionSkew Uses

func IsSupportedVersionSkew(a, b semver.Version) bool

IsSupportedVersionSkew will return true if a and b are no more than one minor version off from each other.

func MachineToInfrastructureMapFunc Uses

func MachineToInfrastructureMapFunc(gvk schema.GroupVersionKind) handler.ToRequestsFunc

MachineToInfrastructureMapFunc returns a handler.ToRequestsFunc that watches for Machine events and returns reconciliation requests for an infrastructure provider object.

func ManagerDelegatingClientFunc Uses

func ManagerDelegatingClientFunc(cache cache.Cache, config *rest.Config, options client.Options) (client.Client, error)

NewDelegatingClientFunc returns a manager.NewClientFunc to be used when creating a new controller runtime manager.

A delegating client reads from the cache and writes directly to the server. This avoids getting unstructured objects directly from the server

See issue: https://github.com/kubernetes-sigs/cluster-api/issues/1663

func ModifyImageRepository Uses

func ModifyImageRepository(imageName, repositoryName string) (string, error)

ModifyImageRepository takes an imageName (e.g., repository/image:tag), and returns an image name with updated repository Deprecated: Please use the functions in util/container

func ModifyImageTag Uses

func ModifyImageTag(imageName, tagName string) (string, error)

ModifyImageTag takes an imageName (e.g., repository/image:tag), and returns an image name with updated tag Deprecated: Please use the functions in util/container

func ObjectKey Uses

func ObjectKey(object metav1.Object) client.ObjectKey

ObjectKey returns client.ObjectKey for the object.

func ObjectReferenceToUnstructured Uses

func ObjectReferenceToUnstructured(in corev1.ObjectReference) *unstructured.Unstructured

ObjectReferenceToUnstructured converts an object reference to an unstructured object.

func Ordinalize Uses

func Ordinalize(n int) string

Ordinalize takes an int and returns the ordinalized version of it. Eg. 1 --> 1st, 103 --> 103rd

func ParseMajorMinorPatch Uses

func ParseMajorMinorPatch(version string) (semver.Version, error)

ParseMajorMinorPatch returns a semver.Version from the string provided by looking only at major.minor.patch and stripping everything else out.

func PointsTo Uses

func PointsTo(refs []metav1.OwnerReference, target *metav1.ObjectMeta) bool

PointsTo returns true if any of the owner references point to the given target Deprecated: Use IsOwnedByObject to cover differences in API version or backup/restore that changed UIDs.

func Poll Uses

func Poll(interval, timeout time.Duration, condition wait.ConditionFunc) error

func PollImmediate Uses

func PollImmediate(interval, timeout time.Duration, condition wait.ConditionFunc) error

func RandomString Uses

func RandomString(n int) string

RandomString returns a random alphanumeric string.

func RemoveOwnerRef Uses

func RemoveOwnerRef(ownerReferences []metav1.OwnerReference, inputRef metav1.OwnerReference) []metav1.OwnerReference

RemoveOwnerRef returns the slice of owner references after removing the supplied owner ref

func ReplaceOwnerRef Uses

func ReplaceOwnerRef(ownerReferences []metav1.OwnerReference, source metav1.Object, target metav1.OwnerReference) []metav1.OwnerReference

ReplaceOwnerRef re-parents an object from one OwnerReference to another It compares strictly based on UID to avoid reparenting across an intentional deletion: if an object is deleted and re-created with the same name and namespace, the only way to tell there was an in-progress deletion is by comparing the UIDs.

func Retry Uses

func Retry(fn wait.ConditionFunc, initialBackoffSec int) error

func SemverToOCIImageTag Uses

func SemverToOCIImageTag(version string) string

SemverToOCIImageTag is a helper function that replaces all non-allowed symbols in tag strings with underscores. Image tag can only contain lowercase and uppercase letters, digits, underscores, periods and dashes. Current usage is for CI images where all of symbols except '+' are valid, but function is for generic usage where input can't be always pre-validated. Taken from k8s.io/cmd/kubeadm/app/util Deprecated: Please use the functions in util/container

func UnstructuredUnmarshalField Uses

func UnstructuredUnmarshalField(obj *unstructured.Unstructured, v interface{}, fields ...string) error

UnstructuredUnmarshalField is a wrapper around json and unstructured objects to decode and copy a specific field value into an object.

func WatchOnClusterPaused Uses

func WatchOnClusterPaused(c controller.Controller, mapFunc handler.Mapper) error

WatchOnClusterPaused adds a conditional watch to the controlled given as input that sends watch notifications on any create or delete, and only updates that toggle Cluster.Spec.Cluster. Deprecated: Instead add the Watch directly and use predicates.ClusterUnpaused or predicates.ClusterUnpausedAndInfrastructureReady depending on your use case.

type KubeAwareAPIVersions Uses

type KubeAwareAPIVersions []string

KubeAwareAPIVersions is a sortable slice of kube-like version strings.

Kube-like version strings are starting with a v, followed by a major version, optional "alpha" or "beta" strings followed by a minor version (e.g. v1, v2beta1). Versions will be sorted based on GA/alpha/beta first and then major and minor versions. e.g. v2, v1, v1beta2, v1beta1, v1alpha1.

func (KubeAwareAPIVersions) Len Uses

func (k KubeAwareAPIVersions) Len() int

func (KubeAwareAPIVersions) Less Uses

func (k KubeAwareAPIVersions) Less(i, j int) bool

func (KubeAwareAPIVersions) Swap Uses

func (k KubeAwareAPIVersions) Swap(i, j int)

type MachinesByCreationTimestamp Uses

type MachinesByCreationTimestamp []*clusterv1.Machine

MachinesByCreationTimestamp sorts a list of Machine by creation timestamp, using their names as a tie breaker.

func (MachinesByCreationTimestamp) Len Uses

func (o MachinesByCreationTimestamp) Len() int

func (MachinesByCreationTimestamp) Less Uses

func (o MachinesByCreationTimestamp) Less(i, j int) bool

func (MachinesByCreationTimestamp) Swap Uses

func (o MachinesByCreationTimestamp) Swap(i, j int)

Directories

PathSynopsis
annotations
certs
conditions
container
conversion
kubeconfig
patch
predicates
record
resource
secret
yaml

Package util imports 35 packages (graph) and is imported by 42 packages. Updated 2020-07-28. Refresh now. Tools for package owners.