utils

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeSHA256Hex added in v0.28.0

func ComputeSHA256Hex(in []byte) string

ComputeSHA256Hex computes the hexadecimal representation of the SHA256 hash of the given input byte slice <in>, converts it to a string and returns it.

func ComputeScheduleInterval added in v0.24.0

func ComputeScheduleInterval(cronSchedule string) (time.Duration, error)

ComputeScheduleInterval computes the interval between two activations for the given cron schedule. Assumes that every cron activation is at equal intervals apart, based on cron schedules such as "once every X hours", "once every Y days", "at 1:00pm on every Tuesday", etc. TODO: write a new function to accurately compute the previous activation time from the cron schedule in order to compute when the previous activation of the cron schedule was supposed to have occurred, instead of relying on the assumption that all the cron activations are evenly spaced.

func GetBackupRestoreContainerEnvVars

func GetBackupRestoreContainerEnvVars(store *druidv1alpha1.StoreSpec) ([]corev1.EnvVar, error)

GetBackupRestoreContainerEnvVars returns non-provider-specific environment variables for the backup-restore container.

func GetEnvVarFromSecret

func GetEnvVarFromSecret(name, secretName, secretKey string, optional bool) corev1.EnvVar

GetEnvVarFromSecret returns environment variable object with provided name and optional value from secret

func GetEnvVarFromValue

func GetEnvVarFromValue(name, value string) corev1.EnvVar

GetEnvVarFromValue returns environment variable object with the provided name and value

func GetEtcdBackupRestoreImage

func GetEtcdBackupRestoreImage(iv imagevector.ImageVector) (*string, error)

GetEtcdBackupRestoreImage returns the image for backup-restore from the given image vector.

func GetEtcdImages

func GetEtcdImages(etcd *druidv1alpha1.Etcd, iv imagevector.ImageVector) (string, string, string, error)

GetEtcdImages returns images for etcd and backup-restore by inspecting the etcd spec and the image vector and returns the image for the init container by inspecting the image vector. It will give preference to images that are set in the etcd spec and only if the image is not found in it should it be picked up from the image vector if it's set there. A return value of nil for either of the images indicates that the image is not set.

func GetInitContainerImage

func GetInitContainerImage(iv imagevector.ImageVector) (*string, error)

GetInitContainerImage returns the image for init container from the given image vector.

func IfConditionOr

func IfConditionOr[T any](condition bool, trueVal, falseVal T) T

IfConditionOr implements a simple ternary operator, if the passed condition is true then trueVal is returned else falseVal is returned.

func IsEmptyString

func IsEmptyString(s string) bool

IsEmptyString returns true if the string is empty or contains only whitespace characters.

func Key

func Key(namespaceOrName string, nameOpt ...string) client.ObjectKey

Key creates a new client.ObjectKey from the given parameters. There are only two ways to call this function:

  • If only namespaceOrName is set, then a client.ObjectKey with name set to namespaceOrName is returned.
  • If namespaceOrName and one nameOpt is given, then a client.ObjectKey with namespace set to namespaceOrName and name set to nameOpt[0] is returned.

For all other cases, this method panics.

func MergeMaps

func MergeMaps[K comparable, V any](sourceMaps ...map[K]V) map[K]V

MergeMaps merges the contents of maps. All maps will be processed in the order in which they are sent. For overlapping keys across source maps, value in the merged map for this key will be from the last occurrence of the key-value.

func MustNewLogger

func MustNewLogger(devMode bool, level druidconfigv1alpha1.LogLevel, format druidconfigv1alpha1.LogFormat) logr.Logger

MustNewLogger is like NewLogger but panics on invalid input.

func NewLogger

func NewLogger(devMode bool, level druidconfigv1alpha1.LogLevel, format druidconfigv1alpha1.LogFormat) (logr.Logger, error)

NewLogger creates a new logr.Logger backed by Zap.

func RunConcurrently

func RunConcurrently(ctx component.OperatorContext, tasks []OperatorTask) []error

RunConcurrently runs tasks concurrently with number of goroutines bounded by bound. If there is a panic executing a single OperatorTask then it will capture the panic and capture it as an error which will then subsequently be returned from this function. It will not propagate the panic causing the app to exit.

Types

type OperatorTask

type OperatorTask struct {
	// Name is the name of the task
	Name string
	// Fn is the function which accepts a component operator context and returns an error if there is one.
	// Implementations of Fn should handle context cancellation properly.
	Fn func(ctx component.OperatorContext) error
}

OperatorTask is a holder for a named function.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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