mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Iterate through thresholds in managerImpl#synchronize
This commit is contained in:
parent
82bfa667ed
commit
19c91a59ab
@ -324,10 +324,8 @@ func (m *managerImpl) synchronize(diskInfoProvider DiskInfoProvider, podFunc Act
|
|||||||
|
|
||||||
// rank the thresholds by eviction priority
|
// rank the thresholds by eviction priority
|
||||||
sort.Sort(byEvictionPriority(thresholds))
|
sort.Sort(byEvictionPriority(thresholds))
|
||||||
thresholdToReclaim := thresholds[0]
|
thresholdToReclaim, resourceToReclaim, foundAny := getReclaimableThreshold(thresholds)
|
||||||
resourceToReclaim, found := signalToResource[thresholdToReclaim.Signal]
|
if !foundAny {
|
||||||
if !found {
|
|
||||||
klog.V(3).Infof("eviction manager: threshold %s was crossed, but reclaim is not implemented for this threshold.", thresholdToReclaim.Signal)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
klog.Warningf("eviction manager: attempting to reclaim %v", resourceToReclaim)
|
klog.Warningf("eviction manager: attempting to reclaim %v", resourceToReclaim)
|
||||||
|
@ -98,6 +98,17 @@ func validSignal(signal evictionapi.Signal) bool {
|
|||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getReclaimableThreshold finds the threshold and resource to reclaim
|
||||||
|
func getReclaimableThreshold(thresholds []evictionapi.Threshold) (evictionapi.Threshold, v1.ResourceName, bool) {
|
||||||
|
for _, thresholdToReclaim := range thresholds {
|
||||||
|
if resourceToReclaim, ok := signalToResource[thresholdToReclaim.Signal]; ok {
|
||||||
|
return thresholdToReclaim, resourceToReclaim, true
|
||||||
|
}
|
||||||
|
klog.V(3).Infof("eviction manager: threshold %s was crossed, but reclaim is not implemented for this threshold.", thresholdToReclaim.Signal)
|
||||||
|
}
|
||||||
|
return evictionapi.Threshold{}, "", false
|
||||||
|
}
|
||||||
|
|
||||||
// ParseThresholdConfig parses the flags for thresholds.
|
// ParseThresholdConfig parses the flags for thresholds.
|
||||||
func ParseThresholdConfig(allocatableConfig []string, evictionHard, evictionSoft, evictionSoftGracePeriod, evictionMinimumReclaim map[string]string) ([]evictionapi.Threshold, error) {
|
func ParseThresholdConfig(allocatableConfig []string, evictionHard, evictionSoft, evictionSoftGracePeriod, evictionMinimumReclaim map[string]string) ([]evictionapi.Threshold, error) {
|
||||||
results := []evictionapi.Threshold{}
|
results := []evictionapi.Threshold{}
|
||||||
|
@ -40,6 +40,65 @@ func quantityMustParse(value string) *resource.Quantity {
|
|||||||
return &q
|
return &q
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetReclaimableThreshold(t *testing.T) {
|
||||||
|
testCases := map[string]struct {
|
||||||
|
thresholds []evictionapi.Threshold
|
||||||
|
}{
|
||||||
|
"": {
|
||||||
|
thresholds: []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"),
|
||||||
|
},
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("0"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalImageFsAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("150Mi"),
|
||||||
|
},
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("2Gi"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Signal: evictionapi.SignalNodeFsAvailable,
|
||||||
|
Operator: evictionapi.OpLessThan,
|
||||||
|
Value: evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("100Mi"),
|
||||||
|
},
|
||||||
|
MinReclaim: &evictionapi.ThresholdValue{
|
||||||
|
Quantity: quantityMustParse("1Gi"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for testName, testCase := range testCases {
|
||||||
|
sort.Sort(byEvictionPriority(testCase.thresholds))
|
||||||
|
_, resource, ok := getReclaimableThreshold(testCase.thresholds)
|
||||||
|
print(resource)
|
||||||
|
if !ok {
|
||||||
|
t.Errorf("Didn't find reclaimable threshold, test: %v", testName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseThresholdConfig(t *testing.T) {
|
func TestParseThresholdConfig(t *testing.T) {
|
||||||
gracePeriod, _ := time.ParseDuration("30s")
|
gracePeriod, _ := time.ParseDuration("30s")
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user