Skip to content

Commit 58c612b

Browse files
authored
Refactor gRPC connection handling and update cache informer options (#146)
- Added a comment to suppress staticcheck warnings for deprecated gRPC options. - Updated the cache informer creation to use the new `NewInformerWithOptions` method for better clarity and flexibility.
1 parent ce5d79c commit 58c612b

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

internal/deviceplugin/real_node.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ func dial(unixSocketPath string, timeout time.Duration) (*grpc.ClientConn, error
4646
ctx, cancel := context.WithTimeout(ctx, timeout)
4747
defer cancel()
4848

49+
//nolint:staticcheck // grpc.DialContext and WithBlock are deprecated but supported throughout 1.x
4950
c, err := grpc.DialContext(
5051
ctx,
5152
unixSocketPath,
5253
grpc.WithTransportCredentials(insecure.NewCredentials()),
53-
grpc.WithBlock(),
54+
grpc.WithBlock(), //nolint:staticcheck
5455
grpc.WithContextDialer(func(_ context.Context, addr string) (net.Conn, error) {
5556
return net.DialTimeout("unix", addr, timeout)
5657
}),

internal/migfaker/syncconfig.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ func ContinuouslySyncMigConfigChanges(clientset kubernetes.Interface, migConfig
5555
fields.OneTermEqualSelector("metadata.name", viper.GetString(constants.EnvNodeName)),
5656
)
5757

58-
_, controller := cache.NewInformer(
59-
listWatch, &v1.Node{}, 0,
60-
cache.ResourceEventHandlerFuncs{
58+
_, controller := cache.NewInformerWithOptions(cache.InformerOptions{
59+
ListerWatcher: listWatch,
60+
ObjectType: &v1.Node{},
61+
Handler: cache.ResourceEventHandlerFuncs{
6162
AddFunc: func(obj interface{}) {
6263
migConfig.Set(obj.(*v1.Node).Annotations[MigConfigAnnotation])
6364
},
@@ -69,7 +70,7 @@ func ContinuouslySyncMigConfigChanges(clientset kubernetes.Interface, migConfig
6970
}
7071
},
7172
},
72-
)
73+
})
7374

7475
go controller.Run(stop)
7576
}

0 commit comments

Comments
 (0)