hash

package
v1.17.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2022 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// OKTHashAnnotationName is hash key to annotate a Kubernetes resource
	// with the hash of its template.
	OKTHashAnnotationName = "operator.k8s.orange.com/okt-hash"
)

Variables

This section is empty.

Functions

func Compute

func Compute(obj interface{}) string

Compute writes the specified object to a 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. The returned hash can be used for object comparisons.

This is inspired by controller revisions in StatefulSets and ElasticSearch Operator: https://github.com/kubernetes/kubernetes/blob/8de1569ddae62e8fab559fe6bd210a5d6100a277/pkg/controller/history/controller_history.go#L89-L101 https://github.com/elastic/cloud-on-k8s/blob/master/pkg/controller/common/hash/hash.go

func GenerateNew

func GenerateNew(obj runtime.Object, template interface{}) (bool, error)

GenerateNew Get object's template hash from its annotation (cur hash), if it exists, and compute the new object's template hash. The object (obj) passed as argument, is storing the hash value in its metadata annotations. The template passed as argument represents all the fields and data that must be taken under account to compute the Hash value. If they are different, then store/replace the old value in annotation by the new one. Then return true (new generated). It returns false (not new!) if the object's template hash is equal to the current hash value in annotations. It returns true if the object had no hash value. The template should be a relevant part (the Spec if it exists or another significant part) on which the Hash key can be computed independantly to any un-relevant modifications on the object.

func GetTemplateHashAnnotation

func GetTemplateHashAnnotation(annotations map[string]string) string

GetTemplateHashAnnotation returns the template hash annotation value if set, or an empty string.

func SetTemplateHashAnnotation

func SetTemplateHashAnnotation(annotations map[string]string, template interface{}) map[string]string

SetTemplateHashAnnotation adds an annotation containing the hash of the given template into the given annotations. This annotation can then be used for template comparisons.

Types

type HashableRef

type HashableRef interface {
	GetRef() interface{}
}

HashableRef xx

Jump to

Keyboard shortcuts

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