Skip to content

Commit f3cbfbe

Browse files
authored
Add more stringers to print data structures. Also print raw json from l2discovery. (#8)
1 parent 9277f6a commit f3cbfbe

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ linters:
5151
- dogsled
5252
- errcheck
5353
- exhaustive
54-
- exportloopref
5554
- funlen
5655
- goconst
5756
- gocritic

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
GOLANGCI_VERSION=v1.53.2
22

3-
.PHONY: all clean test build
3+
.PHONY: all clean test build lint install-lint vet fmt
4+
5+
fmt:
6+
go fmt ./...
47

58
lint:
69
golangci-lint run

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.22
44

55
require (
66
github.com/pkg/errors v0.9.1
7-
github.com/redhat-cne/l2discovery-exports v0.0.4
7+
github.com/redhat-cne/l2discovery-exports v0.0.6
88
github.com/redhat-cne/privileged-daemonset v1.0.34
99
github.com/sirupsen/logrus v1.9.3
1010
github.com/yourbasic/graph v0.0.0-20210606180040-8ecfec1c2869

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
6262
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
6363
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
6464
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
65-
github.com/redhat-cne/l2discovery-exports v0.0.4 h1:oYZlk0lXEnLTO8nxnL1G54L+KdQ1WyA5zZFJln9/8uA=
66-
github.com/redhat-cne/l2discovery-exports v0.0.4/go.mod h1:hYvCYXSfngU/j+auFobgvKcwiu5DurO2BnUBoSmg/NA=
65+
github.com/redhat-cne/l2discovery-exports v0.0.6 h1:CP6A+O2ITI21nnMZGAYeQgWaflHr0Z1bkn3Q9HED6uQ=
66+
github.com/redhat-cne/l2discovery-exports v0.0.6/go.mod h1:hYvCYXSfngU/j+auFobgvKcwiu5DurO2BnUBoSmg/NA=
6767
github.com/redhat-cne/privileged-daemonset v1.0.34 h1:wcffXvaz5PwvAZfq62WiMXi0N+gXFlEFXkK4CcdjshU=
6868
github.com/redhat-cne/privileged-daemonset v1.0.34/go.mod h1:poRO1Giq9rH4JD8/KLxRJobOARGxmPr8xAIwhSrZGRQ=
6969
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=

l2lib.go

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const (
5555
L2ContainerCPUReq = "100m"
5656
L2ContainerMemLim = "100M"
5757
L2ContainerMemReq = "100M"
58+
// ptpIfIndent defines the indentation level for PtpIf detailed output
59+
ptpIfIndent = 6
5860
)
5961

6062
type L2DaemonsetMode int64
@@ -121,6 +123,80 @@ type L2DiscoveryConfig struct {
121123
refresh bool
122124
}
123125

126+
func (config L2DiscoveryConfig) String() string { //nolint:funlen
127+
var result strings.Builder
128+
129+
result.WriteString("L2DiscoveryConfig:\n")
130+
result.WriteString(fmt.Sprintf(" MaxL2GraphSize: %d\n", config.MaxL2GraphSize))
131+
result.WriteString(fmt.Sprintf(" L2DsMode: %s\n", config.L2DsMode))
132+
result.WriteString(fmt.Sprintf(" refresh: %t\n", config.refresh))
133+
134+
// PtpIfList
135+
result.WriteString(" PtpIfList: \n")
136+
for i, ptpIf := range config.PtpIfList {
137+
result.WriteString(fmt.Sprintf(" %d:\n%s\n", i, ptpIf.StringFull(ptpIfIndent)))
138+
}
139+
140+
// PtpIfListUnfiltered
141+
result.WriteString(" PtpIfListUnfiltered: \n")
142+
for key, ptpIf := range config.PtpIfListUnfiltered {
143+
result.WriteString(fmt.Sprintf(" %s:\n%s\n", key, ptpIf.StringFull(ptpIfIndent)))
144+
}
145+
146+
// L2DiscoveryPods
147+
result.WriteString(" L2DiscoveryPods: \n")
148+
for key, pod := range config.L2DiscoveryPods {
149+
result.WriteString(fmt.Sprintf(" [%s]: %s\n", key, pod.Name))
150+
}
151+
152+
// ClusterMacs
153+
result.WriteString(" ClusterMacs:\n")
154+
for key, mac := range config.ClusterMacs {
155+
result.WriteString(fmt.Sprintf(" [%s]: %s\n", key, mac))
156+
}
157+
158+
// ClusterIndexToInt
159+
result.WriteString(" ClusterIndexToInt:\n")
160+
for key, value := range config.ClusterIndexToInt {
161+
result.WriteString(fmt.Sprintf(" [%s]: %d\n", key, value))
162+
}
163+
164+
// ClusterMacToInt
165+
result.WriteString(" ClusterMacToInt:\n")
166+
for key, value := range config.ClusterMacToInt {
167+
result.WriteString(fmt.Sprintf(" [%s]: %d\n", key, value))
168+
}
169+
170+
// ClusterIndexes
171+
result.WriteString(" ClusterIndexes:\n")
172+
for key, value := range config.ClusterIndexes {
173+
result.WriteString(fmt.Sprintf(" [%s]: %s\n", key, value))
174+
}
175+
176+
// LANs
177+
result.WriteString(" LANs: \n")
178+
if config.LANs != nil {
179+
for i, lan := range *config.LANs {
180+
result.WriteString(fmt.Sprintf(" [%d]: %v\n", i, lan))
181+
}
182+
} else {
183+
result.WriteString("nil\n")
184+
}
185+
186+
// PortsGettingPTP
187+
result.WriteString(" PortsGettingPTP:\n")
188+
for i, ptpIf := range config.PortsGettingPTP {
189+
result.WriteString(fmt.Sprintf(" [%d]: %s\n", i, ptpIf))
190+
}
191+
192+
// SkippedInterfaces
193+
result.WriteString(" SkippedInterfaces:\n")
194+
for i, iface := range config.SkippedInterfaces {
195+
result.WriteString(fmt.Sprintf(" [%d]: %s\n", i, iface))
196+
}
197+
return result.String()
198+
}
199+
124200
var GlobalL2DiscoveryConfig L2DiscoveryConfig
125201

126202
func (config *L2DiscoveryConfig) GetPtpIfList() []*l2.PtpIf {
@@ -248,7 +324,12 @@ func (config *L2DiscoveryConfig) getL2Disc(ptpInterfacesOnly bool) error {
248324
if err := json.Unmarshal([]byte(report), &discDataPerNode); err != nil {
249325
return err
250326
}
251-
327+
jsonData, err := json.MarshalIndent(discDataPerNode, "", " ")
328+
if err != nil {
329+
return err
330+
}
331+
// print the formatted json data
332+
logrus.Tracef("key= %s discDataPerNode: %s", k, string(jsonData))
252333
if _, ok := config.DiscoveryMap[config.L2DiscoveryPods[k].Spec.NodeName]; !ok {
253334
config.DiscoveryMap[config.L2DiscoveryPods[k].Spec.NodeName] = make(map[string]map[string]*l2.Neighbors)
254335
}

0 commit comments

Comments
 (0)