util

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 2 more Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeepContains

func DeepContains(x, y interface{}) bool

deepContains reports whether y is a “subset” of x defined as follows. It is a relaxation of the reflect.DeepEqual aimed to compare deeply nested values. Value x deeply contains value y if one of the following cases applies. Values of distinct types never contain each other.

Array x deeply contains array y when the elements of array y deeply contain corresponding elements of array x.

Struct value x deeply contains struct value y if the exported values of y deeply contain corresponding exported fields of x. Unexported fields are ignored.

Func values deeply contain each other if both are nil.

Interface value x deeply contains interface value y if y holds values deeply equal to the concrete values of x, nil or zero values.

Map value x deeply contains map value y when one of the following is true: - map value y is nil or zero value, - length of y is less or equal to the length of x, and they are the same map object or the keys of y match corresponding keys of x (matched using Go equality) and map to deeply contained values.

Pointer values are deeply contained if they are equal using Go's == operator or if they point to deeply contained values.

Slice values are deeply contained when one of the following is true: - y is nil or zero value, - length of y is less or equal to the length of x, and either they point to the same initial entry of the same underlying array (that is, &x[0] == &y[0]) or their corresponding elements (up to length of y) are deeply contained. Note that a non-nil empty slice and a nil slice (for example, []byte{} and []byte(nil)) are deeply contained.

Other values - numbers, bools, strings, and channels - are deeply contained if y is zero value or they are equal using Go's == operator.

In general deepContains is a relaxation of the reflect.DeepEqual aimed to compare deeply nested values. However, this idea is impossible to implement without some inconsistency. Specifically, it is possible for a value to be unequal to itself, either because it is of func type (uncomparable in general) or because it is a floating-point NaN value (not equal to itself in floating-point comparison), or because it is an array, struct, or interface containing such a value.

Another important caveat is zero and nil values. Zero values are indistinguishable from those declared explicitly and will be treated as deeply contained when compared against non-zero values. Deeply nested values y of basic numeric, string and bool types are always compared against their zero values and they are equal to zero values the are treated as "contained" for the corresponding values of x.

On the other hand, pointer values are always equal to themselves, even if they point at or contain such problematic values, because they compare equal using Go's == operator, and that is a sufficient condition to be deeply contained, regardless of content. deepContains has been defined so that the same short-cut applies to slices and maps: if x and y are the same slice or the same map, they are deeply contained regardless of content.

As deepContains traverses the data values it may find a cycle. The second and subsequent times that deepContains compares two pointer values that have been compared before, it treats the values as equal rather than examining the values to which they point. This ensures that deepContains terminates.

func DeepHashObject

func DeepHashObject(hasher hash.Hash, objectToWrite interface{})

DeepHashObject writes specified object to hash using the spew library which follows pointers and prints actual values of the nested objects ensuring the hash does not change when a pointer changes.

func FiltDgStatus added in v0.4.0

func FiltDgStatus(status appsv1.DeploymentStatus) appsv1.DeploymentStatus

func GenerateHash

func GenerateHash(template interface{}) uint64

func GenerateKubeConfigFromToken added in v0.4.0

func GenerateKubeConfigFromToken(serverURL, token string, caCert []byte, flowRate int) (*rest.Config, error)

GenerateKubeConfigFromToken composes a kubeconfig from token

func GetGridValuesFromNode

func GetGridValuesFromNode(nodeLister corelisters.NodeLister, gridUniqKey string) ([]string, error)

func GetTemplateHash

func GetTemplateHash(labels map[string]string) string

func GetTemplateName

func GetTemplateName(templates map[string]string, gridValues string, defaultTemplateName string) string

GetTemplateName returns template name for workload whose name is gridValues, default is 'DefaultTemplateName'

Types

This section is empty.

Jump to

Keyboard shortcuts

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