Skip to content

Commit

Permalink
[Windows] Use syscall to query or operate network adapters (#4898)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
wenyingd authored Jul 28, 2023
1 parent ddf4d44 commit 652c721
Show file tree
Hide file tree
Showing 13 changed files with 1,244 additions and 288 deletions.
2 changes: 1 addition & 1 deletion docs/design/windows-design.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ It is processed and forwarded by OVS, and controlled with OpenFlow entries.

### Service Traffic

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

Expand Down
10 changes: 4 additions & 6 deletions pkg/agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,10 @@ func (i *Initializer) prepareHNSNetworkAndOVSExtension() error {
i.nodeConfig.UplinkNetConfig.Index = adapter.Index
defaultGW, err := util.GetDefaultGatewayByInterfaceIndex(adapter.Index)
if err != nil {
if strings.Contains(err.Error(), "No matching MSFT_NetRoute objects found") {
klog.InfoS("No default gateway found on interface", "interface", adapter.Name)
defaultGW = ""
} else {
return err
}
return err
}
if defaultGW == "" {
klog.InfoS("No default gateway found on interface", "interface", adapter.Name)
}
i.nodeConfig.UplinkNetConfig.Gateway = defaultGW
dnsServers, err := util.GetDNServersByInterfaceIndex(adapter.Index)
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/cniserver/interface_configuration_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ func (ic *ifConfigurator) addPostInterfaceCreateHook(containerID, endpointName s
go func() {
ifaceName := fmt.Sprintf("vEthernet (%s)", endpointName)
var err error
pollErr := wait.PollImmediate(time.Second, 60*time.Second, func() (bool, error) {
pollErr := wait.PollImmediate(100*time.Millisecond, 60*time.Second, func() (bool, error) {
containerAccess.lockContainer(containerID)
defer containerAccess.unlockContainer(containerID)
currentEP, ok := ic.getEndpoint(endpointName)
Expand All @@ -518,7 +518,7 @@ func (ic *ifConfigurator) addPostInterfaceCreateHook(containerID, endpointName s
return true, nil
}
if !hostInterfaceExistsFunc(ifaceName) {
klog.InfoS("Waiting for interface to be created", "interface", ifaceName)
klog.V(2).InfoS("Waiting for interface to be created", "interface", ifaceName)
return false, nil
}
if err = hook(); err != nil {
Expand Down
13 changes: 2 additions & 11 deletions pkg/agent/route/route_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"net"
"reflect"
"strings"
"sync"

"k8s.io/apimachinery/pkg/util/sets"
Expand Down Expand Up @@ -312,11 +311,7 @@ func (c *Client) addServiceCIDRRoute(serviceCIDR *net.IPNet) error {
// Remove stale routes.
for _, rt := range staleRoutes {
if err := util.RemoveNetRoute(rt); err != nil {
if strings.Contains(err.Error(), "No matching MSFT_NetRoute objects") {
klog.InfoS("Failed to delete stale Service CIDR route since the route has been deleted", "route", rt)
} else {
return fmt.Errorf("failed to delete stale Service CIDR route %s: %w", rt.String(), err)
}
return fmt.Errorf("failed to delete stale Service CIDR route %s: %w", rt.String(), err)
} else {
klog.V(4).InfoS("Deleted stale Service CIDR route successfully", "route", rt)
}
Expand Down Expand Up @@ -547,11 +542,7 @@ func (c *Client) DeleteExternalIPRoute(externalIP net.IP) error {
return nil
}
if err := util.RemoveNetRoute(route.(*util.Route)); err != nil {
if strings.Contains(err.Error(), "No matching MSFT_NetRoute objects") {
klog.InfoS("Failed to delete route for external IP since it doesn't exist", "IP", externalIPStr)
} else {
return fmt.Errorf("failed to delete route for external IP %s: %w", externalIPStr, err)
}
return fmt.Errorf("failed to delete route for external IP %s: %w", externalIPStr, err)
}
c.serviceRoutes.Delete(externalIPStr)
klog.V(4).InfoS("Deleted route for external IP", "IP", externalIPStr)
Expand Down
4 changes: 0 additions & 4 deletions pkg/agent/route/route_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ func TestRouteOperation(t *testing.T) {
err = client.Reconcile([]string{dest2})
require.Nil(t, err)

routes5, err := util.GetNetRoutes(gwLink, destCIDR1)
require.Nil(t, err)
assert.Equal(t, 0, len(routes5))

err = client.DeleteRoutes(destCIDR2)
require.Nil(t, err)
routes7, err := util.GetNetRoutes(gwLink, destCIDR2)
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/util/net_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func TestSetAdapterMACAddress(t *testing.T) {
wantErr error
}{
{
name: "Set Adapter MAC",
name: "Set adapter MAC",
expectedCalls: func(mockNetlink *netlinktest.MockInterfaceMockRecorder) {
mockNetlink.LinkByName("test-en0").Return(testLink, nil)
mockNetlink.LinkSetHardwareAddr(testLink, testMACAddr).Return(nil)
Expand Down
Loading

0 comments on commit 652c721

Please sign in to comment.