Skip to content

Commit 9643131

Browse files
isaac-dasanCopilot
andauthored
[backport] perf: dhcp err msg in network swiftv2 code path (#3793) (#3821)
perf: dhcp err msg in network swiftv2 code path (#3793) * fix: dhcp error message to include kubelet err msg * Update network/secondary_endpoint_client_linux.go --------- Signed-off-by: GitHub <[email protected]> Signed-off-by: Isaac <[email protected]> Co-authored-by: Copilot <[email protected]>
1 parent 87917ea commit 9643131

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

network/secondary_endpoint_client_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/Azure/azure-container-networking/platform"
1414
"github.com/pkg/errors"
1515
"go.uber.org/zap"
16+
"k8s.io/kubernetes/pkg/kubelet"
1617
)
1718

1819
var errorSecondaryEndpointClient = errors.New("SecondaryEndpointClient Error")
@@ -141,7 +142,7 @@ func (client *SecondaryEndpointClient) ConfigureContainerInterfacesAndRoutes(epI
141142
logger.Info("Sending DHCP packet", zap.Any("macAddress", epInfo.MacAddress), zap.String("ifName", epInfo.IfName))
142143
err := client.dhcpClient.DiscoverRequest(ctx, epInfo.MacAddress, epInfo.IfName)
143144
if err != nil {
144-
return errors.Wrapf(err, "failed to issue dhcp discover packet to create mapping in host")
145+
return errors.Wrap(err, kubelet.NetworkNotReadyErrorMsg+" - failed to issue dhcp discover packet to create mapping in host")
145146
}
146147
logger.Info("Finished configuring container interfaces and routes for secondary endpoint client")
147148

network/secondary_endpoint_linux_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package network
55

66
import (
7+
"context"
78
"net"
89
"testing"
910

@@ -12,9 +13,18 @@ import (
1213
"github.com/Azure/azure-container-networking/netlink"
1314
"github.com/Azure/azure-container-networking/network/networkutils"
1415
"github.com/Azure/azure-container-networking/platform"
16+
"github.com/pkg/errors"
1517
"github.com/stretchr/testify/require"
18+
"k8s.io/kubernetes/pkg/kubelet"
1619
)
1720

21+
// mockDHCPFail is a mock DHCP client that always returns an error
22+
type mockDHCPFail struct{}
23+
24+
func (m *mockDHCPFail) DiscoverRequest(context.Context, net.HardwareAddr, string) error {
25+
return errors.New("mock DHCP discover request failed")
26+
}
27+
1828
func TestSecondaryAddEndpoints(t *testing.T) {
1929
nl := netlink.NewMockNetlink(false, "")
2030
plc := platform.NewMockExecClient(false)
@@ -363,6 +373,33 @@ func TestSecondaryConfigureContainerInterfacesAndRoutes(t *testing.T) {
363373
wantErr: true,
364374
wantErrMsg: "SecondaryEndpointClient Error: routes expected for eth1",
365375
},
376+
{
377+
name: "Configure Interface and routes DHCP discover fail",
378+
client: &SecondaryEndpointClient{
379+
netlink: netlink.NewMockNetlink(false, ""),
380+
plClient: platform.NewMockExecClient(false),
381+
netUtilsClient: networkutils.NewNetworkUtils(nl, plc),
382+
netioshim: netio.NewMockNetIO(false, 0),
383+
dhcpClient: &mockDHCPFail{},
384+
ep: &endpoint{SecondaryInterfaces: map[string]*InterfaceInfo{"eth1": {Name: "eth1"}}},
385+
},
386+
epInfo: &EndpointInfo{
387+
IfName: "eth1",
388+
IPAddresses: []net.IPNet{
389+
{
390+
IP: net.ParseIP("192.168.0.4"),
391+
Mask: net.CIDRMask(subnetv4Mask, ipv4Bits),
392+
},
393+
},
394+
Routes: []RouteInfo{
395+
{
396+
Dst: net.IPNet{IP: net.ParseIP("192.168.0.4"), Mask: net.CIDRMask(ipv4FullMask, ipv4Bits)},
397+
},
398+
},
399+
},
400+
wantErr: true,
401+
wantErrMsg: kubelet.NetworkNotReadyErrorMsg,
402+
},
366403
}
367404

368405
for _, tt := range tests {

0 commit comments

Comments
 (0)