Skip to content

Commit

Permalink
Change the behavior of burstable QoS class icons and text (#592)
Browse files Browse the repository at this point in the history
* Replace equals logic for burstable QoS to be more clear

* Fix tests

* Fix test

---------

Co-authored-by: Stevie <[email protected]>
  • Loading branch information
sudermanjr and transient1 committed May 16, 2023
1 parent fe9dea6 commit 4ce6376
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 32 deletions.
40 changes: 29 additions & 11 deletions pkg/dashboard/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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 {
Expand All @@ -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 ""
}

Expand Down
29 changes: 16 additions & 13 deletions pkg/dashboard/helpers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
Expand All @@ -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)
})
}
Expand Down
18 changes: 10 additions & 8 deletions pkg/dashboard/templates/container.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

{{ $icon := "icon"}}
{{ $text := "text" }}
{{ $request := "request" }}
{{ $limit := "limit" }}
{{ $uuid := getUUID }}

<section class="detailInfo --qos verticalRhythm">
Expand Down Expand Up @@ -139,9 +141,9 @@
<td>
<i
aria-hidden="true"
class="compTable__compIcon fas {{ getStatusRange $cpuRequest $cpuLowerBound $cpuUpperBound $icon }}"
class="compTable__compIcon fas {{ getStatusRange $cpuRequest $cpuLowerBound $cpuUpperBound $icon $request}}"
></i>
<span class="visually-hidden">{{ getStatusRange $cpuRequest $cpuLowerBound $cpuUpperBound $text }}</span>
<span class="visually-hidden">{{ getStatusRange $cpuRequest $cpuLowerBound $cpuUpperBound $text $request}}</span>
</td>
<td>{{ printResource $cpuLowerBound }}</td>
</tr>
Expand All @@ -152,9 +154,9 @@
<td>
<i
aria-hidden="true"
class="compTable__compIcon fas {{ getStatusRange $cpuLimit $cpuLowerBound $cpuUpperBound $icon }}"
class="compTable__compIcon fas {{ getStatusRange $cpuLimit $cpuLowerBound $cpuUpperBound $icon $limit }}"
></i>
<span class="visually-hidden">{{ getStatusRange $cpuLimit $cpuLowerBound $cpuUpperBound $text }}</span>
<span class="visually-hidden">{{ getStatusRange $cpuLimit $cpuLowerBound $cpuUpperBound $text $limit }}</span>
</td>
<td>{{ printResource $cpuUpperBound }}</td>
</tr>
Expand All @@ -165,9 +167,9 @@
<td>
<i
aria-hidden="true"
class="compTable__compIcon fas {{ getStatusRange $memRequest $memLowerBound $memUpperBound $icon }}"
class="compTable__compIcon fas {{ getStatusRange $memRequest $memLowerBound $memUpperBound $icon $request }}"
></i>
<span class="visually-hidden">{{ getStatusRange $memRequest $memLowerBound $memUpperBound $text }}</span>
<span class="visually-hidden">{{ getStatusRange $memRequest $memLowerBound $memUpperBound $text $limit }}</span>
</td>
<td>{{ printResource $memLowerBound }}</td>
</tr>
Expand All @@ -178,9 +180,9 @@
<td>
<i
aria-hidden="true"
class="compTable__compIcon fas {{ getStatusRange $memLimit $memLowerBound $memUpperBound $icon }}"
class="compTable__compIcon fas {{ getStatusRange $memLimit $memLowerBound $memUpperBound $icon $limit }}"
></i>
<span class="visually-hidden">{{ getStatusRange $memLimit $memLowerBound $memUpperBound $text }}</span>
<span class="visually-hidden">{{ getStatusRange $memLimit $memLowerBound $memUpperBound $text $limit }}</span>
</td>
<td>{{ printResource $memUpperBound }}</td>
</tr>
Expand Down

0 comments on commit 4ce6376

Please sign in to comment.