Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2438 from tylerslaton/fix-cc-tables
Browse files Browse the repository at this point in the history
fix: address issue with computeclass tables not converting properly
  • Loading branch information
tylerslaton authored Jan 19, 2024
2 parents e46d866 + d1c52e7 commit 7083bc6
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions pkg/cli/builder/table/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,46 +272,58 @@ func DisplayRange(minVal, maxVal any) (string, error) {
}

func DefaultMemory(obj any) (string, error) {
b, ok := obj.(adminv1.ComputeClassMemory)
if !ok {
return "", fmt.Errorf("object passed is not a ComputeClassMemory struct")
switch b := obj.(type) {
case apiv1.ComputeClassMemory:
return defaultMemory(b.Default, b.Max), nil
case adminv1.ComputeClassMemory:
return defaultMemory(b.Default, b.Max), nil
default:
return "", fmt.Errorf("object passed cannot be converted into a ComputeClassMemory struct")
}
}

result := b.Default
if b.Default == "0" || b.Default == "" {
result = b.Max
func defaultMemory(def, max string) string {
result := def
if def == "0" || def == "" {
result = max
if result == "0" || result == "" {
result = "Unrestricted"
}
}
return result, nil
return result
}

func MemoryToRange(obj any) (string, error) {
b, ok := obj.(adminv1.ComputeClassMemory)
if !ok {
return "", fmt.Errorf("object passed is not a ComputeClassMemory struct")
switch b := obj.(type) {
case apiv1.ComputeClassMemory:
return memoryToRange(b.Min, b.Max, b.Values), nil
case adminv1.ComputeClassMemory:
return memoryToRange(b.Min, b.Max, b.Values), nil
default:
return "", fmt.Errorf("object passed cannot be converted into a ComputeClassMemory struct")
}
}

min := b.Min
if min == "" {
min = "0"
func memoryToRange(memoryMin, memoryMax string, values []string) string {
if len(values) != 0 {
return strings.Join(values, ",")
}

max := b.Max
if max == "" || max == "0" {
max = "Unrestricted"
rangeMin := memoryMin
if rangeMin == "" {
rangeMin = "0"
}

if len(b.Values) != 0 {
return strings.Join(b.Values, ","), nil
rangeMax := memoryMax
if rangeMax == "" || rangeMax == "0" {
rangeMax = "Unrestricted"
}

if max == "Unrestricted" && min == "0" {
return "Unrestricted", nil
if rangeMin == "0" && rangeMax == "Unrestricted" {
return "Unrestricted"
}

return fmt.Sprintf("%v-%v", min, max), nil
return fmt.Sprintf("%v-%v", rangeMin, rangeMax)
}

func AppGeneration(app apiv1.App, msg string) string {
Expand Down

0 comments on commit 7083bc6

Please sign in to comment.