mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Simplify checking in getMinTolerationTime
This commit is contained in:
parent
3178e69b39
commit
c811b2267f
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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.
|
// getMinTolerationTime returns minimal toleration time from the given slice, or -1 if it's infinite.
|
||||||
func getMinTolerationTime(tolerations []v1.Toleration) time.Duration {
|
func getMinTolerationTime(tolerations []v1.Toleration) time.Duration {
|
||||||
minTolerationTime := int64(-1)
|
minTolerationTime := int64(math.MaxInt64)
|
||||||
if len(tolerations) == 0 {
|
if len(tolerations) == 0 {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -139,12 +140,15 @@ func getMinTolerationTime(tolerations []v1.Toleration) time.Duration {
|
|||||||
tolerationSeconds := *(tolerations[i].TolerationSeconds)
|
tolerationSeconds := *(tolerations[i].TolerationSeconds)
|
||||||
if tolerationSeconds <= 0 {
|
if tolerationSeconds <= 0 {
|
||||||
return 0
|
return 0
|
||||||
} else if tolerationSeconds < minTolerationTime || minTolerationTime == -1 {
|
} else if tolerationSeconds < minTolerationTime {
|
||||||
minTolerationTime = tolerationSeconds
|
minTolerationTime = tolerationSeconds
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if minTolerationTime == int64(math.MaxInt64) {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
return time.Duration(minTolerationTime) * time.Second
|
return time.Duration(minTolerationTime) * time.Second
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -617,6 +617,7 @@ func TestUpdateNodeWithMultiplePods(t *testing.T) {
|
|||||||
|
|
||||||
func TestGetMinTolerationTime(t *testing.T) {
|
func TestGetMinTolerationTime(t *testing.T) {
|
||||||
one := int64(1)
|
one := int64(1)
|
||||||
|
two := int64(2)
|
||||||
oneSec := 1 * time.Second
|
oneSec := 1 * time.Second
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@ -627,6 +628,26 @@ func TestGetMinTolerationTime(t *testing.T) {
|
|||||||
tolerations: []v1.Toleration{},
|
tolerations: []v1.Toleration{},
|
||||||
expected: 0,
|
expected: 0,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tolerations: []v1.Toleration{
|
||||||
|
{
|
||||||
|
TolerationSeconds: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: -1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tolerations: []v1.Toleration{
|
||||||
|
{
|
||||||
|
TolerationSeconds: &one,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
TolerationSeconds: &two,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: oneSec,
|
||||||
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
tolerations: []v1.Toleration{
|
tolerations: []v1.Toleration{
|
||||||
{
|
{
|
||||||
@ -662,7 +683,7 @@ func TestGetMinTolerationTime(t *testing.T) {
|
|||||||
// TestEventualConsistency verifies if getPodsAssignedToNode returns incomplete data
|
// TestEventualConsistency verifies if getPodsAssignedToNode returns incomplete data
|
||||||
// (e.g. due to watch latency), it will reconcile the remaining pods eventually.
|
// (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
|
// 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) {
|
func TestEventualConsistency(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
description string
|
description string
|
||||||
|
Loading…
Reference in New Issue
Block a user