util

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserAgent = "kapacity-manager"
)

Variables

This section is empty.

Functions

func AbsInt32

func AbsInt32(x int32) int32

AbsInt32 returns the absolute value of an int32 number.

func AddPodCondition

func AddPodCondition(status *corev1.PodStatus, condition *corev1.PodCondition) bool

AddPodCondition adds a pod condition if not exists. Sets LastTransitionTime to now if not exists. Returns true if pod condition has been added.

func AddPodReadinessGate

func AddPodReadinessGate(spec *corev1.PodSpec, conditionType corev1.PodConditionType) bool

AddPodReadinessGate adds the provided condition to the pod's readiness gates. Returns true if the readiness gate has been added.

func ConvertPromLabelSetToMap added in v0.2.0

func ConvertPromLabelSetToMap(in prommodel.LabelSet) map[string]string

func CopyMapValues added in v0.2.0

func CopyMapValues(dst, src map[string]string)

CopyMapValues copies all the values from src map to dst map, overwriting any existing one.

func ExponentialBackoffWithContext added in v0.2.0

func ExponentialBackoffWithContext(ctx context.Context, backoff wait.Backoff, condition wait.ConditionWithContextFunc) error

ExponentialBackoffWithContext works similar like wait.ExponentialBackoffWithContext but with below differences: * It does not stop when the cap of backoff is reached. * It does not return the error of ctx when done.

func GetPodNames

func GetPodNames(pods []*corev1.Pod) []string

GetPodNames generate a list of pod names from a list of pod objects.

func IsCronActive

func IsCronActive(t time.Time, startCron, endCron string) (bool, time.Time, error)

IsCronActive returns if the given time is in the range specified by the start cron and end cron as well as the next time of the end cron.

func IsMapValueChanged added in v0.2.0

func IsMapValueChanged(oldValues, newValues map[string]string) bool

IsMapValueChanged compares two maps' values key by key, if any value in oldValues map differs from the one in newValues map, it returns true, otherwise returns false.

func IsPodActive

func IsPodActive(pod *corev1.Pod) bool

IsPodActive returns if the given pod has not terminated.

func IsPodRunning

func IsPodRunning(pod *corev1.Pod) bool

IsPodRunning returns if the given pod's phase is running and is not being deleted.

func MaxInt32

func MaxInt32(a, b int32) int32

MaxInt32 returns the biggest one between two int32 numbers.

func MinInt32

func MinInt32(a, b int32) int32

MinInt32 returns the smallest one between two int32 numbers.

func NewControllerRef added in v0.2.0

func NewControllerRef(obj client.Object) *metav1.OwnerReference

NewControllerRef creates a controller owner reference pointing to the given owner.

func NewCtrlPodLister added in v0.2.0

func NewCtrlPodLister(client client.Client) corev1listers.PodLister

NewCtrlPodLister creates a corev1listers.PodLister wrapper for given controller-runtime client.

func ParseScaleSelector

func ParseScaleSelector(selector string) (labels.Selector, error)

ParseScaleSelector parses the selector string got from Kubernetes scale API to labels.Selector.

func SetConditionInList

func SetConditionInList(inputList []metav1.Condition, conditionType string, status metav1.ConditionStatus, observedGeneration int64, reason, message string) []metav1.Condition

SetConditionInList sets the specific condition type on the given condition list to the specified value with the given reason and message. The condition will be added if it is not present. The new list will be returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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