Skip to content

Commit 04da2a2

Browse files
committed
address pr comments
1 parent 519ddd8 commit 04da2a2

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

cns/service/main.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"net/http"
1313
"os"
1414
"os/signal"
15-
"reflect"
1615
"runtime"
1716
"strconv"
1817
"strings"
@@ -67,6 +66,7 @@ import (
6766
"github.com/Azure/azure-container-networking/store"
6867
"github.com/Azure/azure-container-networking/telemetry"
6968
"github.com/avast/retry-go/v4"
69+
"github.com/google/go-cmp/cmp"
7070
"github.com/pkg/errors"
7171
"go.uber.org/zap"
7272
"go.uber.org/zap/zapcore"
@@ -112,6 +112,9 @@ const (
112112
defaultLocalServerPort = "10090"
113113
defaultDevicePluginRetryInterval = 2 * time.Second
114114
defaultNodeInfoCRDPollInterval = 5 * time.Second
115+
defaultDevicePluginMaxRetryCount = 5
116+
initialVnetNICCount = 0
117+
initialIBNICCount = 0
115118
)
116119

117120
type cniConflistScenario string
@@ -886,8 +889,6 @@ func main() {
886889
}
887890

888891
if cnsconfig.EnableSwiftV2 && cnsconfig.EnableK8sDevicePlugin {
889-
initialVnetNICCount := 0
890-
initialIBNICCount := 0
891892
// Create device plugin manager instance
892893
pluginManager := deviceplugin.NewPluginManager(z)
893894
pluginManager.AddPlugin(mtv1alpha1.DeviceTypeVnetNIC, initialVnetNICCount)
@@ -898,15 +899,24 @@ func main() {
898899

899900
// Start device plugin manager in a separate goroutine
900901
go func() {
902+
retryCount := 0
903+
ticker := time.NewTicker(defaultDevicePluginRetryInterval)
904+
// Ensure the ticker is stopped on exit
905+
defer ticker.Stop()
901906
for {
902907
select {
903908
case <-ctx.Done():
904909
z.Info("Context canceled, stopping plugin manager")
905910
return
906-
default:
911+
case <-ticker.C:
907912
if pluginErr := pluginManager.Run(ctx); pluginErr != nil {
908913
z.Error("plugin manager exited with error", zap.Error(pluginErr))
909-
time.Sleep(defaultDevicePluginRetryInterval)
914+
retryCount++
915+
// Implementing a basic circuit breaker
916+
if retryCount >= defaultDevicePluginMaxRetryCount {
917+
z.Error("Max retries reached, stopping plugin manager")
918+
return
919+
}
910920
} else {
911921
return
912922
}
@@ -1140,7 +1150,7 @@ func pollNodeInfoCRDAndUpdatePlugin(ctx context.Context, zlog *zap.Logger, plugi
11401150
}
11411151

11421152
// Check if the status is set
1143-
if !reflect.DeepEqual(nodeInfo.Status, mtv1alpha1.NodeInfoStatus{}) && len(nodeInfo.Status.DeviceInfos) > 0 {
1153+
if !cmp.Equal(nodeInfo.Status, mtv1alpha1.NodeInfoStatus{}) && len(nodeInfo.Status.DeviceInfos) > 0 {
11441154
// Create a map to count devices by type
11451155
deviceCounts := map[mtv1alpha1.DeviceType]int{
11461156
mtv1alpha1.DeviceTypeVnetNIC: 0,

0 commit comments

Comments
 (0)