utils

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// SandboxFinalizer is sandbox finalizer
	SandboxFinalizer = "agents.kruise.io/sandbox"
	// PodAnnotationCreatedBy is used to identify Pod source: created by Sandbox controller or externally created (bypassing Sandbox syntax sugar)
	PodAnnotationCreatedBy = "agents.kruise.io/created-by"
	// PodLabelCreatedBy is a label mirroring PodAnnotationCreatedBy, used as a label selector
	// for informer filtering so that only agent-related pods are cached.
	PodLabelCreatedBy = "agents.kruise.io/created-by"

	// default sandbox deploy namespace
	DefaultSandboxDeployNamespace = "sandbox-system"

	PodConditionContainersPaused  = "ContainersPaused"
	PodConditionContainersResumed = "ContainersResumed"
)
View Source
const (
	True  = "true"
	False = "false"

	CreatedByExternal = "external"
	CreatedBySandbox  = "sandbox"
)

Variables

View Source
var (
	// MaxConditionMessageLen is the max length for a Condition.Message.
	// Configurable via MAX_CONDITION_MESSAGE_LEN env var, defaults to 1024.
	MaxConditionMessageLen = getEnvIntOrDefault("MAX_CONDITION_MESSAGE_LEN", 1024)

	CacheBackoff = wait.Backoff{
		Duration: 100 * time.Millisecond,
		Factor:   2.0,
		Steps:    10,
		Jitter:   1.1,
	}
)

Functions

func DecodeBase64Proto added in v0.1.0

func DecodeBase64Proto[T proto.Message](raw string, into T) error

func DoItSlowly

func DoItSlowly(count int, initialBatchSize int, fn func() error) (int, error)

DoItSlowly tries to call the provided function a total of 'count' times, starting slow to check for errors, then speeding up if calls succeed.

It groups the calls into batches, starting with a group of initialBatchSize. Within each batch, it may call the function multiple times concurrently.

If a whole batch succeeds, the next batch may get exponentially larger. If there are any failures in a batch, all remaining batches are skipped after waiting for the current batch to complete.

It returns the number of successful calls to the function.

func DoItSlowlyWithInputs

func DoItSlowlyWithInputs[T any](inputs []T, initialBatchSize int, fn func(T) error) (int, error)

func DumpJson

func DumpJson(o interface{}) string

func EncodeBase64Proto added in v0.1.0

func EncodeBase64Proto[T proto.Message](data T) (string, error)

func GenerateSandboxName added in v0.3.0

func GenerateSandboxName(baseName string) string

GenerateSandboxName generates a K8s generateName prefix for sandbox objects. When SandboxMultiClusterNaming feature gate is enabled and CLUSTER_ID env is set, the cluster ID hash is embedded in the prefix to prevent cross-cluster naming conflicts. The returned prefix always ends with "-" and is truncated to 58 characters max.

func GetClusterIDHash added in v0.3.0

func GetClusterIDHash() string

GetClusterIDHash returns a 4-character hex hash of the CLUSTER_ID environment variable. Returns empty string if CLUSTER_ID is not set.

func GetControllerKey added in v0.1.0

func GetControllerKey(obj client.Object) string

func GetFirstNonLoopbackIP added in v0.2.0

func GetFirstNonLoopbackIP() string

func GetFromInformerOrApiServer added in v0.3.0

func GetFromInformerOrApiServer[T client.Object](ctx context.Context, target T, key client.ObjectKey,
	client client.Client, apiReader client.Reader) error

func GetPodCondition

func GetPodCondition(status *corev1.PodStatus, condType corev1.PodConditionType) *corev1.PodCondition

func GetSandboxCondition

func GetSandboxCondition(status *agentsv1alpha1.SandboxStatus, condType string) *metav1.Condition

func GetSandboxControllerUsername added in v0.2.0

func GetSandboxControllerUsername() string

func GetTemplateFromSandbox added in v0.3.0

func GetTemplateFromSandbox(sbx metav1.Object) string

func HashData added in v0.1.0

func HashData(by []byte) string

func IsLoopbackIP added in v0.2.0

func IsLoopbackIP(ip string) bool

func PatchFinalizer

func PatchFinalizer(ctx context.Context, c client.Client, object client.Object, op FinalizerOpType, finalizer string) (client.Object, error)

func RemoveSandboxCondition

func RemoveSandboxCondition(status *agentsv1alpha1.SandboxStatus, condType string)

func RetryIfContextNotCanceled added in v0.2.0

func RetryIfContextNotCanceled(ctx context.Context) func(err error) bool

func SetSandboxCondition

func SetSandboxCondition(status *agentsv1alpha1.SandboxStatus, condition metav1.Condition)

func TruncateConditionMessage added in v0.3.0

func TruncateConditionMessage(msg string) string

func UpdateFinalizer

func UpdateFinalizer(c client.Client, object client.Object, op FinalizerOpType, finalizer string) error

UpdateFinalizer add/remove a finalizer from a object

Types

type FinalizerOpType

type FinalizerOpType string
const (
	AddFinalizerOpType    FinalizerOpType = "Add"
	RemoveFinalizerOpType FinalizerOpType = "Remove"
)

Directories

Path Synopsis
Package utils provides utility functions for parsing and handling Kubernetes resource quantities.
Package utils provides utility functions for parsing and handling Kubernetes resource quantities.

Jump to

Keyboard shortcuts

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