utils

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPodCliqueNameFromPodCliqueFQN

func GetPodCliqueNameFromPodCliqueFQN(pclqObjectMeta metav1.ObjectMeta) (string, error)

GetPodCliqueNameFromPodCliqueFQN get unqualified PodClique name from FQN.

func GetPodCliqueSetReplicaIndexFromPodCliqueFQN

func GetPodCliqueSetReplicaIndexFromPodCliqueFQN(pcsName, pclqFQNName string) (int, error)

GetPodCliqueSetReplicaIndexFromPodCliqueFQN extracts the PodCliqueSet replica index from a Pod Clique FQN name.

func IsEmptyStringType

func IsEmptyStringType[T ~string](val T) bool

IsEmptyStringType returns true if value (which is a string or has an underline type string) is empty or contains only whitespace characters.

func OnlyOneIsNil

func OnlyOneIsNil[T any](objA, objB *T) bool

OnlyOneIsNil returns true if only one of the Objects is nil else it will return false.

Types

type RunResult

type RunResult struct {
	// SuccessfulTasks holds the names of taskConfigs that were executed successfully.
	SuccessfulTasks []string
	// FailedTasks holds the names of taskConfigs that failed during execution.
	FailedTasks []string
	// SkippedTasks holds the names of taskConfigs that were skipped (not executed).
	SkippedTasks []string
	// Errors holds the errors encountered during the execution of taskConfigs.
	Errors []error
}

RunResult is a structure that holds the results of running taskConfigs concurrently.

func RunConcurrently

func RunConcurrently(ctx context.Context, logger logr.Logger, tasks []Task) RunResult

RunConcurrently executes a slice of Tasks concurrently.

func RunConcurrentlyWithBounds

func RunConcurrentlyWithBounds(ctx context.Context, logger logr.Logger, tasks []Task, bound int) RunResult

RunConcurrentlyWithBounds executes a slice of Tasks with at most `bound` taskConfigs running concurrently.

func RunConcurrentlyWithSlowStart

func RunConcurrentlyWithSlowStart(ctx context.Context, logger logr.Logger, initialBatchSize int, tasks []Task) RunResult

RunConcurrentlyWithSlowStart executes a slice of Tasks by grouping them into batches that double in size each time, starting with `initialBatchSize`. If the whole batch succeeds, the next batch is doubled in size and executed. If there are any errors in the batch, then it fails fast and returns the errors immediately, thus halting the execution of further taskConfigs. kube-apiserver does not provide batching of requests, therefore if there are many resources for which calls are made to kube-apiserver, then this function prevents overwhelming the kube-apiserver with too many requests at once.

func (*RunResult) GetAggregatedError

func (r *RunResult) GetAggregatedError() error

GetAggregatedError aggregates all errors encountered during the execution of taskConfigs.

func (*RunResult) GetSummary

func (r *RunResult) GetSummary() string

GetSummary returns a summary of the RunResult, including the number of successful, failed, and skipped taskConfigs.

func (*RunResult) HasErrors

func (r *RunResult) HasErrors() bool

HasErrors checks if there are any taskConfigs that errored out during execution.

type Task

type Task struct {
	// Name is the name of the task, used for logging and result reporting.
	Name string
	// Fn is the function that will be executed.
	Fn func(ctx context.Context) error
}

Task is a named closure.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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