Skip to content

Commit 24ee07a

Browse files
Fixes to lb list and describe (#265)
* Fixes to lb list and describe * Add separator * Remove columns * Remove separators * remove separator
1 parent d30ce0a commit 24ee07a

2 files changed

Lines changed: 5 additions & 28 deletions

File tree

internal/cmd/load-balancer/describe/describe.go

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import (
44
"context"
55
"encoding/json"
66
"fmt"
7-
"strconv"
8-
"strings"
97

108
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
119
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
@@ -161,36 +159,14 @@ func renderListeners(listeners []loadbalancer.Listener) string {
161159
listener := listeners[i]
162160
table.AddRow(*listener.Name, *listener.Port, *listener.Protocol, *listener.TargetPool)
163161
}
164-
165162
return table.Render()
166163
}
167164

168165
func renderTargetPools(targetPools []loadbalancer.TargetPool) string {
169166
table := tables.NewTable()
170-
table.SetHeader("TARGET POOL NAME", "PORT", "TARGETS", "SESSION PERSISTENCE", "HEALTH CHECK INTERVAL (S)", "DOWN AFTER (CHECKS)", "UP AFTER (CHECKS)")
167+
table.SetHeader("TARGET POOL NAME", "PORT", "TARGETS")
171168
for _, targetPool := range targetPools {
172-
var targetsArray []string
173-
for _, t := range *targetPool.Targets {
174-
targetsArray = append(targetsArray, fmt.Sprintf("%s (%s)", *t.DisplayName, *t.Ip))
175-
}
176-
targets := strings.Join(targetsArray, "\n")
177-
178-
sessionPersistence := "None"
179-
if targetPool.SessionPersistence != nil && targetPool.SessionPersistence.UseSourceIpAddress != nil && *targetPool.SessionPersistence.UseSourceIpAddress {
180-
sessionPersistence = "Use Source IP"
181-
}
182-
183-
healthCheckInterval := "-"
184-
healthCheckUnhealthyThreshold := "-"
185-
healthCheckHealthyThreshold := "-"
186-
if targetPool.ActiveHealthCheck != nil {
187-
healthCheckInterval = *targetPool.ActiveHealthCheck.Interval
188-
healthCheckUnhealthyThreshold = strconv.FormatInt(*targetPool.ActiveHealthCheck.UnhealthyThreshold, 10)
189-
healthCheckHealthyThreshold = strconv.FormatInt(*targetPool.ActiveHealthCheck.HealthyThreshold, 10)
190-
}
191-
192-
table.AddRow(*targetPool.Name, *targetPool.TargetPort, targets, sessionPersistence, healthCheckInterval, healthCheckUnhealthyThreshold, healthCheckHealthyThreshold)
169+
table.AddRow(*targetPool.Name, *targetPool.TargetPort, len(*targetPool.Targets))
193170
}
194-
195171
return table.Render()
196172
}

internal/cmd/load-balancer/list/list.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
6464
if err != nil {
6565
return fmt.Errorf("get load balancers: %w", err)
6666
}
67-
loadBalancers := *resp.LoadBalancers
68-
if len(loadBalancers) == 0 {
67+
68+
if resp.LoadBalancers == nil || (resp.LoadBalancers != nil && len(*resp.LoadBalancers) == 0) {
6969
projectLabel, err := projectname.GetProjectName(ctx, p, cmd)
7070
if err != nil {
7171
p.Debug(print.ErrorLevel, "get project name: %v", err)
@@ -75,6 +75,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
7575
return nil
7676
}
7777

78+
loadBalancers := *resp.LoadBalancers
7879
// Truncate output
7980
if model.Limit != nil && len(loadBalancers) > int(*model.Limit) {
8081
loadBalancers = loadBalancers[:*model.Limit]

0 commit comments

Comments
 (0)