mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-04 23:17:50 +00:00
Implement hash collision avoidance mechanism
Signed-off-by: Michail Kargakis <mkargaki@redhat.com>
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user