utils

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeleteTagAnnotation = "kuadrant.io/delete"
	ClusterIDLength     = 6
)

Variables

This section is empty.

Functions

func Filter

func Filter[T any](slice []T, f func(T) bool) []T

Filter filters the input slice using the given predicate function and returns a new slice with the results.

func Find

func Find[T any](slice []T, match func(T) bool) (*T, bool)

func FindDeploymentStatusCondition

func FindDeploymentStatusCondition(conditions []appsv1.DeploymentCondition, conditionType string) *appsv1.DeploymentCondition

func FindObjectKey

func FindObjectKey(a []client.ObjectKey, x client.ObjectKey) int

FindObjectKey returns the smallest index i at which x == a[i], or len(a) if there is no such index.

func GetClusterUID

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

func GetEmptySliceIfNil

func GetEmptySliceIfNil[T any](val []T) []T

GetEmptySliceIfNil returns a provided slice, or an empty slice of the same type if the input slice is nil.

func GetLabel

func GetLabel(obj metav1.Object, key string) string

func GetService

func GetService(ctx context.Context, k8sClient client.Client, serviceKey client.ObjectKey) (*corev1.Service, error)

func GetServicePortNumber

func GetServicePortNumber(ctx context.Context, k8sClient client.Client, serviceKey client.ObjectKey, servicePort string) (int32, error)

GetServicePortNumber returns the port number from the referenced key and port info the port info can be named port or already a number.

func GetServiceWorkloadSelector

func GetServiceWorkloadSelector(ctx context.Context, k8sClient client.Client, serviceKey client.ObjectKey) (map[string]string, error)

func HasLabel

func HasLabel(obj metav1.Object, key string) bool

func HostnamesToStrings

func HostnamesToStrings(hostnames []gatewayapiv1.Hostname) []string

HostnamesToStrings converts []gatewayapiv1.Hostname to []string

func Index

func Index[T any](slice []T, match func(T) bool) int

func Intersect

func Intersect[T comparable](slice1, slice2 []T) bool

func Intersection

func Intersection[T comparable](slice1, slice2 []T) []T

func IsObjectTaggedToDelete

func IsObjectTaggedToDelete(obj client.Object) bool

IsObjectTaggedToDelete checks if the given object is tagged for deletion. It looks for the DeleteTagAnnotation in the object's annotations and returns true if the annotation value is set to "true", false otherwise.

func IsOwnedBy

func IsOwnedBy(owned, owner client.Object) bool

IsOwnedBy checks if the provided owned object is owned by the given owner object. Ownership is determined based on matching the owner reference's group, kind, and name. The version of the owner reference is not checked in this implementation. Returns true if the owned object is owned by the owner object, false otherwise.

func Map

func Map[T, U any](slice []T, f func(T) U) []U

Map applies the given mapper function to each element in the input slice and returns a new slice with the results.

func NamespacedNameToObjectKey

func NamespacedNameToObjectKey(namespacedName, defaultNamespace string) client.ObjectKey

NamespacedNameToObjectKey converts <namespace/name> format string to k8s object key. It's common for K8s to reference an object using this format. For e.g. gateways in VirtualService.

func ObjectInfo

func ObjectInfo(obj client.Object) string

ObjectInfo generates a string representation of the provided Kubernetes object, including its kind and name. The generated string follows the format: "kind/name".

func ObjectKeyListDifference

func ObjectKeyListDifference(a, b []client.ObjectKey) []client.ObjectKey

ObjectKeyListDifference computest a - b

func ReadAnnotationsFromObject

func ReadAnnotationsFromObject(obj client.Object) map[string]string

ReadAnnotationsFromObject reads the annotations from a Kubernetes object and returns them as a map. If the object has no annotations, it returns an empty map.

func SameElements

func SameElements[T comparable](s1, s2 []T) bool

SameElements checks if the two slices contain the exact same elements. Order does not matter.

func StatusConditionsMarshalJSON

func StatusConditionsMarshalJSON(input []metav1.Condition) ([]byte, error)

StatusConditionsMarshalJSON marshals the list of conditions as a JSON array, sorted by condition type.

func TagObjectToDelete

func TagObjectToDelete(obj client.Object)

TagObjectToDelete adds a special DeleteTagAnnotation to the object's annotations. If the object's annotations are nil, it first initializes the Annotations field with an empty map.

func ValidSubdomains

func ValidSubdomains(domains, subdomains []string) (bool, string)

ValidSubdomains returns (true, "") when every single subdomains item is a subset of at least one of the domains. Domains and subdomains may be prefixed with a wildcard label (*.). The wildcard label must appear by itself as the first label. When one of the subdomains is not a subset of the domains, it returns false and the subdomain not being subset of the domains

Types

type Name

type Name string

Name describes a (possibly wildcarded) hostname

func (Name) IsWildCarded

func (n Name) IsWildCarded() bool

func (Name) String

func (n Name) String() string

func (Name) SubsetOf

func (n Name) SubsetOf(o Name) bool

SubsetOf returns true if this hostname is a valid subset of the other hostname. The semantics are the same as "Matches", but only in one direction (i.e., h is covered by o).

Jump to

Keyboard shortcuts

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