-
Notifications
You must be signed in to change notification settings - Fork 904
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: using our own pod template hashing (#1809)
* fix: implement pod template hash calculate function Signed-off-by: Andrii Perenesenko <[email protected]> * fix: using new hashing for FindNewReplicaSet and other places Signed-off-by: Andrii Perenesenko <[email protected]> * fix tests Signed-off-by: Andrii Perenesenko <[email protected]> * fix tests with deprecated hash Signed-off-by: Andrii Perenesenko <[email protected]> * test TestFindNewReplicaSet, TestHashUtils Signed-off-by: Andrii Perenesenko <[email protected]> * fix the doc for ComputePodTemplateHash Signed-off-by: Andrii Perenesenko <[email protected]> * test for ComputePodTemplateHash with collisionCount Signed-off-by: Andrii Perenesenko <[email protected]> * refactoring avoid double FindNewReplicaSet call: pass newRS as a parameter to the FindOldReplicaSets as it using only right after the FindNewReplicaSet Signed-off-by: Andrii Perenesenko <[email protected]> * fix time dependent flaky test Signed-off-by: Andrii Perenesenko <[email protected]>
- Loading branch information
1 parent
f388937
commit e79296a
Showing
15 changed files
with
175 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package hash | ||
|
||
import ( | ||
"encoding/binary" | ||
"encoding/json" | ||
"fmt" | ||
"hash/fnv" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/rand" | ||
) | ||
|
||
// ComputePodTemplateHash returns a hash value calculated from pod template. | ||
// The hash will be safe encoded to avoid bad words. | ||
func ComputePodTemplateHash(template *corev1.PodTemplateSpec, collisionCount *int32) string { | ||
podTemplateSpecHasher := fnv.New32a() | ||
stepsBytes, err := json.Marshal(template) | ||
if err != nil { | ||
panic(err) | ||
} | ||
_, err = podTemplateSpecHasher.Write(stepsBytes) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if collisionCount != nil { | ||
collisionCountBytes := make([]byte, 8) | ||
binary.LittleEndian.PutUint32(collisionCountBytes, uint32(*collisionCount)) | ||
_, err = podTemplateSpecHasher.Write(collisionCountBytes) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} | ||
return rand.SafeEncodeString(fmt.Sprint(podTemplateSpecHasher.Sum32())) | ||
} |
Oops, something went wrong.