Skip to content

Commit

Permalink
Make sure we return the right version when autoscaling v2 is found (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#1075)

Signed-off-by: Kevin Earls <[email protected]>

Signed-off-by: Kevin Earls <[email protected]>
  • Loading branch information
kevinearls authored Sep 6, 2022
1 parent 5ae67ea commit a5f268c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/autodetect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/autodetect/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

0 comments on commit a5f268c

Please sign in to comment.