Skip to content

Commit 67ec347

Browse files
authored
fix: implement String for logging of PodInfo and IPConfig (#2020)
Signed-off-by: Evan Baker <[email protected]>
1 parent 9765544 commit 67ec347

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

cns/NetworkContainerContract.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ type PodInfo interface {
166166
OrchestratorContext() (json.RawMessage, error)
167167
// Equals implements a functional equals for PodInfos
168168
Equals(PodInfo) bool
169+
// String implements string for logging PodInfos
170+
String() string
169171
}
170172

171173
type KubernetesPodInfo struct {
@@ -183,6 +185,11 @@ type podInfo struct {
183185
Version podInfoScheme
184186
}
185187

188+
func (p podInfo) String() string {
189+
return fmt.Sprintf("InfraContainerID: [%s], InterfaceID: [%s], Key: [%s], Name: [%s], Namespace: [%s]",
190+
p.InfraContainerID(), p.InterfaceID(), p.Key(), p.Name(), p.Namespace())
191+
}
192+
186193
func (p *podInfo) Equals(o PodInfo) bool {
187194
if (p == nil) != (o == nil) {
188195
return false

cns/api.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ func (i *IPConfigurationStatus) WithStateMiddleware(fs ...stateMiddlewareFunc) {
9797
i.stateMiddlewareFuncs = append(i.stateMiddlewareFuncs, fs...)
9898
}
9999

100-
func (i *IPConfigurationStatus) String() string {
101-
return fmt.Sprintf("IPConfigurationStatus: Id: [%s], NcId: [%s], IpAddress: [%s], State: [%s], PodInfo: [%v]",
102-
i.ID, i.NCID, i.IPAddress, i.state, i.PodInfo)
100+
func (i IPConfigurationStatus) String() string {
101+
return fmt.Sprintf("ID: [%s], NCID: [%s], IPAddress: [%s], State: [%s], LastStateTransition: [%s] PodInfo: [%s]",
102+
i.ID, i.NCID, i.IPAddress, i.state, i.LastStateTransition.Format(time.RFC3339), i.PodInfo)
103103
}
104104

105105
// MarshalJSON is a custom marshaller for IPConfigurationStatus that

cns/restserver/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (service *HTTPRestService) addIPConfigStateUntransacted(ncID string, hostVe
282282

283283
if ipState, exists := service.PodIPConfigState[ipID]; exists {
284284
logger.Printf("[Azure-Cns] Set ipId %s, IP %s version to %d, programmed host nc version is %d, "+
285-
"ipState: %+v", ipID, ipconfig.IPAddress, ipconfig.NCVersion, hostVersion, ipState)
285+
"ipState: %s", ipID, ipconfig.IPAddress, ipconfig.NCVersion, hostVersion, ipState)
286286
continue
287287
}
288288

0 commit comments

Comments
 (0)