From 237757a5d2d15c5248d235313307717e8782bc1c Mon Sep 17 00:00:00 2001 From: Aya Igarashi Date: Thu, 25 Feb 2021 15:18:20 +0900 Subject: [PATCH] Do not set limits when recommendation is 0 --- .../pkg/utils/vpa/limit_and_request_scaling.go | 4 ++++ .../pkg/utils/vpa/limit_and_request_scaling_test.go | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling.go b/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling.go index fd4dd52f1c21..9bcfe65fcd72 100644 --- a/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling.go +++ b/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling.go @@ -70,6 +70,10 @@ func getProportionalResourceLimit(resourceName core.ResourceName, originalLimit, if originalLimit == nil || originalLimit.Value() == 0 { return nil, "" } + // recommendedRequest not set, don't set limit. + if recommendedRequest == nil || recommendedRequest.Value() == 0 { + return nil, "" + } // originalLimit set but originalRequest not set - K8s will treat the pod as if they were equal, // recommend limit equal to request if originalRequest == nil || originalRequest.Value() == 0 { diff --git a/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling_test.go b/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling_test.go index c334279c6a4a..43dc9b222eee 100644 --- a/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling_test.go +++ b/vertical-pod-autoscaler/pkg/utils/vpa/limit_and_request_scaling_test.go @@ -67,6 +67,13 @@ func TestGetProportionalResourceLimit(t *testing.T) { recommendedRequest: mustParseToPointer("10"), expectLimit: mustParseToPointer("10"), }, + { + name: "no recommendation", + originalRequest: mustParseToPointer("1"), + recommendedRequest: mustParseToPointer("0"), + defaultLimit: mustParseToPointer("2"), + expectLimit: nil, + }, { name: "limit equal to request", originalLimit: mustParseToPointer("1"),