core

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Overview

Package core implements core utilities.

Index

Constants

View Source
const (
	// CharSet defines the alphanumeric set for random string generation.
	CharSet = "0123456789abcdefghijklmnopqrstuvwxyz"
)

Variables

View Source
var (

	// ErrNoChain is returned when the cluster
	// label could not be found on the object passed in.
	ErrNoChain = fmt.Errorf("no %q label present", v1beta1.ChainNameLabel)

	// ErrUnstructuredFieldNotFound determines that a field
	// in an unstructured object could not be found.
	ErrUnstructuredFieldNotFound = fmt.Errorf("field not found")
)

Functions

func ChainToTypedObjectsMapper

func ChainToTypedObjectsMapper(c client.Client, ro client.ObjectList, scheme *runtime.Scheme) (handler.MapFunc, error)

ChainToTypedObjectsMapper 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 `v1beta1.ChainNameLabel` 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 GetChainByName

func GetChainByName(ctx context.Context, c client.Client, namespace, name string) (*v1beta1.Chain, error)

GetChainByName finds and return a Chain object using the specified params.

func GetChainFromMetadata

func GetChainFromMetadata(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*v1beta1.Chain, error)

GetChainFromMetadata returns the Chain object (if present) using the object metadata.

func GetGVKMetadata

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 GetMinerByName

func GetMinerByName(ctx context.Context, c client.Client, namespace, name string) (*v1beta1.Miner, error)

GetMinerByName finds and return a Miner object using the specified params.

func GetMinerIfExists

func GetMinerIfExists(ctx context.Context, c client.Client, namespace, name string) (*v1beta1.Miner, error)

GetMinerIfExists gets a miner from the API server if it exists.

func GetOwnerChain

func GetOwnerChain(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*v1beta1.Chain, error)

GetOwnerChain returns the Chain object owning the current resource.

func GetOwnerMiner

func GetOwnerMiner(ctx context.Context, c client.Client, obj metav1.ObjectMeta) (*v1beta1.Miner, error)

GetOwnerMiner returns the Miner 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 IsControlledBy

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

IsControlledBy differs from metav1.IsControlledBy. This function matches on Group, Kind and Name. The metav1.IsControlledBy function matches on UID only.

func IsExternalManagedControlPlane

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

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

func IsNodeReady(node *corev1.Node) bool

IsNodeReady returns true if a node is ready.

func IsOwnedByObject

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

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

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

func LowestNonZeroInt32(i, j int32) int32

LowestNonZeroInt32 returns the lowest non-zero value of the two provided values.

func LowestNonZeroResult

func LowestNonZeroResult(i, j ctrl.Result) ctrl.Result

LowestNonZeroResult compares two reconciliation results and returns the one with lowest requeue time.

func MergeMap

func MergeMap(maps ...map[string]string) map[string]string

MergeMap merges maps. NOTE: In case a key exists in multiple maps, the value of the first map is preserved.

func ObjectKey

func ObjectKey(object metav1.Object) client.ObjectKey

ObjectKey returns client.ObjectKey for the object.

func ObjectReferenceToUnstructured

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

ObjectReferenceToUnstructured converts an object reference to an unstructured object.

func Ordinalize

func Ordinalize(n int) string

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

func RandomString

func RandomString(n int) string

RandomString returns a random alphanumeric string.

func RemoveOwnerRef

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

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 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

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

func (k KubeAwareAPIVersions) Len() int

func (KubeAwareAPIVersions) Less

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

func (KubeAwareAPIVersions) Swap

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

Jump to

Keyboard shortcuts

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