From 4ce63764d40d8215b2d517c7cb34c557cc81e533 Mon Sep 17 00:00:00 2001 From: Andrew Suderman Date: Tue, 16 May 2023 13:52:43 -0600 Subject: [PATCH] Change the behavior of burstable QoS class icons and text (#592) * Replace equals logic for burstable QoS to be more clear * Fix tests * Fix test --------- Co-authored-by: Stevie <4719798+transient1@users.noreply.github.com> --- pkg/dashboard/helpers/helpers.go | 40 +++++++++++++++++------- pkg/dashboard/helpers/helpers_test.go | 29 +++++++++-------- pkg/dashboard/templates/container.gohtml | 18 ++++++----- 3 files changed, 55 insertions(+), 32 deletions(-) diff --git a/pkg/dashboard/helpers/helpers.go b/pkg/dashboard/helpers/helpers.go index 9c23162a..41071863 100644 --- a/pkg/dashboard/helpers/helpers.go +++ b/pkg/dashboard/helpers/helpers.go @@ -75,7 +75,7 @@ func GetStatus(existing resource.Quantity, recommendation resource.Quantity, sty return "" } -func GetStatusRange(existing, lower, upper resource.Quantity, style string) string { +func GetStatusRange(existing, lower, upper resource.Quantity, style string, resourceType string) string { if existing.IsZero() { switch style { case "text": @@ -89,16 +89,6 @@ func GetStatusRange(existing, lower, upper resource.Quantity, style string) stri comparisonLower := existing.Cmp(lower) comparisonUpper := existing.Cmp(upper) - if comparisonUpper <= 0 && comparisonLower >= 0 { - switch style { - case "text": - return "equal" - case "icon": - return "fa-equals success" - default: - return "" - } - } if comparisonLower < 0 { switch style { @@ -118,6 +108,34 @@ func GetStatusRange(existing, lower, upper resource.Quantity, style string) stri } } + switch resourceType { + case "request": + if comparisonLower == 0 { + switch style { + case "text": + return "equal" + case "icon": + return "fa-equals success" + } + } + case "limit": + if comparisonUpper == 0 { + switch style { + case "text": + return "equal" + case "icon": + return "fa-equals success" + } + } + } + + switch style { + case "text": + return "not equal" + case "icon": + return "fa-exclamation error" + } + return "" } diff --git a/pkg/dashboard/helpers/helpers_test.go b/pkg/dashboard/helpers/helpers_test.go index 31c5ee96..d0314ffb 100644 --- a/pkg/dashboard/helpers/helpers_test.go +++ b/pkg/dashboard/helpers/helpers_test.go @@ -152,10 +152,11 @@ func Test_GetStatus(t *testing.T) { func Test_GetStatusRange(t *testing.T) { type args struct { - existing resource.Quantity - lower resource.Quantity - upper resource.Quantity - style string + existing resource.Quantity + lower resource.Quantity + upper resource.Quantity + resourceType string + style string } tests := []struct { name string @@ -205,20 +206,22 @@ func Test_GetStatusRange(t *testing.T) { { name: "text equal", args: args{ - existing: *resource.NewMilliQuantity(50, resource.DecimalSI), - lower: *resource.NewMilliQuantity(25, resource.DecimalSI), - upper: *resource.NewMilliQuantity(75, resource.DecimalSI), - style: "text", + existing: *resource.NewMilliQuantity(25, resource.DecimalSI), + lower: *resource.NewMilliQuantity(25, resource.DecimalSI), + upper: *resource.NewMilliQuantity(75, resource.DecimalSI), + resourceType: "request", + style: "text", }, want: "equal", }, { name: "icon equal", args: args{ - existing: *resource.NewMilliQuantity(50, resource.DecimalSI), - lower: *resource.NewMilliQuantity(25, resource.DecimalSI), - upper: *resource.NewMilliQuantity(75, resource.DecimalSI), - style: "icon", + existing: *resource.NewMilliQuantity(25, resource.DecimalSI), + lower: *resource.NewMilliQuantity(25, resource.DecimalSI), + upper: *resource.NewMilliQuantity(75, resource.DecimalSI), + resourceType: "request", + style: "icon", }, want: "fa-equals success", }, @@ -245,7 +248,7 @@ func Test_GetStatusRange(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := GetStatusRange(tt.args.existing, tt.args.lower, tt.args.upper, tt.args.style) + got := GetStatusRange(tt.args.existing, tt.args.lower, tt.args.upper, tt.args.style, tt.args.resourceType) assert.Equal(t, got, tt.want) }) } diff --git a/pkg/dashboard/templates/container.gohtml b/pkg/dashboard/templates/container.gohtml index cb747beb..687c4db4 100644 --- a/pkg/dashboard/templates/container.gohtml +++ b/pkg/dashboard/templates/container.gohtml @@ -14,6 +14,8 @@ {{ $icon := "icon"}} {{ $text := "text" }} +{{ $request := "request" }} +{{ $limit := "limit" }} {{ $uuid := getUUID }}
@@ -139,9 +141,9 @@ - {{ getStatusRange $cpuRequest $cpuLowerBound $cpuUpperBound $text }} + {{ getStatusRange $cpuRequest $cpuLowerBound $cpuUpperBound $text $request}} {{ printResource $cpuLowerBound }} @@ -152,9 +154,9 @@ - {{ getStatusRange $cpuLimit $cpuLowerBound $cpuUpperBound $text }} + {{ getStatusRange $cpuLimit $cpuLowerBound $cpuUpperBound $text $limit }} {{ printResource $cpuUpperBound }} @@ -165,9 +167,9 @@ - {{ getStatusRange $memRequest $memLowerBound $memUpperBound $text }} + {{ getStatusRange $memRequest $memLowerBound $memUpperBound $text $limit }} {{ printResource $memLowerBound }} @@ -178,9 +180,9 @@ - {{ getStatusRange $memLimit $memLowerBound $memUpperBound $text }} + {{ getStatusRange $memLimit $memLowerBound $memUpperBound $text $limit }} {{ printResource $memUpperBound }}