From 171ce3eebc896ffc825953951f76bf66d43f5e24 Mon Sep 17 00:00:00 2001 From: pemoticak <109155041+pemoticak@users.noreply.github.com> Date: Thu, 21 Sep 2023 19:30:00 +0200 Subject: [PATCH] Improve standalone CNF component detection (#129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improve standalone CNF detection Signed-off-by: Peter Motičák --- client/client.go | 8 +++++++- cmd/swctl/app/cmd_status.go | 37 +++++++++++++++++++++++++------------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/client/client.go b/client/client.go index 02c40f07..3ce7ae02 100644 --- a/client/client.go +++ b/client/client.go @@ -42,6 +42,7 @@ import ( const ( DefaultHTTPClientTimeout = 60 * time.Second + DefaultPortGRPC = 9111 DefaultPortHTTP = 9191 StoneWorkServiceName = "stonework" ) @@ -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 { @@ -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 } @@ -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 diff --git a/cmd/swctl/app/cmd_status.go b/cmd/swctl/app/cmd_status.go index b8bdf908..a5f50c72 100644 --- a/cmd/swctl/app/cmd_status.go +++ b/cmd/swctl/app/cmd_status.go @@ -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}}