From cb7766de19bd7c38c771e8348228b42823a6a640 Mon Sep 17 00:00:00 2001 From: Avesh Agarwal Date: Tue, 26 Jul 2016 11:39:30 -0400 Subject: [PATCH] Fix kubelet to not accept negative eviction (hard, soft) thresholds and add unit tests --- pkg/kubelet/eviction/helpers.go | 4 ++++ pkg/kubelet/eviction/helpers_test.go | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pkg/kubelet/eviction/helpers.go b/pkg/kubelet/eviction/helpers.go index b9d5a4f196b..d10831339cc 100644 --- a/pkg/kubelet/eviction/helpers.go +++ b/pkg/kubelet/eviction/helpers.go @@ -157,6 +157,10 @@ func parseThresholdStatement(statement string) (Threshold, error) { if err != nil { return Threshold{}, err } + if quantity.Sign() < 0 { + return Threshold{}, fmt.Errorf("eviction threshold %v cannot be negative: %s", signal, &quantity) + } + return Threshold{ Signal: signal, Operator: operator, diff --git a/pkg/kubelet/eviction/helpers_test.go b/pkg/kubelet/eviction/helpers_test.go index 121fae5c8fc..b57b1842771 100644 --- a/pkg/kubelet/eviction/helpers_test.go +++ b/pkg/kubelet/eviction/helpers_test.go @@ -83,6 +83,22 @@ func TestParseThresholdConfig(t *testing.T) { expectErr: true, 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": { evictionHard: "memory.available<150Mi,memory.available<100Mi", evictionSoft: "",