Skip to content

Commit

Permalink
Improve standalone CNF component detection (#129)
Browse files Browse the repository at this point in the history
Improve standalone CNF detection

Signed-off-by: Peter Motičák <[email protected]>
  • Loading branch information
pemoticak authored Sep 21, 2023
1 parent df7319f commit 171ce3e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
8 changes: 7 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (

const (
DefaultHTTPClientTimeout = 60 * time.Second
DefaultPortGRPC = 9111
DefaultPortHTTP = 9191
StoneWorkServiceName = "stonework"
)
Expand Down Expand Up @@ -231,6 +232,8 @@ func (c *Client) GetComponents() ([]Component, error) {

logrus.Tracef("found metadata for container: %s, data: %+v", container.Name, metadata)

// TODO: Refactor rest of this function (creation and determining of component type).
// Rethink standalone CNF detection.
compo := &component{Metadata: metadata}
msLabel, found := containsPrefix(container.Config.Env, "MICROSERVICE_LABEL=")
if !found {
Expand All @@ -241,7 +244,7 @@ func (c *Client) GetComponents() ([]Component, error) {
}
info, ok := cnfInfos[msLabel]
if !ok {
client, err := vppagent.NewClientWithOpts(vppagent.WithHost(compo.Metadata["containerIPAddress"]), vppagent.WithHTTPPort(9191))
client, err := vppagent.NewClientWithOpts(vppagent.WithHost(compo.Metadata["containerIPAddress"]), vppagent.WithHTTPPort(DefaultPortHTTP))
if err != nil {
return components, err
}
Expand All @@ -254,6 +257,9 @@ func (c *Client) GetComponents() ([]Component, error) {
}
compo.Name = container.Config.Labels[compose.ServiceLabel]
compo.Mode = ComponentStandalone
compo.agentclient = client
components = append(components, compo)
continue
}
compo.Name = info.MsLabel
compo.Info = &info
Expand Down
37 changes: 25 additions & 12 deletions cmd/swctl/app/cmd_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,33 @@ func printStatusTable(out io.Writer, infos []statusInfo, useColors bool) {
}
config := info.ConfigCounts.String()
configColor := configColor(info.ConfigCounts)
compoInfo := info.GetInfo()
grpcState := compoInfo.GRPCConnState.String()
var statusClr int
// gRPC state does not make sense for StoneWork itself
if info.GetMode() == client.ComponentStonework {
grpcState = strings.Repeat("-", len("Status"))
statusClr = tablewriter.FgHiBlackColor
grpcState := strings.Repeat("-", len("Status"))
statusClr := tablewriter.FgHiBlackColor
var ipAddr, grpcPort, httpPort string
if info.GetInfo() != nil {
compoInfo := info.GetInfo()
ipAddr = compoInfo.IPAddr
grpcPort = strconv.Itoa(compoInfo.GRPCPort)
httpPort = strconv.Itoa(compoInfo.HTTPPort)
// gRPC state does not make sense for StoneWork itself
if info.GetMode() != client.ComponentStonework {
grpcState = compoInfo.GRPCConnState.String()
statusClr = tablewriter.Normal
}
} else {
// TODO: this is standalone cnf related, currently using default values but these should be correctly detected
ipAddr = info.GetMetadata()["containerIPAddress"]
grpcPort = strconv.Itoa(client.DefaultPortGRPC)
httpPort = strconv.Itoa(client.DefaultPortHTTP)
}
row = append(row,
compoInfo.IPAddr,
strconv.Itoa(compoInfo.GRPCPort),
strconv.Itoa(compoInfo.HTTPPort),
row = append(
row,
ipAddr,
grpcPort,
httpPort,
grpcState,
config)
config,
)

if useColors {
clrs = []tablewriter.Colors{{}, {}, {}, {}, {}, {statusClr}, {configColor}}
Expand Down

0 comments on commit 171ce3e

Please sign in to comment.