Skip to content

Commit e6bf4fd

Browse files
committed
Revise to fix lint errors and address if-statement complexity
Signed-off-by: William Zhao <[email protected]>
1 parent c697be8 commit e6bf4fd

File tree

2 files changed

+8
-24
lines changed

2 files changed

+8
-24
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/pkg/errors v0.9.1
1717
github.com/stretchr/testify v1.10.0
1818
github.com/vishvananda/netlink v1.3.0
19+
golang.org/x/sys v0.30.0
1920
google.golang.org/grpc v1.69.2
2021
k8s.io/kubelet v0.32.0
2122
)
@@ -59,7 +60,6 @@ require (
5960
golang.org/x/mod v0.20.0 // indirect
6061
golang.org/x/net v0.36.0 // indirect
6162
golang.org/x/oauth2 v0.23.0 // indirect
62-
golang.org/x/sys v0.30.0 // indirect
6363
golang.org/x/term v0.29.0 // indirect
6464
golang.org/x/text v0.22.0 // indirect
6565
golang.org/x/time v0.7.0 // indirect

pkg/netdevice/netResourcePool.go

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,40 +103,24 @@ func (rp *netResourcePool) Probe() bool {
103103
}
104104
cachedPfLinkStatus[pfName] = pfIsUp
105105
}
106-
pfIsUpLog = fmt.Sprintf("PF %s", pfName)
107-
if pfIsUp {
108-
pfIsUpLog = fmt.Sprintf("%s is UP, ", pfIsUpLog)
109-
} else {
110-
pfIsUpLog = fmt.Sprintf("%s is DOWN, ", pfIsUpLog)
111-
}
106+
pfIsUpLog = fmt.Sprintf("PF %s is %s,", pfName, map[bool]string{true: "Up", false: "Down"}[pfIsUp])
112107
}
113108

114109
deviceExists := true
115110
deviceExistsLog := ""
116111
if rp.config.CheckHealthOnDeviceExist {
117112
deviceExists = netDev.DeviceExists()
118-
deviceExistsLog = fmt.Sprintf("Device %s", netDev.GetPciAddr())
119-
if deviceExists {
120-
deviceExistsLog = fmt.Sprintf("%s is existing, ", deviceExistsLog)
121-
} else {
122-
deviceExistsLog = fmt.Sprintf("%s is missing, ", deviceExistsLog)
123-
}
113+
deviceExistsLog = fmt.Sprintf("Device %s is %s,", netDev.GetPciAddr(),
114+
map[bool]string{true: "existing", false: "missing"}[deviceExists])
124115
}
125116

126117
if pfIsUp && deviceExists && !currentHealth {
127-
glog.Infof("%s%sdevice was unhealthy, marking device %s as healthy", pfIsUpLog, deviceExistsLog, id)
118+
glog.Infof("%s %s device was unhealthy, marking device %s as healthy", pfIsUpLog, deviceExistsLog, id)
128119
device.SetHealth(true)
129120
changes = true
130-
} else if !pfIsUp && deviceExists && currentHealth {
131-
glog.Infof("%s%sdevice was healthy, marking device %s as unhealthy", pfIsUpLog, deviceExistsLog, id)
132-
device.SetHealth(false)
133-
changes = true
134-
} else if pfIsUp && !deviceExists && currentHealth {
135-
glog.Infof("%s%sdevice was healthy, marking device %s as unhealthy", pfIsUpLog, deviceExistsLog, id)
136-
device.SetHealth(false)
137-
changes = true
138-
} else if !pfIsUp && !deviceExists && currentHealth {
139-
glog.Infof("%s%sdevice was healthy, marking device %s as unhealthy", pfIsUpLog, deviceExistsLog, id)
121+
} else if (!pfIsUp || !deviceExists) && currentHealth {
122+
// If either the PF is down or the device is missing:
123+
glog.Infof("%s %s device was healthy, marking device %s as unhealthy", pfIsUpLog, deviceExistsLog, id)
140124
device.SetHealth(false)
141125
changes = true
142126
}

0 commit comments

Comments
 (0)