mirror of
https://github.com/actions/actions-runner-controller.git
synced 2025-12-10 19:50:30 +00:00
Introduce new preview auto-scaling mode for ARC. (#2153)
Co-authored-by: Cory Miller <cory-miller@github.com> Co-authored-by: Nikola Jokic <nikola-jokic@github.com> Co-authored-by: Ava Stancu <AvaStancu@github.com> Co-authored-by: Ferenc Hammerl <fhammerl@github.com> Co-authored-by: Francesco Renzi <rentziass@github.com> Co-authored-by: Bassem Dghaidi <Link-@github.com>
This commit is contained in:
26
hash/hash.go
26
hash/hash.go
@@ -5,9 +5,12 @@
|
||||
package hash
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash"
|
||||
"hash/fnv"
|
||||
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
)
|
||||
|
||||
// DeepHashObject writes specified object to hash using the spew library
|
||||
@@ -23,3 +26,26 @@ func DeepHashObject(hasher hash.Hash, objectToWrite interface{}) {
|
||||
}
|
||||
printer.Fprintf(hasher, "%#v", objectToWrite)
|
||||
}
|
||||
|
||||
// ComputeHash returns a hash value calculated from template and
|
||||
// a collisionCount to avoid hash collision. The hash will be safe encoded to
|
||||
// avoid bad words. It expects **template. In other words, you should pass an address
|
||||
// of a DeepCopy result.
|
||||
//
|
||||
// Proudly modified and adopted from k8s.io/kubernetes/pkg/util/hash.DeepHashObject and
|
||||
// k8s.io/kubernetes/pkg/controller.ComputeHash.
|
||||
func ComputeTemplateHash(template interface{}) string {
|
||||
hasher := fnv.New32a()
|
||||
|
||||
hasher.Reset()
|
||||
|
||||
printer := spew.ConfigState{
|
||||
Indent: " ",
|
||||
SortKeys: true,
|
||||
DisableMethods: true,
|
||||
SpewKeys: true,
|
||||
}
|
||||
printer.Fprintf(hasher, "%#v", template)
|
||||
|
||||
return rand.SafeEncodeString(fmt.Sprint(hasher.Sum32()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user