Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: implement String for logging of PodInfo and IPConfig #2020

Merged
merged 1 commit into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cns/NetworkContainerContract.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ type PodInfo interface {
OrchestratorContext() (json.RawMessage, error)
// Equals implements a functional equals for PodInfos
Equals(PodInfo) bool
// String implements string for logging PodInfos
String() string
}

type KubernetesPodInfo struct {
Expand All @@ -186,6 +188,11 @@ type podInfo struct {
Version podInfoScheme
}

func (p podInfo) String() string {
return fmt.Sprintf("InfraContainerID: [%s], InterfaceID: [%s], Key: [%s], Name: [%s], Namespace: [%s]",
p.InfraContainerID(), p.InterfaceID(), p.Key(), p.Name(), p.Namespace())
}

func (p *podInfo) Equals(o PodInfo) bool {
if (p == nil) != (o == nil) {
return false
Expand Down
6 changes: 3 additions & 3 deletions cns/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func (i *IPConfigurationStatus) WithStateMiddleware(fs ...stateMiddlewareFunc) {
i.stateMiddlewareFuncs = append(i.stateMiddlewareFuncs, fs...)
}

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

// MarshalJSON is a custom marshaller for IPConfigurationStatus that
Expand Down
2 changes: 1 addition & 1 deletion cns/restserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (service *HTTPRestService) addIPConfigStateUntransacted(ncID string, hostVe

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

Expand Down