Skip to content

Commit

Permalink
Merge pull request #245 from vbnrh/fix-obc-naming-previous-version
Browse files Browse the repository at this point in the history
Fix issue with the hash generation for MirrorPeer
  • Loading branch information
openshift-merge-bot[bot] authored Dec 9, 2024
2 parents 190d5a5 + 78291db commit 27674c2
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions controllers/utils/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,23 @@ func CreateUniqueReplicationId(clusterFSIDs map[string]string) (string, error) {
}

func GenerateUniqueIdForMirrorPeer(mirrorPeer multiclusterv1alpha1.MirrorPeer, hasStorageClientRef bool) string {
var peerAccumulator []string

var checksum [20]byte
if hasStorageClientRef {
var peerAccumulator []string
for _, peer := range mirrorPeer.Spec.Items {
peerAccumulator = append(peerAccumulator, GetKey(peer.ClusterName, peer.StorageClusterRef.Name))
}
sort.Strings(peerAccumulator)
checksum = sha1.Sum([]byte(strings.Join(peerAccumulator, "-")))
} else {
var peerAccumulator string
for _, peer := range mirrorPeer.Spec.Items {
peerAccumulator = append(peerAccumulator, peer.ClusterName)
peerAccumulator += peer.ClusterName
}

checksum = sha1.Sum([]byte(peerAccumulator))
}

sort.Strings(peerAccumulator)

checksum := sha1.Sum([]byte(strings.Join(peerAccumulator, "-")))
return hex.EncodeToString(checksum[:])
// truncate to bucketGenerateName + "-" + first 12 (out of 20) byte representations of sha1 checksum
return hex.EncodeToString(checksum[:])[0 : len(BucketGenerateName)+1+12]
}

func GetKey(clusterName, clientName string) string {
Expand Down

0 comments on commit 27674c2

Please sign in to comment.