utils

package
v0.3.8 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallWithRetry added in v0.3.0

func CallWithRetry(ctx context.Context, call func(retryTimes int) (shouldRetry bool, err error), retryRateLimiter func(retryTimes int) time.Duration) error

CallWithRetry attempts to call a function with retries based on a custom rate limiter.

func CheckAndFinallyCall added in v0.2.0

func CheckAndFinallyCall(ctx context.Context, checkFunc func(context.Context) (bool, error), timeout, interval time.Duration, finally, timeoutCall func()) error

CheckAndFinallyCall checks a condition at a specified interval until it's true or a timeout occurs.

func ConvertBizStatusToContainerStatus added in v0.3.4

func ConvertBizStatusToContainerStatus(container *corev1.Container, containerStatus *corev1.ContainerStatus, data *model.BizStatusData) (*corev1.ContainerStatus, error)

ConvertBizStatusToContainerStatus converts tunnel container status to Kubernetes container status, if not the status for the container, then create a empty state container status

func ConvertByteNumToResourceQuantity

func ConvertByteNumToResourceQuantity(byteNum int64) resource.Quantity

ConvertByteNumToResourceQuantity converts a byte number to a resource quantity.

func ConvertNodeToNodeInfo added in v0.3.6

func ConvertNodeToNodeInfo(node *corev1.Node) model.NodeInfo

func DefaultRateLimiter added in v0.3.0

func DefaultRateLimiter(retryTimes int) time.Duration

DefaultRateLimiter calculates the duration for retry based on the number of retries.

func ExtractNodeIDFromNodeName added in v0.2.0

func ExtractNodeIDFromNodeName(nodeName string) string

ExtractNodeIDFromNodeName extracts the node ID from a node name.

func FillPodKey added in v0.3.4

func FillPodKey(pods []corev1.Pod, bizStatusDatas []model.BizStatusData) (toUpdate []model.BizStatusData, toDelete []model.BizStatusData)

func FormatNodeName added in v0.2.0

func FormatNodeName(nodeID, env string) string

FormatNodeName constructs a node name based on node ID and environment.

func GetBizNameAndVersionFromUniqueKey added in v0.3.8

func GetBizNameAndVersionFromUniqueKey(bizUniqueKey string) (string, string)

GetBizNameAndVersionFromUniqueKey extracts the biz name and version from a unique key

func GetBizUniqueKey added in v0.3.4

func GetBizUniqueKey(container *corev1.Container) string

GetBizUniqueKey returns a unique key for the container

func GetContainerKey added in v0.2.0

func GetContainerKey(podKey, containerName string) string

GetContainerKey constructs a container key from a pod key and container name.

func GetContainerNameFromContainerKey added in v0.2.0

func GetContainerNameFromContainerKey(containerKey string) string

GetContainerNameFromContainerKey extracts the container name from a container key.

func GetEnv added in v0.2.0

func GetEnv(key, defaultValue string) string

GetEnv retrieves an environment variable or returns a default value if not set.

func GetNameSpaceAndNameFromPodKey added in v0.3.7

func GetNameSpaceAndNameFromPodKey(podKey string) (string, string)

func GetPodKey added in v0.2.0

func GetPodKey(pod *corev1.Pod) string

GetPodKey constructs a pod key from a pod object.

func GetPodKeyFromContainerKey added in v0.2.0

func GetPodKeyFromContainerKey(containerKey string) string

GetPodKeyFromContainerKey extracts the pod key from a container key.

func MergeNodeFromProvider added in v0.3.5

func MergeNodeFromProvider(node *corev1.Node, data model.NodeStatusData) *corev1.Node

MergeNodeFromProvider constructs a virtual node based on the latest node status data.

func PodsEqual

func PodsEqual(pod1, pod2 *corev1.Pod) bool

PodsEqual checks if two pods are equal based on specific fields that can be modified after startup.

func SplitMetaNamespaceKey added in v0.2.0

func SplitMetaNamespaceKey(key string) (namespace, name string, err error)

SplitMetaNamespaceKey splits a key into namespace and name.

func TimedTaskWithInterval

func TimedTaskWithInterval(ctx context.Context, interval time.Duration, task func(context.Context))

TimedTaskWithInterval runs a task at a specified interval until the context is cancelled.

Types

This section is empty.

Jump to

Keyboard shortcuts

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