Documentation ¶
Index ¶
- Constants
- func Compute(obj interface{}) string
- func GenerateNew(obj runtime.Object, template interface{}) (bool, error)
- func GetTemplateHashAnnotation(annotations map[string]string) string
- func SetTemplateHashAnnotation(annotations map[string]string, template interface{}) map[string]string
- type HashableRef
Constants ¶
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 ¶
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 ¶
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.