utils

package
v0.0.0-...-d298aea Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package utils collects all the logic shared between different controllers

Package utils collects all the logic shared between different controllers

Package utils collects all the logic shared between different controllers

Index

Constants

View Source
const (
	// LogInfoLevel -> level associated with informational messages.
	LogInfoLevel = 0
	// LogDebugLevel -> level associated with debug messages.
	LogDebugLevel = 2
)

Variables

This section is empty.

Functions

func AutoEnrollEnabled

func AutoEnrollEnabled(autoEnroll clv1alpha1.WorkspaceAutoenroll) bool

AutoEnrollEnabled checks if the specified WorkspaceAutoenroll enables any feature.

func CheckLabels

func CheckLabels(ns *corev1.Namespace, matchLabels map[string]string) bool

CheckLabels verifies whether a namespace is characterized by a set of required labels.

func CheckSelectorLabel

func CheckSelectorLabel(ctx context.Context, k8sClient client.Client, namespaceName string, matchLabels map[string]string) (bool, error)

CheckSelectorLabel checks if the given namespace belongs to the whitelisted namespaces where to perform reconciliation.

func CheckSingleLabel

func CheckSingleLabel(obj client.Object, label, value string) bool

CheckSingleLabel checks if the instance has the label and value.

func Contains

func Contains(slice []string, value string) bool

Contains checks if the value is contained in the slice.

func EnforceObjectAbsence

func EnforceObjectAbsence(ctx context.Context, c client.Client, obj client.Object, kind string) error

EnforceObjectAbsence deletes a Kubernetes object and prints the appropriate log messages, without failing if it does not exist.

func FromResult

func FromResult(result controllerutil.OperationResult) int

FromResult returns a logger level, given the result of a CreateOrUpdate operation.

func HTTPGet

func HTTPGet(ctx context.Context, url string, timeout time.Duration) (statusCode int, contents []byte, err error)

HTTPGet performs a HTTP GET request to the given URL.

func HTTPGetJSONIntoStruct

func HTTPGetJSONIntoStruct(ctx context.Context, url string, obj interface{}, timeout time.Duration) (statusCode int, err error)

HTTPGetJSONIntoStruct performs a HTTP GET request to the given URL and unmarshals the response into the given struct.

func LogConstructor

func LogConstructor(logger logr.Logger, ctrlname string) func(*reconcile.Request) logr.Logger

LogConstructor returns a constructor for a logger to be used by the given controller.

func LongThreshold

func LongThreshold() time.Duration

LongThreshold returns the duration used to trigger tracing printing.

func MatchOneInStringSlices

func MatchOneInStringSlices(a, b []string) bool

MatchOneInStringSlices checks if there's at least one common string between two string slices.

func NFSDriveProvisioning

func NFSDriveProvisioning(ctx context.Context, log logr.Logger, c client.Client, pvc *v1.PersistentVolumeClaim, owner metav1.Object) (bool, error)

NFSDriveProvisioning enforces a job to provision the passed PVC, changing its owner and adding it a label when done.

func ParseDockerDirectory

func ParseDockerDirectory(name string) string

ParseDockerDirectory returns a valid Docker image directory.

func PatchObject

func PatchObject[T interface {
	client.Object
	DeepCopy() T
}](ctx context.Context, c client.Client, obj T, mutation func(T) T) error

PatchObject applies a patch to a Kubernetes object, allowing for modifications without overwriting the entire object.

Types

This section is empty.

Directories

Path Synopsis
Package args groups the methods used for utils args.
Package args groups the methods used for utils args.
Package restcfg contains utility functions to deal with rest configs.
Package restcfg contains utility functions to deal with rest configs.
Package tests contains utilities for tests.
Package tests contains utilities for tests.

Jump to

Keyboard shortcuts

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