mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Fix kubelet to not accept negative eviction (hard, soft) thresholds
and add unit tests
This commit is contained in:
parent
03fe6b962c
commit
cb7766de19
@ -157,6 +157,10 @@ func parseThresholdStatement(statement string) (Threshold, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Threshold{}, err
|
return Threshold{}, err
|
||||||
}
|
}
|
||||||
|
if quantity.Sign() < 0 {
|
||||||
|
return Threshold{}, fmt.Errorf("eviction threshold %v cannot be negative: %s", signal, &quantity)
|
||||||
|
}
|
||||||
|
|
||||||
return Threshold{
|
return Threshold{
|
||||||
Signal: signal,
|
Signal: signal,
|
||||||
Operator: operator,
|
Operator: operator,
|
||||||
|
@ -83,6 +83,22 @@ func TestParseThresholdConfig(t *testing.T) {
|
|||||||
expectErr: true,
|
expectErr: true,
|
||||||
expectThresholds: []Threshold{},
|
expectThresholds: []Threshold{},
|
||||||
},
|
},
|
||||||
|
"hard-signal-negative": {
|
||||||
|
evictionHard: "memory.available<-150Mi",
|
||||||
|
evictionSoft: "",
|
||||||
|
evictionSoftGracePeriod: "",
|
||||||
|
evictionMinReclaim: "",
|
||||||
|
expectErr: true,
|
||||||
|
expectThresholds: []Threshold{},
|
||||||
|
},
|
||||||
|
"soft-signal-negative": {
|
||||||
|
evictionHard: "",
|
||||||
|
evictionSoft: "memory.available<-150Mi",
|
||||||
|
evictionSoftGracePeriod: "",
|
||||||
|
evictionMinReclaim: "",
|
||||||
|
expectErr: true,
|
||||||
|
expectThresholds: []Threshold{},
|
||||||
|
},
|
||||||
"duplicate-signal": {
|
"duplicate-signal": {
|
||||||
evictionHard: "memory.available<150Mi,memory.available<100Mi",
|
evictionHard: "memory.available<150Mi,memory.available<100Mi",
|
||||||
evictionSoft: "",
|
evictionSoft: "",
|
||||||
|
Loading…
Reference in New Issue
Block a user