Fix out of bounds error on non-64-bit machines

This commit is contained in:
Jordan Liggitt 2018-06-28 16:29:52 -04:00
parent a6e351484e
commit 52abbeffe6
No known key found for this signature in database
GPG Key ID: 39928704103C7229

View File

@ -80,10 +80,10 @@ func (p *podUpdateItem) nodeName() string {
return "" return ""
} }
func hash(val string) int { func hash(val string, max int) int {
hasher := fnv.New32a() hasher := fnv.New32a()
io.WriteString(hasher, val) io.WriteString(hasher, val)
return int(hasher.Sum32()) return int(hasher.Sum32() % uint32(max))
} }
// NoExecuteTaintManager listens to Taint/Toleration changes and is responsible for removing Pods // NoExecuteTaintManager listens to Taint/Toleration changes and is responsible for removing Pods
@ -221,12 +221,12 @@ func (tc *NoExecuteTaintManager) Run(stopCh <-chan struct{}) {
break break
} }
nodeUpdate := item.(*nodeUpdateItem) nodeUpdate := item.(*nodeUpdateItem)
hash := hash(nodeUpdate.name()) hash := hash(nodeUpdate.name(), workers)
select { select {
case <-stopCh: case <-stopCh:
tc.nodeUpdateQueue.Done(item) tc.nodeUpdateQueue.Done(item)
break break
case tc.nodeUpdateChannels[hash%workers] <- nodeUpdate: case tc.nodeUpdateChannels[hash] <- nodeUpdate:
} }
tc.nodeUpdateQueue.Done(item) tc.nodeUpdateQueue.Done(item)
} }
@ -239,12 +239,12 @@ func (tc *NoExecuteTaintManager) Run(stopCh <-chan struct{}) {
break break
} }
podUpdate := item.(*podUpdateItem) podUpdate := item.(*podUpdateItem)
hash := hash(podUpdate.nodeName()) hash := hash(podUpdate.nodeName(), workers)
select { select {
case <-stopCh: case <-stopCh:
tc.podUpdateQueue.Done(item) tc.podUpdateQueue.Done(item)
break break
case tc.podUpdateChannels[hash%workers] <- podUpdate: case tc.podUpdateChannels[hash] <- podUpdate:
} }
tc.podUpdateQueue.Done(item) tc.podUpdateQueue.Done(item)
} }