Skip to content

Commit

Permalink
move nolint annotations inline
Browse files Browse the repository at this point in the history
  • Loading branch information
aggarwal0009 committed Aug 6, 2024
1 parent aed17cc commit 798e2e5
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
3 changes: 1 addition & 2 deletions cns/deviceplugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,8 @@ func (p *Plugin) run(ctx context.Context) error {
return nil
}

//nolint:staticcheck // TODO: Move to grpc.NewClient method
func (p *Plugin) registerWithKubelet(ctx context.Context) error {
conn, err := grpc.Dial(p.kubeletSocket, grpc.WithTransportCredentials(insecure.NewCredentials()),
conn, err := grpc.Dial(p.kubeletSocket, grpc.WithTransportCredentials(insecure.NewCredentials()), //nolint:staticcheck // TODO: Move to grpc.NewClient method
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
d := &net.Dialer{}
conn, err := d.DialContext(ctx, "unix", addr)
Expand Down
3 changes: 2 additions & 1 deletion cns/deviceplugin/pluginmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ func (p *PluginManager) Run(ctx context.Context) error {
}

var wg sync.WaitGroup
wg.Add(2) //nolint:gomnd // starting two goroutines to wait on
wg.Add(1) //nolint:gomnd // starting two goroutines to wait on
go func() {
defer wg.Done()
p.VnetNICPlugin.Run(ctx)
}()

wg.Add(1) //nolint:gomnd // starting two goroutines to wait on
go func() {
defer wg.Done()
p.IBNICPlugin.Run(ctx)
Expand Down
40 changes: 26 additions & 14 deletions cns/deviceplugin/pluginmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/Azure/azure-container-networking/cns/deviceplugin"
"github.com/Azure/azure-container-networking/crd/multitenancy/api/v1alpha1"
"github.com/avast/retry-go/v3"
"github.com/pkg/errors"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand Down Expand Up @@ -73,14 +74,26 @@ func TestPluginManagerStartStop(t *testing.T) {
t.Fatalf("error tracking IB devices: %v", err)
}

<-time.After(3 * time.Second)
gotVnetNICCount = getDeviceCount(t, vnetPluginEndpoint)
if gotVnetNICCount != expectedVnetNICs {
t.Fatalf("expected %d vnet nics but got %d", expectedVnetNICs, gotVnetNICCount)
checkDeviceCounts := func() error {
gotVnetNICCount := getDeviceCount(t, vnetPluginEndpoint)
if gotVnetNICCount != expectedVnetNICs {
return errors.Errorf("expected %d vnet nics but got %d", expectedVnetNICs, gotVnetNICCount)
}
gotIBNICCount := getDeviceCount(t, ibPluginEndpoint)
if gotIBNICCount != expectedIBNICs {
return errors.Errorf("expected %d ib nics but got %d", expectedIBNICs, gotIBNICCount)
}
return nil
}
gotIBNICCount = getDeviceCount(t, ibPluginEndpoint)
if gotIBNICCount != expectedIBNICs {
t.Fatalf("expected %d ib nics but got %d", expectedIBNICs, gotIBNICCount)

deviceCountErr := retry.Do(
checkDeviceCounts,
retry.Attempts(6),
retry.Delay(500*time.Millisecond),
)

if deviceCountErr != nil {
t.Fatalf("failed to verify device counts: %v", err)
}

// call allocate method and check the response
Expand Down Expand Up @@ -176,9 +189,8 @@ func runFakeKubelet(ctx context.Context, address string, vnetPluginRegisterChan,
return nil
}

//nolint:staticcheck // TODO: Move to grpc.NewClient method
func getDeviceCount(t *testing.T, pluginAddress string) int {
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()),
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), //nolint:staticcheck // TODO: Move to grpc.NewClient method
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
d := &net.Dialer{}
conn, err := d.DialContext(ctx, "unix", addr)
Expand Down Expand Up @@ -206,9 +218,9 @@ func getDeviceCount(t *testing.T, pluginAddress string) int {
return len(resp.Devices)
}

//nolint:staticcheck // TODO: Move to grpc.NewClient method
func getAllocateResponse(t *testing.T, pluginAddress string, req *v1beta1.AllocateRequest) *v1beta1.AllocateResponse {
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()),
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), //nolint:staticcheck // TODO: Move to grpc.NewClient method

grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
d := &net.Dialer{}
conn, err := d.DialContext(ctx, "unix", addr)
Expand All @@ -232,7 +244,7 @@ func getAllocateResponse(t *testing.T, pluginAddress string, req *v1beta1.Alloca

//nolint:staticcheck // TODO: Move to grpc.NewClient method
func getDevicePluginOptionsResponse(pluginAddress string) (*v1beta1.DevicePluginOptions, error) {
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()),
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), //nolint:staticcheck // TODO: Move to grpc.NewClient method
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
d := &net.Dialer{}
conn, err := d.DialContext(ctx, "unix", addr)
Expand All @@ -256,7 +268,7 @@ func getDevicePluginOptionsResponse(pluginAddress string) (*v1beta1.DevicePlugin

//nolint:staticcheck // TODO: Move to grpc.NewClient method
func getPreferredAllocationResponse(pluginAddress string) (*v1beta1.PreferredAllocationResponse, error) {
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()),
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), //nolint:staticcheck // TODO: Move to grpc.NewClient method
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
d := &net.Dialer{}
conn, err := d.DialContext(ctx, "unix", addr)
Expand All @@ -280,7 +292,7 @@ func getPreferredAllocationResponse(pluginAddress string) (*v1beta1.PreferredAll

//nolint:staticcheck // TODO: Move to grpc.NewClient method
func getPreStartContainerResponse(pluginAddress string) (*v1beta1.PreStartContainerResponse, error) {
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()),
conn, err := grpc.Dial(pluginAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), //nolint:staticcheck // TODO: Move to grpc.NewClient method
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
d := &net.Dialer{}
conn, err := d.DialContext(ctx, "unix", addr)
Expand Down
4 changes: 1 addition & 3 deletions cns/deviceplugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,8 @@ func (s *Server) Run(ctx context.Context) error {
}

// Ready blocks until the server is ready
//
//nolint:staticcheck // TODO: Move to grpc.NewClient method
func (s *Server) Ready(ctx context.Context) error {
c, err := grpc.DialContext(ctx, s.address, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(),
c, err := grpc.DialContext(ctx, s.address, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(), //nolint:staticcheck // TODO: Move to grpc.NewClient method
grpc.WithContextDialer(func(ctx context.Context, addr string) (net.Conn, error) {
conn, err := (&net.Dialer{}).DialContext(ctx, "unix", addr)
if err != nil {
Expand Down

0 comments on commit 798e2e5

Please sign in to comment.