Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kubelet: eviction: allow minimum reclaim as percentage #33392

Merged
merged 1 commit into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/kubelet/eviction/eviction_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,9 @@ func TestMinReclaim(t *testing.T) {
Value: ThresholdValue{
Quantity: quantityMustParse("1Gi"),
},
MinReclaim: quantityMustParse("500Mi"),
MinReclaim: &ThresholdValue{
Quantity: quantityMustParse("500Mi"),
},
},
},
}
Expand Down Expand Up @@ -788,7 +790,9 @@ func TestNodeReclaimFuncs(t *testing.T) {
Value: ThresholdValue{
Quantity: quantityMustParse("1Gi"),
},
MinReclaim: quantityMustParse("500Mi"),
MinReclaim: &ThresholdValue{
Quantity: quantityMustParse("500Mi"),
},
},
},
}
Expand Down
31 changes: 26 additions & 5 deletions pkg/kubelet/eviction/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,21 +256,40 @@ func parseGracePeriods(expr string) (map[Signal]time.Duration, error) {
}

// parseMinimumReclaims parses the minimum reclaim statements
func parseMinimumReclaims(expr string) (map[Signal]resource.Quantity, error) {
func parseMinimumReclaims(expr string) (map[Signal]ThresholdValue, error) {
if len(expr) == 0 {
return nil, nil
}
results := map[Signal]resource.Quantity{}
results := map[Signal]ThresholdValue{}
statements := strings.Split(expr, ",")
for _, statement := range statements {
parts := strings.Split(statement, "=")
if len(parts) != 2 {
return nil, fmt.Errorf("invalid eviction minimum reclaim syntax: %v, expected <signal>=<quantity>", statement)
return nil, fmt.Errorf("invalid eviction minimum reclaim syntax: %v, expected <signal>=<value>", statement)
}
signal := Signal(parts[0])
if !validSignal(signal) {
return nil, fmt.Errorf(unsupportedEvictionSignal, signal)
}

quantityValue := parts[1]
if strings.HasSuffix(quantityValue, "%") {
percentage, err := parsePercentage(quantityValue)
if err != nil {
return nil, err
}
if percentage <= 0 {
return nil, fmt.Errorf("eviction percentage minimum reclaim %v must be positive: %s", signal, quantityValue)
}
// check against duplicate statements
if _, found := results[signal]; found {
return nil, fmt.Errorf("duplicate eviction minimum reclaim specified for %v", signal)
}
results[signal] = ThresholdValue{
Percentage: percentage,
}
continue
}
// check against duplicate statements
if _, found := results[signal]; found {
return nil, fmt.Errorf("duplicate eviction minimum reclaim specified for %v", signal)
Expand All @@ -282,7 +301,9 @@ func parseMinimumReclaims(expr string) (map[Signal]resource.Quantity, error) {
if err != nil {
return nil, err
}
results[signal] = quantity
results[signal] = ThresholdValue{
Quantity: &quantity,
}
}
return results, nil
}
Expand Down Expand Up @@ -650,7 +671,7 @@ func thresholdsMet(thresholds []Threshold, observations signalObservations, enfo
quantity := getThresholdQuantity(threshold.Value, observed.capacity)
// if enforceMinReclaim is specified, we compare relative to value - minreclaim
if enforceMinReclaim && threshold.MinReclaim != nil {
quantity.Add(*threshold.MinReclaim)
quantity.Add(*getThresholdQuantity(*threshold.MinReclaim, observed.capacity))
}
thresholdResult := quantity.Cmp(*observed.available)
switch threshold.Operator {
Expand Down