Skip to content

Commit 63f38ef

Browse files
committed
address feedback
1 parent 94a7991 commit 63f38ef

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

cni/network/network.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
437437
zap.Any("IPs", cniResult.IPs),
438438
zap.Error(log.NewErrorWithoutStackTrace(err)))
439439

440-
telemetryClient.SendEvent(fmt.Sprintf("ADD command completed with [ipamAddResult]: %s [epInfos]: %s [error]: %v ", ipamAddResult.PrettyString(), network.FormatStructPointers(epInfos), err))
440+
telemetryClient.SendEvent(fmt.Sprintf("ADD command completed with [ipamAddResult]: %s [epInfos]: %s [error]: %v ", ipamAddResult.PrettyString(), network.FormatSliceOfPointersToString(epInfos), err))
441441
}()
442442

443443
ipamAddResult = IPAMAddResult{interfaceInfo: make(map[string]network.InterfaceInfo)}

network/endpoint.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ type apipaClient interface {
150150
CreateHostNCApipaEndpoint(ctx context.Context, networkContainerID string) (string, error)
151151
}
152152

153-
func FormatStructPointers[T any](slice []*T) string {
153+
// FormatSliceOfPointersToString takes in a slice of pointers, and for each pointer, dereferences the pointer if not nil
154+
// and then formats it to its string representation, returning a string where each line is a separate item in the slice.
155+
// This is used for convenience to get a string representation of the actual structs and their fields
156+
// in slices of pointers since the default string representation of a slice of pointers is a list of memory addresses.
157+
func FormatSliceOfPointersToString[T any](slice []*T) string {
154158
var builder strings.Builder
155159
for _, ptr := range slice {
156160
if ptr != nil {
@@ -174,7 +178,7 @@ func (ifInfo *InterfaceInfo) PrettyString() string {
174178
ncresponse = fmt.Sprintf("%+v", *ifInfo.NCResponse)
175179
}
176180
return fmt.Sprintf("Name:%s NICType:%v MacAddr:%s IPConfigs:%s Routes:%+v DNSInfo:%+v NCResponse: %s",
177-
ifInfo.Name, ifInfo.NICType, ifInfo.MacAddress.String(), FormatStructPointers(ifInfo.IPConfigs), ifInfo.Routes, ifInfo.DNS, ncresponse)
181+
ifInfo.Name, ifInfo.NICType, ifInfo.MacAddress.String(), FormatSliceOfPointersToString(ifInfo.IPConfigs), ifInfo.Routes, ifInfo.DNS, ncresponse)
178182
}
179183

180184
// NewEndpoint creates a new endpoint in the network.

network/endpoint_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ var _ = Describe("Test FormatStructPointers", func() {
3434
Describe("Test FormatStructPointers", func() {
3535
Context("When passing in a slice of pointers", func() {
3636
It("Should create a pretty printed string of the contents", func() {
37-
result := FormatStructPointers(ptrSlice)
37+
result := FormatSliceOfPointersToString(ptrSlice)
3838
Expect(result).To(Equal("{Address:{IP:<nil> Mask:<nil>} Gateway:10.10.0.1} \n{Address:{IP:<nil> Mask:<nil>} Gateway:10.10.0.2} \n"))
3939
})
4040
})
4141
Context("When passing in nil", func() {
4242
It("Should not error", func() {
4343
var empty []*IPConfig
44-
result := FormatStructPointers(empty)
44+
result := FormatSliceOfPointersToString(empty)
4545
Expect(result).To(Equal(""))
4646
})
4747
})

network/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ func (nm *networkManager) UpdateEndpointState(eps []*endpoint) error {
423423

424424
ifnameToIPInfoMap := generateCNSIPInfoMap(eps) // key : interface name, value : IPInfo
425425
for key, ipinfo := range ifnameToIPInfoMap {
426-
logger.Info("Update endpoint state", zap.String("key", key), zap.String("hnsEndpointID", ipinfo.HnsEndpointID), zap.String("hnsNetworkID", ipinfo.HnsNetworkID),
426+
logger.Info("Update endpoint state", zap.String("ifname", key), zap.String("hnsEndpointID", ipinfo.HnsEndpointID), zap.String("hnsNetworkID", ipinfo.HnsNetworkID),
427427
zap.String("hostVethName", ipinfo.HostVethName), zap.String("macAddress", ipinfo.MacAddress), zap.String("nicType", string(ipinfo.NICType)))
428428
}
429429
// we assume all endpoints have the same container id

0 commit comments

Comments
 (0)