Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve standalone CNF component detection #129

Merged
merged 1 commit into from
Sep 21, 2023
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
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