Skip to content

Commit

Permalink
cmd/service: unify service list/get output
Browse files Browse the repository at this point in the history
Previously `cilium service get` command did not show the state
of each backend.

This commit unifies the outputs to use a single function where
the formatting is defined.

Signed-off-by: Ondrej Blazek <ondrej.blazek@firma.seznam.cz>
  • Loading branch information
oblazek authored and borkmann committed Mar 6, 2023
1 parent db5211f commit e9eb17e
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions cilium/cmd/service_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
package cmd

import (
"fmt"
"os"
"strconv"
"text/tabwriter"

"github.com/spf13/cobra"

"github.com/cilium/cilium/api/v1/models"
"github.com/cilium/cilium/pkg/command"
"github.com/cilium/cilium/pkg/loadbalancer"
)

// serviceGetCmd represents the service_get command
Expand All @@ -34,31 +34,15 @@ var serviceGetCmd = &cobra.Command{
Fatalf("Cannot get service '%v': empty response\n", id)
}

slice := []string{}
for _, be := range svc.Status.Realized.BackendAddresses {
if bea, err := loadbalancer.NewL3n4AddrFromBackendModel(be); err != nil {
slice = append(slice, fmt.Sprintf("invalid backend: %+v", be))
} else {
slice = append(slice, bea.String())
}
}

if command.OutputOption() {
if err := command.PrintOutput(svc); err != nil {
os.Exit(1)
}
return
}

if fea, err := loadbalancer.NewL3n4AddrFromModel(svc.Status.Realized.FrontendAddress); err != nil {
fmt.Fprintf(os.Stderr, "invalid frontend model: %s", err)
} else {
fmt.Printf("%s =>\n", fea.String())
}

for i, be := range slice {
fmt.Printf("\t\t%d => %s (%d)\n", i+1, be, svc.Status.Realized.ID)
}
w := tabwriter.NewWriter(os.Stdout, 5, 0, 3, ' ', 0)
printServiceList(w, []*models.Service{svc})
},
}

Expand Down

0 comments on commit e9eb17e

Please sign in to comment.