Implement hash collision avoidance mechanism

Signed-off-by: Michail Kargakis <mkargaki@redhat.com>
This commit is contained in:
Michail Kargakis
2017-04-21 19:49:30 +02:00
parent aeb2d9b9b4
commit 4a2c5eae92
9 changed files with 227 additions and 67 deletions

View File

@@ -17,6 +17,7 @@ limitations under the License.
package util
import (
"encoding/binary"
"hash/fnv"
"github.com/golang/glog"
@@ -30,9 +31,17 @@ import (
hashutil "k8s.io/kubernetes/pkg/util/hash"
)
func GetPodTemplateSpecHash(template v1.PodTemplateSpec) uint32 {
func GetPodTemplateSpecHash(template *v1.PodTemplateSpec, uniquifier *int64) uint32 {
podTemplateSpecHasher := fnv.New32a()
hashutil.DeepHashObject(podTemplateSpecHasher, template)
hashutil.DeepHashObject(podTemplateSpecHasher, *template)
// Add uniquifier in the hash if it exists.
if uniquifier != nil {
uniquifierBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(uniquifierBytes, uint64(*uniquifier))
podTemplateSpecHasher.Write(uniquifierBytes)
}
return podTemplateSpecHasher.Sum32()
}