From b7081575f8742cddbf82b7e59c33b405882ba8af Mon Sep 17 00:00:00 2001 From: Kevin Earls Date: Tue, 6 Sep 2022 10:29:25 +0200 Subject: [PATCH] Make sure we return the right version when autoscaling v2 is found (#1075) Signed-off-by: Kevin Earls Signed-off-by: Kevin Earls --- pkg/autodetect/main.go | 6 +++--- pkg/autodetect/main_test.go | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/autodetect/main.go b/pkg/autodetect/main.go index 57d6748f6a..dc4c237363 100644 --- a/pkg/autodetect/main.go +++ b/pkg/autodetect/main.go @@ -95,7 +95,7 @@ func (a *autoDetect) HPAVersion() (AutoscalingVersion, error) { for _, version := range versions { if version.Version == "v2" || version.Version == "v2beta2" { - return toAutoscalingVersion(version.Version), nil + return ToAutoScalingVersion(version.Version), nil } } return AutoscalingVersionUnknown, errors.New("Failed to find appropriate version of apiGroup autoscaling, only v2 and v2beta2 are supported") @@ -117,10 +117,10 @@ func (v AutoscalingVersion) String() string { return "unknown" } -func toAutoscalingVersion(version string) AutoscalingVersion { +func ToAutoScalingVersion(version string) AutoscalingVersion { switch version { case "v2": - return AutoscalingVersionV2Beta2 + return AutoscalingVersionV2 case "v2beta2": return AutoscalingVersionV2Beta2 } diff --git a/pkg/autodetect/main_test.go b/pkg/autodetect/main_test.go index 42be4eba1a..eea043120a 100644 --- a/pkg/autodetect/main_test.go +++ b/pkg/autodetect/main_test.go @@ -94,3 +94,9 @@ func TestAutoscalingVersionToString(t *testing.T) { assert.Equal(t, "v2beta2", autodetect.AutoscalingVersionV2Beta2.String()) assert.Equal(t, "unknown", autodetect.AutoscalingVersionUnknown.String()) } + +func TestToAutoScalingVersion(t *testing.T) { + assert.Equal(t, autodetect.AutoscalingVersionV2, autodetect.ToAutoScalingVersion("v2")) + assert.Equal(t, autodetect.AutoscalingVersionV2Beta2, autodetect.ToAutoScalingVersion("v2beta2")) + assert.Equal(t, autodetect.AutoscalingVersionUnknown, autodetect.ToAutoScalingVersion("fred")) +}