Merge pull request #65596 from liggitt/out-of-bounds

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

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

This fixes an out of bounds error when running the controllers on a 32-bit machine

```
W0628 17:52:30.171975       1 node_lifecycle_controller.go:782] Missing timestamp for Node kube-master. Assuming now as a timestamp.
I0628 17:52:30.172115       1 taint_manager.go:205] Starting NoExecuteTaintManager
panic: runtime error: index out of range

goroutine 1740 [running]:
k8s.io/kubernetes/pkg/controller/nodelifecycle/scheduler.(*NoExecuteTaintManager).Run.func1(0x165e6000, 0x8, 0x15984100)
        /workspace/anago-v1.11.0-rc.3.3+91e7b4fd31fcd3/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/controller/nodelifecycle/scheduler/taint_manager.go:229 +0x1f8
created by k8s.io/kubernetes/pkg/controller/nodelifecycle/scheduler.(*NoExecuteTaintManager).Run
        /workspace/anago-v1.11.0-rc.3.3+91e7b4fd31fcd3/src/k8s.io/kubernetes/_output/dockerized/go/src/k8s.io/kubernetes/pkg/controller/nodelifecycle/scheduler/taint_manager.go:217 +0x27c
```

See https://play.golang.org/p/rIpicHGHtiT for an example of the coercion overflow


/assign @wojtek-t
/kind bug

```release-note
fixes an out of range panic in the NoExecuteTaintManager controller when running a non-64-bit build
```
This commit is contained in:
Kubernetes Submit Queue 2018-06-29 00:55:03 -07:00 committed by GitHub
commit 85aa6d2405
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,10 +80,10 @@ func (p *podUpdateItem) nodeName() string {
return ""
}
func hash(val string) int {
func hash(val string, max int) int {
hasher := fnv.New32a()
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
@ -221,12 +221,12 @@ func (tc *NoExecuteTaintManager) Run(stopCh <-chan struct{}) {
break
}
nodeUpdate := item.(*nodeUpdateItem)
hash := hash(nodeUpdate.name())
hash := hash(nodeUpdate.name(), workers)
select {
case <-stopCh:
tc.nodeUpdateQueue.Done(item)
break
case tc.nodeUpdateChannels[hash%workers] <- nodeUpdate:
case tc.nodeUpdateChannels[hash] <- nodeUpdate:
}
tc.nodeUpdateQueue.Done(item)
}
@ -239,12 +239,12 @@ func (tc *NoExecuteTaintManager) Run(stopCh <-chan struct{}) {
break
}
podUpdate := item.(*podUpdateItem)
hash := hash(podUpdate.nodeName())
hash := hash(podUpdate.nodeName(), workers)
select {
case <-stopCh:
tc.podUpdateQueue.Done(item)
break
case tc.podUpdateChannels[hash%workers] <- podUpdate:
case tc.podUpdateChannels[hash] <- podUpdate:
}
tc.podUpdateQueue.Done(item)
}