mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Merge pull request #102455 from lunhuijie/addTestHelpers
Add test cases to the addAllocatableThresholds function in pkg/kubelet/eviction/helpers.go
This commit is contained in:
commit
e154a6d637
@ -18,6 +18,7 @@ package eviction
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"k8s.io/apimachinery/pkg/util/diff"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
@ -453,6 +454,187 @@ func TestParseThresholdConfig(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddAllocatableThresholds(t *testing.T) {
|
||||||
|
// About func addAllocatableThresholds, only someone threshold that "Signal" is "memory.available" and "GracePeriod" is 0,
|
||||||
|
// append this threshold(changed "Signal" to "allocatableMemory.available") to thresholds
|
||||||
|
testCases := map[string]struct {
|
||||||
|
thresholds []evictionapi.Threshold
|
||||||
|
expected []evictionapi.Threshold
|
||||||
|
}{
|
||||||
|
"non-memory-signal": {
|
||||||
|
thresholds: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalImageFsAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalImageFsAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"memory-signal-with-grace": {
|
||||||
|
thresholds: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 10,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 10,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"memory-signal-without-grace": {
|
||||||
|
thresholds: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalAllocatableMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"memory-signal-without-grace-two-thresholds": {
|
||||||
|
thresholds: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("200Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("1Gi"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []evictionapi.Threshold{
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalAllocatableMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalAllocatableMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("200Mi"),
|
||||||
|
},
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("1Gi"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalMemoryAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("200Mi"),
|
||||||
|
},
|
||||||
|
GracePeriod: 0,
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("1Gi"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for testName, testCase := range testCases {
|
||||||
|
t.Run(testName, func(t *testing.T) {
|
||||||
|
if !thresholdsEqual(testCase.expected, addAllocatableThresholds(testCase.thresholds)) {
|
||||||
|
t.Errorf("Err not as expected, test: %v, Unexpected data: %s", testName, diff.ObjectDiff(testCase.expected, addAllocatableThresholds(testCase.thresholds)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func thresholdsEqual(expected []evictionapi.Threshold, actual []evictionapi.Threshold) bool {
|
func thresholdsEqual(expected []evictionapi.Threshold, actual []evictionapi.Threshold) bool {
|
||||||
if len(expected) != len(actual) {
|
if len(expected) != len(actual) {
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user