Skip to content

Commit a10f0df

Browse files
committed
address linter issues
1 parent 0e0414e commit a10f0df

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

dhcp/dhcp_windows.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,44 +87,44 @@ func (s *Socket) Close() error {
8787
func (c *DHCP) getIPv4InterfaceAddresses(ifName string) ([]net.IP, error) {
8888
nic, err := c.netioClient.GetNetworkInterfaceByName(ifName)
8989
if err != nil {
90-
return []net.IP{}, err
90+
return []net.IP{}, errors.Wrap(err, "failed to get interface by name to find ipv4 addresses")
9191
}
9292
addresses, err := c.netioClient.GetNetworkInterfaceAddrs(nic)
9393
if err != nil {
94-
return []net.IP{}, err
94+
return []net.IP{}, errors.Wrap(err, "failed to get interface addresses")
9595
}
9696
ret := []net.IP{}
9797
for _, address := range addresses {
9898
// check if the ip is ipv4 and parse it
99-
ip, _, err := net.ParseCIDR(address.String())
100-
if err != nil || ip.To4() == nil {
99+
ip, _, cidrErr := net.ParseCIDR(address.String())
100+
if cidrErr != nil || ip.To4() == nil {
101101
continue
102102
}
103103
ret = append(ret, ip)
104104
}
105105

106106
c.logger.Info("Interface addresses found", zap.Any("foundIPs", addresses), zap.Any("selectedIPs", ret))
107-
return ret, err
107+
return ret, nil
108108
}
109109

110-
func (c *DHCP) verifyIPv4InterfaceAddressCount(ifName string, count, maxRuns int, sleep time.Duration) error {
110+
func (c *DHCP) verifyIPv4InterfaceAddressCount(ctx context.Context, ifName string, count, maxRuns int, sleep time.Duration) error {
111111
retrier := retry.Retrier{
112112
Cooldown: retry.Max(maxRuns, retry.Fixed(sleep)),
113113
}
114-
addressCountErr := retrier.Do(context.Background(), func() error {
114+
addressCountErr := retrier.Do(ctx, func() error {
115115
addresses, err := c.getIPv4InterfaceAddresses(ifName)
116116
if err != nil || len(addresses) != count {
117117
return errIncorrectAddressCount
118118
}
119119
return nil
120120
})
121-
return addressCountErr
121+
return errors.Wrap(addressCountErr, "failed to verify interface ipv4 address count")
122122
}
123123

124124
// issues a dhcp discover request on an interface by finding the secondary's ip and sending on its ip
125125
func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr, ifName string) error {
126126
// Find the ipv4 address of the secondary interface (we're betting that this gets autoconfigured)
127-
err := c.verifyIPv4InterfaceAddressCount(ifName, 1, retryCount, ipAssignRetryDelay)
127+
err := c.verifyIPv4InterfaceAddressCount(ctx, ifName, 1, retryCount, ipAssignRetryDelay)
128128
if err != nil {
129129
return errors.Wrap(err, "failed to get auto ip config assigned in apipa range in time")
130130
}
@@ -181,7 +181,7 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
181181
Cooldown: retry.Max(retryCount, retry.Fixed(retryDelay)),
182182
}
183183
// retry sending the packet until it succeeds
184-
err = retrier.Do(context.Background(), func() error {
184+
err = retrier.Do(ctx, func() error {
185185
_, sockErr := sock.Write(bytesToSend)
186186
return sockErr
187187
})

network/network_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const (
4646
defaultIPv6Route = "::/0"
4747
// Default IPv6 nextHop
4848
defaultIPv6NextHop = "fe80::1234:5678:9abc"
49+
dhcpTimeout = 15 * time.Second
4950
)
5051

5152
// Windows implementation of route.
@@ -438,8 +439,7 @@ func (nm *networkManager) newNetworkImplHnsV2(nwInfo *EndpointInfo, extIf *exter
438439
func (nm *networkManager) sendDHCPDiscoverOnSecondary(client dhcpClient, mac net.HardwareAddr, ifName string) error {
439440
// issue dhcp discover packet to ensure mapping created for dns via wireserver to work
440441
// we do not use the response for anything
441-
timeout := 15 * time.Second
442-
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(timeout))
442+
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(dhcpTimeout))
443443
defer cancel()
444444
logger.Info("Sending DHCP packet", zap.Any("macAddress", mac), zap.String("ifName", ifName))
445445
err := client.DiscoverRequest(ctx, mac, ifName)

network/transparent_vlan_endpointclient_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,10 @@ func (client *TransparentVlanEndpointClient) Retry(f func() error) error {
680680
retrier := retry.Retrier{
681681
Cooldown: retry.Max(numRetries, retry.Fixed(sleepDelay)),
682682
}
683-
return retrier.Do(context.Background(), func() error {
683+
return errors.Wrap(retrier.Do(context.Background(), func() error {
684684
// we always want to retry, so all errors are temporary errors
685-
return retry.WrapTemporaryError(f())
686-
})
685+
return retry.WrapTemporaryError(f()) // nolint
686+
}), "error during retry")
687687
}
688688

689689
// Helper function that allows executing a function in a VM namespace

retry/retry.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ func (r RetriableError) Error() string {
3636
}
3737
return r.err.Error()
3838
}
39+
3940
func (r RetriableError) Unwrap() error {
4041
return r.err
4142
}
43+
4244
func (r RetriableError) Temporary() bool {
4345
return true
4446
}

retry/retry_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/stretchr/testify/require"
1111
)
1212

13+
var errTest = errors.New("mock error")
14+
1315
type TestError struct{}
1416

1517
func (t TestError) Error() string {
@@ -168,13 +170,12 @@ func TestMax(t *testing.T) {
168170

169171
func TestRetriableError(t *testing.T) {
170172
// wrapping nil returns a nil
171-
require.Nil(t, WrapTemporaryError(nil))
173+
require.NoError(t, WrapTemporaryError(nil))
172174

173-
mockError := errors.New("mock error")
174-
wrappedMockError := WrapTemporaryError(pkgerrors.Wrap(mockError, "nested"))
175+
wrappedMockError := WrapTemporaryError(pkgerrors.Wrap(testError, "nested"))
175176

176177
// temporary errors should still be able to be unwrapped
177-
require.ErrorIs(t, wrappedMockError, mockError)
178+
require.ErrorIs(t, wrappedMockError, testError)
178179

179180
var temporaryError TemporaryError
180181
require.ErrorAs(t, wrappedMockError, &temporaryError)
@@ -194,7 +195,7 @@ func createFunctionWithFailurePattern(errorPattern []error) func() error {
194195
}
195196

196197
func TestRunWithRetries(t *testing.T) {
197-
errMock := WrapTemporaryError(errors.New("mock error"))
198+
errMock := WrapTemporaryError(testError)
198199
retries := 3 // runs 4 times, then errors before the 5th
199200
retrier := Retrier{
200201
Cooldown: Max(retries, Fixed(100*time.Millisecond)),

0 commit comments

Comments
 (0)