Merge pull request #79443 from tedyu/taint-mgr-name

Simplify checking in getMinTolerationTime
This commit is contained in:
Kubernetes Prow Robot 2019-08-05 15:08:03 -07:00 committed by GitHub
commit 9e735d6b27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 3 deletions

View File

@ -20,6 +20,7 @@ import (
"fmt"
"hash/fnv"
"io"
"math"
"sync"
"time"
@ -129,7 +130,7 @@ func getNoExecuteTaints(taints []v1.Taint) []v1.Taint {
// getMinTolerationTime returns minimal toleration time from the given slice, or -1 if it's infinite.
func getMinTolerationTime(tolerations []v1.Toleration) time.Duration {
minTolerationTime := int64(-1)
minTolerationTime := int64(math.MaxInt64)
if len(tolerations) == 0 {
return 0
}
@ -139,12 +140,15 @@ func getMinTolerationTime(tolerations []v1.Toleration) time.Duration {
tolerationSeconds := *(tolerations[i].TolerationSeconds)
if tolerationSeconds <= 0 {
return 0
} else if tolerationSeconds < minTolerationTime || minTolerationTime == -1 {
} else if tolerationSeconds < minTolerationTime {
minTolerationTime = tolerationSeconds
}
}
}
if minTolerationTime == int64(math.MaxInt64) {
return -1
}
return time.Duration(minTolerationTime) * time.Second
}

View File

@ -617,6 +617,7 @@ func TestUpdateNodeWithMultiplePods(t *testing.T) {
func TestGetMinTolerationTime(t *testing.T) {
one := int64(1)
two := int64(2)
oneSec := 1 * time.Second
tests := []struct {
@ -627,6 +628,26 @@ func TestGetMinTolerationTime(t *testing.T) {
tolerations: []v1.Toleration{},
expected: 0,
},
{
tolerations: []v1.Toleration{
{
TolerationSeconds: nil,
},
},
expected: -1,
},
{
tolerations: []v1.Toleration{
{
TolerationSeconds: &one,
},
{
TolerationSeconds: &two,
},
},
expected: oneSec,
},
{
tolerations: []v1.Toleration{
{
@ -662,7 +683,7 @@ func TestGetMinTolerationTime(t *testing.T) {
// TestEventualConsistency verifies if getPodsAssignedToNode returns incomplete data
// (e.g. due to watch latency), it will reconcile the remaining pods eventually.
// This scenario is partially covered by TestUpdatePods, but given this is an important
// property of TaitManager, it's better to have explicit test for this.
// property of TaintManager, it's better to have explicit test for this.
func TestEventualConsistency(t *testing.T) {
testCases := []struct {
description string