Skip to content

Commit

Permalink
Initial variant for support command (included docker inspect) (#107)
Browse files Browse the repository at this point in the history
Initial variant for support command

include agentctl data into zip file

add agentctl info for each docker container

Signed-off-by: mykola <[email protected]>

add docker logs

Signed-off-by: mykola <[email protected]>

add docker ps

Signed-off-by: mykola <[email protected]>

add docker inspect & replace inner zip files with directories

Signed-off-by: Daniel Béreš <[email protected]>

* update vpp-agent dependency

Signed-off-by: Daniel Béreš <[email protected]>

* - fix error handling
- delete commented code
- sort imports

Signed-off-by: Daniel Béreš <[email protected]>

* Change support errors behaviour &&
fixing modified time on files inside zip

Signed-off-by: Daniel Béreš <[email protected]>

* handle stat error

Signed-off-by: Daniel Béreš <[email protected]>

---------

Signed-off-by: Daniel Béreš <[email protected]>
Co-authored-by: mykola <[email protected]>
Co-authored-by: Daniel Béreš <[email protected]>
Co-authored-by: pemoticak <[email protected]>
  • Loading branch information
4 people authored Aug 17, 2023
1 parent 28bf8d8 commit b3cd960
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 21 deletions.
43 changes: 29 additions & 14 deletions cmd/swctl/cmd_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ func runStatusCmd(cli Cli, opts StatusOptions) error {
return nil
}

infos, err := getStatusInfo(resp)
if err != nil {
return err
}

if opts.Format == "" {
printStatusTable(cli.Out(), infos, true)
} else {
if err := formatAsTemplate(cli.Out(), opts.Format, infos); err != nil {
return err
}
}
return nil
}

func getStatusInfo(components []client.Component) ([]statusInfo, error) {
type infoWithErr struct {
statusInfo
error
Expand All @@ -108,11 +124,12 @@ func runStatusCmd(cli Cli, opts StatusOptions) error {
var wg sync.WaitGroup
infoCh := make(chan infoWithErr)

for _, compo := range resp {
for _, compo := range components {
wg.Add(1)
go func(compo client.Component) {
defer wg.Done()
var counts *client.ConfigCounts
var err error
if compo.GetMode() != client.ComponentAuxiliary {
counts, err = compo.ConfigStatus()
if err != nil {
Expand All @@ -135,19 +152,12 @@ func runStatusCmd(cli Cli, opts StatusOptions) error {

for i := range infoCh {
if i.error != nil {
return i.error
return nil, i.error
}
infos = append(infos, i.statusInfo)
}
slices.SortFunc(infos, cmpStatus)
if opts.Format == "" {
printStatusTable(cli.Out(), infos)
} else {
if err := formatAsTemplate(cli.Out(), opts.Format, infos); err != nil {
return err
}
}
return nil
return infos, nil
}

func cmpStatus(a, b statusInfo) bool {
Expand All @@ -158,7 +168,7 @@ func cmpStatus(a, b statusInfo) bool {
return greater
}

func printStatusTable(out io.Writer, infos []statusInfo) {
func printStatusTable(out io.Writer, infos []statusInfo, useColors bool) {
table := tablewriter.NewWriter(out)
header := []string{
"Name", "Mode", "IP Address", "GRPC Port", "HTTP Port", "Status", "Configuration",
Expand All @@ -182,7 +192,9 @@ func printStatusTable(out io.Writer, infos []statusInfo) {
if info.GetMode() == client.ComponentAuxiliary {
clrs = []tablewriter.Colors{{}, {}}
for i := range header[2:] {
clrs = append(clrs, []int{tablewriter.FgHiBlackColor})
if useColors {
clrs = append(clrs, []int{tablewriter.FgHiBlackColor})
}
row = append(row, strings.Repeat("-", len(header[i+2])))
}
table.Rich(row, clrs)
Expand All @@ -204,8 +216,11 @@ func printStatusTable(out io.Writer, infos []statusInfo) {
strconv.Itoa(compoInfo.HTTPPort),
grpcState,
config)
clrs = []tablewriter.Colors{
{}, {}, {}, {}, {}, {statusClr}, {configColor},

if useColors {
clrs = []tablewriter.Colors{{}, {}, {}, {}, {}, {statusClr}, {configColor}}
} else {
clrs = []tablewriter.Colors{}
}
table.Rich(row, clrs)
}
Expand Down
Loading

0 comments on commit b3cd960

Please sign in to comment.