Documentation ¶
Overview ¶
Package hash provides common utilities hashing kube objects and comparing hashes.
Index ¶
- func Equal(a, b string) bool
- func Object(obj interface{}) string
- func SecureEqual(a, b string) bool
- func SecureObject(obj interface{}) string
- type EqualFunc
- type ObjectHashFunc
- type ObjectHasher
- type Set
- func (s Set[T]) Contains(other Set[T]) bool
- func (s Set[T]) Delete(objects ...T) Set[T]
- func (s Set[T]) EqualElements(other Set[T]) bool
- func (s Set[T]) Has(objects ...T) bool
- func (s Set[T]) Insert(objects ...T) Set[T]
- func (s Set[T]) Intersect(other Set[T]) Set[T]
- func (s Set[T]) Len() int
- func (s Set[T]) Pop() (T, bool)
- func (s Set[T]) SetDifference(other Set[T]) Set[T]
- func (s Set[T]) Union(other Set[T]) Set[T]
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Object ¶
func Object(obj interface{}) string
Object canonicalizes the object before hashing with xxhash
Example ¶
configmap := corev1.ConfigMap{ Data: map[string]string{ "some": "data", }, } hash := Object(configmap) fmt.Println(Equal(hash, "n688h54h56ch64bh677h55fh648hddq"))
Output: true
func SecureObject ¶
func SecureObject(obj interface{}) string
SecureObject canonicalizes the object before hashing with sha512 and then with xxhash
Example ¶
secret := corev1.Secret{ StringData: map[string]string{ "some": "data", }, } hash := SecureObject(secret) fmt.Println(SecureEqual(hash, "n665hb8h667h68hfbhffh669h54dq"))
Output: true
Types ¶
type ObjectHashFunc ¶
type ObjectHasher ¶
ObjectHasher hashes and object and can compare hashes for equality
func NewObjectHash ¶
func NewObjectHash() ObjectHasher
NewObjectHash returns a new ObjectHasher using Object
func NewSecureObjectHash ¶
func NewSecureObjectHash() ObjectHasher
NewSecureObjectHash returns a new ObjectHasher using SecureObject
type Set ¶ added in v0.7.0
Set is a set that stores objects based on their Object hash
func (Set[T]) Contains ¶ added in v0.7.0
Contains returns true if all elements of other can be found in s.
func (Set[T]) EqualElements ¶ added in v0.7.0
EqualElements returns true if both sets have equal elements.
func (Set[T]) Intersect ¶ added in v0.7.0
Intersect returns a new set containing all the elements common to both. The new set will contain the object values from the receiver, not from the argument.
func (Set[T]) Pop ¶ added in v0.7.0
Pop removes and returns a single element from the set, and a bool indicating whether an element was found to pop.
func (Set[T]) SetDifference ¶ added in v0.7.0
SetDifference returns the set of objects in s that are not in other.