Skip to content

Commit 652c721

Browse files
authored
[Windows] Use syscall to query or operate network adapters (#4898)
1. Add syscall to support getting adapter address in all compartments 2. Add syscall to get or set netIPInterface entry 3. Modify container MTU inside compartment. 4. Add syscall for route on Windows Signed-off-by: wenyingd <[email protected]> Signed-off-by: Qiyue Yao <[email protected]>
1 parent ddf4d44 commit 652c721

File tree

13 files changed

+1244
-288
lines changed

13 files changed

+1244
-288
lines changed

docs/design/windows-design.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ It is processed and forwarded by OVS, and controlled with OpenFlow entries.
209209

210210
### Service Traffic
211211

212-
Kube-proxy userspace mode is configured to provide NodePort Service function. A specific Network Adapter named
212+
Kube-proxy userspace mode is configured to provide NodePort Service function. A specific Network adapter named
213213
"HNS Internal NIC" is provided to kube-proxy to configure Service addresses. The OpenFlow entries for the
214214
NodePort Service traffic on Windows are the same as those on Linux.
215215

pkg/agent/agent_windows.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,10 @@ func (i *Initializer) prepareHNSNetworkAndOVSExtension() error {
9292
i.nodeConfig.UplinkNetConfig.Index = adapter.Index
9393
defaultGW, err := util.GetDefaultGatewayByInterfaceIndex(adapter.Index)
9494
if err != nil {
95-
if strings.Contains(err.Error(), "No matching MSFT_NetRoute objects found") {
96-
klog.InfoS("No default gateway found on interface", "interface", adapter.Name)
97-
defaultGW = ""
98-
} else {
99-
return err
100-
}
95+
return err
96+
}
97+
if defaultGW == "" {
98+
klog.InfoS("No default gateway found on interface", "interface", adapter.Name)
10199
}
102100
i.nodeConfig.UplinkNetConfig.Gateway = defaultGW
103101
dnsServers, err := util.GetDNServersByInterfaceIndex(adapter.Index)

pkg/agent/cniserver/interface_configuration_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (ic *ifConfigurator) addPostInterfaceCreateHook(containerID, endpointName s
505505
go func() {
506506
ifaceName := fmt.Sprintf("vEthernet (%s)", endpointName)
507507
var err error
508-
pollErr := wait.PollImmediate(time.Second, 60*time.Second, func() (bool, error) {
508+
pollErr := wait.PollImmediate(100*time.Millisecond, 60*time.Second, func() (bool, error) {
509509
containerAccess.lockContainer(containerID)
510510
defer containerAccess.unlockContainer(containerID)
511511
currentEP, ok := ic.getEndpoint(endpointName)
@@ -518,7 +518,7 @@ func (ic *ifConfigurator) addPostInterfaceCreateHook(containerID, endpointName s
518518
return true, nil
519519
}
520520
if !hostInterfaceExistsFunc(ifaceName) {
521-
klog.InfoS("Waiting for interface to be created", "interface", ifaceName)
521+
klog.V(2).InfoS("Waiting for interface to be created", "interface", ifaceName)
522522
return false, nil
523523
}
524524
if err = hook(); err != nil {

pkg/agent/route/route_windows.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"net"
2424
"reflect"
25-
"strings"
2625
"sync"
2726

2827
"k8s.io/apimachinery/pkg/util/sets"
@@ -312,11 +311,7 @@ func (c *Client) addServiceCIDRRoute(serviceCIDR *net.IPNet) error {
312311
// Remove stale routes.
313312
for _, rt := range staleRoutes {
314313
if err := util.RemoveNetRoute(rt); err != nil {
315-
if strings.Contains(err.Error(), "No matching MSFT_NetRoute objects") {
316-
klog.InfoS("Failed to delete stale Service CIDR route since the route has been deleted", "route", rt)
317-
} else {
318-
return fmt.Errorf("failed to delete stale Service CIDR route %s: %w", rt.String(), err)
319-
}
314+
return fmt.Errorf("failed to delete stale Service CIDR route %s: %w", rt.String(), err)
320315
} else {
321316
klog.V(4).InfoS("Deleted stale Service CIDR route successfully", "route", rt)
322317
}
@@ -547,11 +542,7 @@ func (c *Client) DeleteExternalIPRoute(externalIP net.IP) error {
547542
return nil
548543
}
549544
if err := util.RemoveNetRoute(route.(*util.Route)); err != nil {
550-
if strings.Contains(err.Error(), "No matching MSFT_NetRoute objects") {
551-
klog.InfoS("Failed to delete route for external IP since it doesn't exist", "IP", externalIPStr)
552-
} else {
553-
return fmt.Errorf("failed to delete route for external IP %s: %w", externalIPStr, err)
554-
}
545+
return fmt.Errorf("failed to delete route for external IP %s: %w", externalIPStr, err)
555546
}
556547
c.serviceRoutes.Delete(externalIPStr)
557548
klog.V(4).InfoS("Deleted route for external IP", "IP", externalIPStr)

pkg/agent/route/route_windows_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ func TestRouteOperation(t *testing.T) {
8484
err = client.Reconcile([]string{dest2})
8585
require.Nil(t, err)
8686

87-
routes5, err := util.GetNetRoutes(gwLink, destCIDR1)
88-
require.Nil(t, err)
89-
assert.Equal(t, 0, len(routes5))
90-
9187
err = client.DeleteRoutes(destCIDR2)
9288
require.Nil(t, err)
9389
routes7, err := util.GetNetRoutes(gwLink, destCIDR2)

pkg/agent/util/net_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func TestSetAdapterMACAddress(t *testing.T) {
407407
wantErr error
408408
}{
409409
{
410-
name: "Set Adapter MAC",
410+
name: "Set adapter MAC",
411411
expectedCalls: func(mockNetlink *netlinktest.MockInterfaceMockRecorder) {
412412
mockNetlink.LinkByName("test-en0").Return(testLink, nil)
413413
mockNetlink.LinkSetHardwareAddr(testLink, testMACAddr).Return(nil)

0 commit comments

Comments
 (0)