Documentation ¶
Overview ¶
Package util implements utilities.
Index ¶
- Constants
- Variables
- func ClusterToInfrastructureMapFunc(ctx context.Context, gvk schema.GroupVersionKind, c client.Client, ...) handler.MapFunc
- func ClusterToTypedObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error)
- func EnsureOwnerRef(ownerReferences []metav1.OwnerReference, ref metav1.OwnerReference) []metav1.OwnerReference
- func GetClusterByName(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Cluster, error)
- func GetClusterFromMetadata(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.Cluster, error)
- func GetGVKMetadata(ctx context.Context, c client.Client, gvk schema.GroupVersionKind) (*metav1.PartialObjectMetadata, error)
- func GetMachineByName(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Machine, error)
- func GetMachineIfExists(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Machine, error)
- func GetOwnerCluster(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.Cluster, error)
- func GetOwnerMachine(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*clusterv1.Machine, error)
- func HasOwner(refList []metav1.OwnerReference, apiVersion string, kinds []string) bool
- func HasOwnerRef(ownerReferences []metav1.OwnerReference, ref metav1.OwnerReference) bool
- func IsControlPlaneMachine(machine *clusterv1.Machine) bool
- func IsControlledBy(obj metav1.Object, owner client.Object) bool
- func IsExternalManagedControlPlane(controlPlane *unstructured.Unstructured) bool
- func IsNil(i interface{}) bool
- func IsNodeReady(node *corev1.Node) bool
- func IsOwnedByObject(obj metav1.Object, target client.Object) bool
- func IsSupportedVersionSkew(a, b semver.Version) bool
- func LowestNonZeroInt32(i, j int32) int32
- func LowestNonZeroResult(i, j ctrl.Result) ctrl.Result
- func MachineDeploymentToObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error)
- func MachineSetToObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error)
- func MachineToInfrastructureMapFunc(gvk schema.GroupVersionKind) handler.MapFunc
- func MergeMap(maps ...map[string]string) map[string]string
- func ObjectKey(object metav1.Object) client.ObjectKey
- func ObjectReferenceToUnstructured(in corev1.ObjectReference) *unstructured.Unstructured
- func Ordinalize(n int) string
- func RandomString(n int) string
- func RemoveOwnerRef(ownerReferences []metav1.OwnerReference, inputRef metav1.OwnerReference) []metav1.OwnerReference
- func ReplaceOwnerRef(ownerReferences []metav1.OwnerReference, source metav1.Object, ...) []metav1.OwnerReference
- func Retry(fn wait.ConditionFunc, initialBackoffSec int) error
- func UnstructuredUnmarshalField(obj *unstructured.Unstructured, v interface{}, fields ...string) error
- type KubeAwareAPIVersions
Constants ¶
const (
// CharSet defines the alphanumeric set for random string generation.
CharSet = "0123456789abcdefghijklmnopqrstuvwxyz"
)
Variables ¶
var ( // ErrNoCluster is returned when the cluster // label could not be found on the object passed in. ErrNoCluster = fmt.Errorf("no %q label present", clusterv1.ClusterNameLabel) // ErrUnstructuredFieldNotFound determines that a field // in an unstructured object could not be found. ErrUnstructuredFieldNotFound = fmt.Errorf("field not found") )
Functions ¶
func ClusterToInfrastructureMapFunc ¶
func ClusterToInfrastructureMapFunc(ctx context.Context, gvk schema.GroupVersionKind, c client.Client, providerCluster client.Object) handler.MapFunc
ClusterToInfrastructureMapFunc returns a handler.ToRequestsFunc that watches for Cluster events and returns reconciliation requests for an infrastructure provider object.
func ClusterToTypedObjectsMapper ¶ added in v1.5.0
func ClusterToTypedObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error)
ClusterToTypedObjectsMapper returns a mapper function that gets a cluster and lists all objects for the object passed in and returns a list of requests. Note: This function uses the passed in typed ObjectList and thus with the default client configuration all list calls will be cached. NB: The objects are required to have `clusterv1.ClusterNameLabel` applied.
func EnsureOwnerRef ¶
func EnsureOwnerRef(ownerReferences []metav1.OwnerReference, ref metav1.OwnerReference) []metav1.OwnerReference
EnsureOwnerRef makes sure the slice contains the OwnerReference. Note: EnsureOwnerRef will update the version of the OwnerReference fi it exists with a different version. It will also update the UID.
func GetClusterByName ¶
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 ¶
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 GetGVKMetadata ¶ added in v0.4.3
func GetGVKMetadata(ctx context.Context, c client.Client, gvk schema.GroupVersionKind) (*metav1.PartialObjectMetadata, error)
GetGVKMetadata retrieves a CustomResourceDefinition metadata from the API server using partial object metadata.
This function is greatly more efficient than GetCRDWithContract and should be preferred in most cases.
func GetMachineByName ¶
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 ¶
func GetMachineIfExists(ctx context.Context, c client.Client, namespace, name string) (*clusterv1.Machine, error)
GetMachineIfExists gets a machine from the API server if it exists.
func GetOwnerCluster ¶
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 ¶
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 ¶
func HasOwner(refList []metav1.OwnerReference, apiVersion string, kinds []string) bool
HasOwner checks if any of the references in the passed list match the given group from apiVersion and one of the given kinds.
func HasOwnerRef ¶
func HasOwnerRef(ownerReferences []metav1.OwnerReference, ref metav1.OwnerReference) bool
HasOwnerRef returns true if the OwnerReference is already in the slice. It matches based on Group, Kind and Name.
func IsControlPlaneMachine ¶
IsControlPlaneMachine checks machine is a control plane node.
func IsControlledBy ¶ added in v0.3.7
IsControlledBy differs from metav1.IsControlledBy. This function matches on Group, Kind and Name. The metav1.IsControlledBy function matches on UID only.
func IsExternalManagedControlPlane ¶ added in v0.3.10
func IsExternalManagedControlPlane(controlPlane *unstructured.Unstructured) bool
IsExternalManagedControlPlane returns a bool indicating whether the control plane referenced in the passed Unstructured resource is an externally managed control plane such as AKS, EKS, GKE, etc.
func IsNil ¶ added in v1.2.0
func IsNil(i interface{}) bool
IsNil returns an error if the passed interface is equal to nil or if it has an interface value of nil.
func IsNodeReady ¶
IsNodeReady returns true if a node is ready.
func IsOwnedByObject ¶ added in v0.3.7
IsOwnedByObject returns true if any of the owner references point to the given target. It matches the object based on the Group, Kind and Name.
func IsSupportedVersionSkew ¶ added in v0.3.7
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 LowestNonZeroInt32 ¶ added in v1.4.0
LowestNonZeroInt32 returns the lowest non-zero value of the two provided values.
func LowestNonZeroResult ¶ added in v0.3.9
LowestNonZeroResult compares two reconciliation results and returns the one with lowest requeue time.
func MachineDeploymentToObjectsMapper ¶ added in v1.7.0
func MachineDeploymentToObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error)
MachineDeploymentToObjectsMapper returns a mapper function that gets a machinedeployment and lists all objects for the object passed in and returns a list of requests. NB: The objects are required to have `clusterv1.MachineDeploymentNameLabel` applied.
func MachineSetToObjectsMapper ¶ added in v1.7.0
func MachineSetToObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error)
MachineSetToObjectsMapper returns a mapper function that gets a machineset and lists all objects for the object passed in and returns a list of requests. NB: The objects are required to have `clusterv1.MachineSetNameLabel` applied.
func MachineToInfrastructureMapFunc ¶
func MachineToInfrastructureMapFunc(gvk schema.GroupVersionKind) handler.MapFunc
MachineToInfrastructureMapFunc returns a handler.ToRequestsFunc that watches for Machine events and returns reconciliation requests for an infrastructure provider object.
func MergeMap ¶ added in v1.5.0
MergeMap merges maps. NOTE: In case a key exists in multiple maps, the value of the first map is preserved.
func ObjectReferenceToUnstructured ¶ added in v0.3.7
func ObjectReferenceToUnstructured(in corev1.ObjectReference) *unstructured.Unstructured
ObjectReferenceToUnstructured converts an object reference to an unstructured object.
func Ordinalize ¶ added in v0.3.3
Ordinalize takes an int and returns the ordinalized version of it. Eg. 1 --> 1st, 103 --> 103rd.
func RandomString ¶
RandomString returns a random alphanumeric string.
func RemoveOwnerRef ¶ added in v0.3.7
func RemoveOwnerRef(ownerReferences []metav1.OwnerReference, inputRef metav1.OwnerReference) []metav1.OwnerReference
RemoveOwnerRef returns the slice of owner references after removing the supplied owner ref. Note: RemoveOwnerRef ignores apiVersion and UID. It will remove the passed ownerReference where it matches Name, Group and Kind.
func ReplaceOwnerRef ¶ added in v0.3.7
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 ¶
func Retry(fn wait.ConditionFunc, initialBackoffSec int) error
Retry retries a given function with exponential backoff.
func UnstructuredUnmarshalField ¶
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.
Types ¶
type KubeAwareAPIVersions ¶ added in v0.3.0
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 ¶ added in v0.3.0
func (k KubeAwareAPIVersions) Len() int
func (KubeAwareAPIVersions) Less ¶ added in v0.3.0
func (k KubeAwareAPIVersions) Less(i, j int) bool
func (KubeAwareAPIVersions) Swap ¶ added in v0.3.0
func (k KubeAwareAPIVersions) Swap(i, j int)
Directories ¶
Path | Synopsis |
---|---|
Package annotations implements annotation helper functions.
|
Package annotations implements annotation helper functions. |
Package certs implements cert handling utilities.
|
Package certs implements cert handling utilities. |
Package collections implements collection utilities.
|
Package collections implements collection utilities. |
Package conditions implements condition utilities.
|
Package conditions implements condition utilities. |
Package container implements container utility functionality.
|
Package container implements container utility functionality. |
Package contract contains utils related to the Cluster API contract.
|
Package contract contains utils related to the Cluster API contract. |
Package conversion implements conversion utilities.
|
Package conversion implements conversion utilities. |
Package defaulting implements defaulting webhook functionality.
|
Package defaulting implements defaulting webhook functionality. |
Package failuredomains implements FailureDomain utility functions.
|
Package failuredomains implements FailureDomain utility functions. |
Package flags implements the manager options utilities.
|
Package flags implements the manager options utilities. |
Package kubeconfig implements utilities for working with kubeconfigs.
|
Package kubeconfig implements utilities for working with kubeconfigs. |
Package labels implements label utility functions.
|
Package labels implements label utility functions. |
format
Package format contains functions to format and compare formatted values used in Kubernetes labels.
|
Package format contains functions to format and compare formatted values used in Kubernetes labels. |
Package log provides log utils.
|
Package log provides log utils. |
Package patch implements patch utilities.
|
Package patch implements patch utilities. |
Package predicates implements predicate utilities.
|
Package predicates implements predicate utilities. |
Package record implements recording functionality.
|
Package record implements recording functionality. |
Package resource implements resource utilites.
|
Package resource implements resource utilites. |
Package secret implements utilities for secret handling.
|
Package secret implements utilities for secret handling. |
Package topology implements topology utility functions.
|
Package topology implements topology utility functions. |
Package version implements version handling.
|
Package version implements version handling. |
Package yaml implements yaml utility functions.
|
Package yaml implements yaml utility functions. |