Skip to content

Commit 171ce3e

Browse files
authored
Improve standalone CNF component detection (#129)
Improve standalone CNF detection Signed-off-by: Peter Motičák <[email protected]>
1 parent df7319f commit 171ce3e

File tree

2 files changed

+32
-13
lines changed

2 files changed

+32
-13
lines changed

client/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import (
4242

4343
const (
4444
DefaultHTTPClientTimeout = 60 * time.Second
45+
DefaultPortGRPC = 9111
4546
DefaultPortHTTP = 9191
4647
StoneWorkServiceName = "stonework"
4748
)
@@ -231,6 +232,8 @@ func (c *Client) GetComponents() ([]Component, error) {
231232

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

235+
// TODO: Refactor rest of this function (creation and determining of component type).
236+
// Rethink standalone CNF detection.
234237
compo := &component{Metadata: metadata}
235238
msLabel, found := containsPrefix(container.Config.Env, "MICROSERVICE_LABEL=")
236239
if !found {
@@ -241,7 +244,7 @@ func (c *Client) GetComponents() ([]Component, error) {
241244
}
242245
info, ok := cnfInfos[msLabel]
243246
if !ok {
244-
client, err := vppagent.NewClientWithOpts(vppagent.WithHost(compo.Metadata["containerIPAddress"]), vppagent.WithHTTPPort(9191))
247+
client, err := vppagent.NewClientWithOpts(vppagent.WithHost(compo.Metadata["containerIPAddress"]), vppagent.WithHTTPPort(DefaultPortHTTP))
245248
if err != nil {
246249
return components, err
247250
}
@@ -254,6 +257,9 @@ func (c *Client) GetComponents() ([]Component, error) {
254257
}
255258
compo.Name = container.Config.Labels[compose.ServiceLabel]
256259
compo.Mode = ComponentStandalone
260+
compo.agentclient = client
261+
components = append(components, compo)
262+
continue
257263
}
258264
compo.Name = info.MsLabel
259265
compo.Info = &info

cmd/swctl/app/cmd_status.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,20 +203,33 @@ func printStatusTable(out io.Writer, infos []statusInfo, useColors bool) {
203203
}
204204
config := info.ConfigCounts.String()
205205
configColor := configColor(info.ConfigCounts)
206-
compoInfo := info.GetInfo()
207-
grpcState := compoInfo.GRPCConnState.String()
208-
var statusClr int
209-
// gRPC state does not make sense for StoneWork itself
210-
if info.GetMode() == client.ComponentStonework {
211-
grpcState = strings.Repeat("-", len("Status"))
212-
statusClr = tablewriter.FgHiBlackColor
206+
grpcState := strings.Repeat("-", len("Status"))
207+
statusClr := tablewriter.FgHiBlackColor
208+
var ipAddr, grpcPort, httpPort string
209+
if info.GetInfo() != nil {
210+
compoInfo := info.GetInfo()
211+
ipAddr = compoInfo.IPAddr
212+
grpcPort = strconv.Itoa(compoInfo.GRPCPort)
213+
httpPort = strconv.Itoa(compoInfo.HTTPPort)
214+
// gRPC state does not make sense for StoneWork itself
215+
if info.GetMode() != client.ComponentStonework {
216+
grpcState = compoInfo.GRPCConnState.String()
217+
statusClr = tablewriter.Normal
218+
}
219+
} else {
220+
// TODO: this is standalone cnf related, currently using default values but these should be correctly detected
221+
ipAddr = info.GetMetadata()["containerIPAddress"]
222+
grpcPort = strconv.Itoa(client.DefaultPortGRPC)
223+
httpPort = strconv.Itoa(client.DefaultPortHTTP)
213224
}
214-
row = append(row,
215-
compoInfo.IPAddr,
216-
strconv.Itoa(compoInfo.GRPCPort),
217-
strconv.Itoa(compoInfo.HTTPPort),
225+
row = append(
226+
row,
227+
ipAddr,
228+
grpcPort,
229+
httpPort,
218230
grpcState,
219-
config)
231+
config,
232+
)
220233

221234
if useColors {
222235
clrs = []tablewriter.Colors{{}, {}, {}, {}, {}, {statusClr}, {configColor}}

0 commit comments

Comments
 (0)