util

package
v1.0.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: Apache-2.0 Imports: 22 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GlobalCache = cache.NewStore(func(obj interface{}) (string, error) {
	metaObj, ok := obj.(metav1.Object)
	if !ok {
		return "", fmt.Errorf("failed to convert obj to metav1.Object")
	}
	namespacedName := fmt.Sprintf("%s/%s", metaObj.GetNamespace(), metaObj.GetName())

	runtimeObj, ok := obj.(runtime.Object)
	if !ok {
		return "", fmt.Errorf("failed to convert obj to runtime.Object")
	}
	key := fmt.Sprintf("%v/%s", runtimeObj.GetObjectKind().GroupVersionKind(), namespacedName)
	return key, nil
})

GlobalCache using GVK/namespace/name as key

View Source
var GlobalKeyedMutex = &KeyedMutex{}

Functions

func CheckDuplicate added in v0.3.1

func CheckDuplicate(list []string) []string

CheckDuplicate finds if there are duplicated items in a list.

func DiffPods added in v0.9.0

func DiffPods(pods1, pods2 []*v1.Pod) (ret []*v1.Pod)

DiffPods returns pods in pods1 but not in pods2

func DumpJSON

func DumpJSON(o interface{}) string

DumpJSON returns the JSON encoding

func GetContainer added in v0.8.0

func GetContainer(name string, pod *v1.Pod) *v1.Container

func GetContainerEnvValue added in v0.8.0

func GetContainerEnvValue(container *v1.Container, key string) string

func GetContainerEnvVar added in v0.8.0

func GetContainerEnvVar(container *v1.Container, key string) *v1.EnvVar

func GetContainerStatus added in v0.9.0

func GetContainerStatus(name string, pod *v1.Pod) *v1.ContainerStatus

func GetContainerVolumeMount added in v0.8.0

func GetContainerVolumeMount(container *v1.Container, key string) *v1.VolumeMount

func GetFastLabelSelector added in v0.8.0

func GetFastLabelSelector(ps *metav1.LabelSelector) (labels.Selector, error)

func GetIntOrStrPointer added in v0.7.0

func GetIntOrStrPointer(i intstrutil.IntOrString) *intstrutil.IntOrString

func GetPodNames added in v0.6.1

func GetPodNames(pods []*v1.Pod) sets.String

GetPodNames returns names of the given Pods array

func GetPodVolume added in v0.8.0

func GetPodVolume(pod *v1.Pod, volumeName string) *v1.Volume

func InjectReadinessGateToPod added in v0.9.0

func InjectReadinessGateToPod(pod *v1.Pod, conditionType v1.PodConditionType)

func IntAbs added in v0.9.0

func IntAbs(i int) int

IntAbs returns the abs number of the given int number

func IsContainerImageEqual added in v0.8.0

func IsContainerImageEqual(image1, image2 string) bool

1. image1, image2 are digest image, compare repo+digest 2. image1, image2 are normal image, compare repo+tag 3. image1, image2 are digest+normal image, don't support compare it, return false

func IsImageDigest added in v0.8.0

func IsImageDigest(image string) bool

whether image is digest format, for example: docker.io/busybox@sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d

func IsIntPlusAndMinus added in v0.9.0

func IsIntPlusAndMinus(i, j int) bool

func IsJSONObjectEqual added in v0.9.0

func IsJSONObjectEqual(o1, o2 interface{}) bool

IsJSONObjectEqual checks if two objects are equal after encoding json

func IsPodContainerDigestEqual added in v0.8.0

func IsPodContainerDigestEqual(containers sets.String, pod *v1.Pod) bool

func IsPodOwnedByKruise added in v0.9.0

func IsPodOwnedByKruise(pod *v1.Pod) bool

func IsRunningAndReady added in v0.8.0

func IsRunningAndReady(pod *v1.Pod) bool

func IsSelectorLooseOverlap added in v0.10.0

func IsSelectorLooseOverlap(selector1, selector2 *metav1.LabelSelector) bool

whether selectors overlap (indicates that selector1, selector2 have same key, and there is an certain intersection) 1. when selector1、selector2 don't have same key, it is considered non-overlap, e.g. selector1(a=b) and selector2(c=d) 2. when selector1、selector2 have same key, and matchLabels & matchExps are intersection, it is considered overlap. For examples:

a In [b,c]    And a Exist
                  a In [b,...] [c,...] [Include any b,c,...]
                  a NotIn [a,...] [b,....] [c,....] [All other cases are allowed except for the inclusion of both b,c...] [b,c,e]
a Exist       And a Exist
                  a In [x,y,Any,...]
                  a NotIn [a,b,Any...]
a NotIn [b,c] And a Exist
                  a NotExist
                  a NotIn [a,b,Any...]
                  a In [a,b] [a,c] [e,f] [Any,...] other than [b],[c],[b,c]
a NotExist    And a NotExist
                  a NotIn [Any,...]
When selector1 and selector2 contain the same key, except for the above case, they are considered non-overlap

func IsSelectorOverlapping added in v0.8.0

func IsSelectorOverlapping(selector1, selector2 *metav1.LabelSelector) bool

whether selector overlaps, the criteria: if exist one same key has different value and not overlap, then it is judged non-overlap, for examples:

  • a=b and a=c
  • a in [b,c] and a not in [b,c...]
  • a not in [b] and a not exist
  • a=b,c=d,e=f and a=x,c=d,e=f

then others is overlap:

  • a=b and c=d

func MergeEnvVar added in v0.8.0

func MergeEnvVar(original []v1.EnvVar, additional []v1.EnvVar) []v1.EnvVar

func MergePods added in v0.6.1

func MergePods(pods1, pods2 []*v1.Pod) []*v1.Pod

MergePods merges two pods arrays

func MergeVolumeMounts added in v0.8.0

func MergeVolumeMounts(original, additional []v1.VolumeMount) []v1.VolumeMount

func MergeVolumeMountsInContainer added in v0.8.0

func MergeVolumeMountsInContainer(origin *v1.Container, other v1.Container)

func MergeVolumes added in v0.8.0

func MergeVolumes(original []v1.Volume, additional []v1.Volume) []v1.Volume

func NewClientFromManager added in v0.8.0

func NewClientFromManager(mgr manager.Manager, name string) client.Client

func ParseImage added in v0.8.0

func ParseImage(image string) (repo, tag, digest string, err error)

parse container images, 1. docker.io/busybox@sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d repo=docker.io/busybox, tag="", digest=sha256:a9286defaba7b3a519d585ba0e37d0b2cbee74ebfe590960b0b1d6a5e97d1e1d 2. docker.io/busybox:latest repo=docker.io/busybox, tag=latest, digest=""

func SlowStartBatch added in v0.3.0

func SlowStartBatch(count int, initialBatchSize int, fn func(index int) error) (int, error)

SlowStartBatch 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 with its index.

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.

Types

type KeyedMutex added in v0.10.1

type KeyedMutex struct {
	// contains filtered or unexported fields
}

func (*KeyedMutex) Lock added in v0.10.1

func (m *KeyedMutex) Lock(key string) func()

func (*KeyedMutex) Unlock added in v0.10.1

func (m *KeyedMutex) Unlock(key string)

Jump to

Keyboard shortcuts

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