Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 2 additions & 26 deletions internal/cmd/load-balancer/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"
"strings"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -161,36 +159,14 @@ func renderListeners(listeners []loadbalancer.Listener) string {
listener := listeners[i]
table.AddRow(*listener.Name, *listener.Port, *listener.Protocol, *listener.TargetPool)
}

return table.Render()
}

func renderTargetPools(targetPools []loadbalancer.TargetPool) string {
table := tables.NewTable()
table.SetHeader("TARGET POOL NAME", "PORT", "TARGETS", "SESSION PERSISTENCE", "HEALTH CHECK INTERVAL (S)", "DOWN AFTER (CHECKS)", "UP AFTER (CHECKS)")
table.SetHeader("TARGET POOL NAME", "PORT", "TARGETS")
for _, targetPool := range targetPools {
var targetsArray []string
for _, t := range *targetPool.Targets {
targetsArray = append(targetsArray, fmt.Sprintf("%s (%s)", *t.DisplayName, *t.Ip))
}
targets := strings.Join(targetsArray, "\n")

sessionPersistence := "None"
if targetPool.SessionPersistence != nil && targetPool.SessionPersistence.UseSourceIpAddress != nil && *targetPool.SessionPersistence.UseSourceIpAddress {
sessionPersistence = "Use Source IP"
}

healthCheckInterval := "-"
healthCheckUnhealthyThreshold := "-"
healthCheckHealthyThreshold := "-"
if targetPool.ActiveHealthCheck != nil {
healthCheckInterval = *targetPool.ActiveHealthCheck.Interval
healthCheckUnhealthyThreshold = strconv.FormatInt(*targetPool.ActiveHealthCheck.UnhealthyThreshold, 10)
healthCheckHealthyThreshold = strconv.FormatInt(*targetPool.ActiveHealthCheck.HealthyThreshold, 10)
}

table.AddRow(*targetPool.Name, *targetPool.TargetPort, targets, sessionPersistence, healthCheckInterval, healthCheckUnhealthyThreshold, healthCheckHealthyThreshold)
table.AddRow(*targetPool.Name, *targetPool.TargetPort, len(*targetPool.Targets))
}

return table.Render()
}
5 changes: 3 additions & 2 deletions internal/cmd/load-balancer/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
if err != nil {
return fmt.Errorf("get load balancers: %w", err)
}
loadBalancers := *resp.LoadBalancers
if len(loadBalancers) == 0 {

if resp.LoadBalancers == nil || (resp.LoadBalancers != nil && len(*resp.LoadBalancers) == 0) {
projectLabel, err := projectname.GetProjectName(ctx, p, cmd)
if err != nil {
p.Debug(print.ErrorLevel, "get project name: %v", err)
Expand All @@ -75,6 +75,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
return nil
}

loadBalancers := *resp.LoadBalancers
// Truncate output
if model.Limit != nil && len(loadBalancers) > int(*model.Limit) {
loadBalancers = loadBalancers[:*model.Limit]
Expand Down