Skip to content

Commit

Permalink
Update Node's MAC address to the Node's annotation for direct routing
Browse files Browse the repository at this point in the history
  • Loading branch information
tnqn committed May 10, 2021
1 parent e50142c commit 9c5a7da
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,7 @@ rules:
- get
- watch
- list
- update
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,7 @@ rules:
- get
- watch
- list
- update
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,7 @@ rules:
- get
- watch
- list
- update
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,7 @@ rules:
- get
- watch
- list
- update
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2918,6 +2918,7 @@ rules:
- get
- watch
- list
- update
- apiGroups:
- ""
resources:
Expand Down
1 change: 1 addition & 0 deletions build/yamls/base/agent-rbac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ rules:
- get
- watch
- list
- update
- apiGroups:
- ""
resources:
Expand Down
4 changes: 4 additions & 0 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ func (i *Initializer) Initialize() error {
return err
}

if err := i.updateNodeMACAnnotation(); err != nil {
return err
}

if err := i.setupOVSBridge(); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/agent/agent_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ func (i *Initializer) prepareHostNetwork() error {
return nil
}

func (i *Initializer) updateNodeMACAnnotation() error {
return nil
}

// prepareOVSBridge returns immediately on Linux.
func (i *Initializer) prepareOVSBridge() error {
return nil
Expand Down
35 changes: 35 additions & 0 deletions pkg/agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,22 @@
package agent

import (
"context"
"encoding/json"
"fmt"
"net"
"strings"

"github.com/Microsoft/hcsshim"
"github.com/rakelkar/gonetsh/netroute"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
apitypes "k8s.io/apimachinery/pkg/types"
"k8s.io/klog"

"github.com/vmware-tanzu/antrea/pkg/agent/config"
"github.com/vmware-tanzu/antrea/pkg/agent/interfacestore"
"github.com/vmware-tanzu/antrea/pkg/agent/types"
"github.com/vmware-tanzu/antrea/pkg/agent/util"
"github.com/vmware-tanzu/antrea/pkg/ovs/ovsctl"
)
Expand Down Expand Up @@ -76,6 +82,35 @@ func (i *Initializer) prepareHostNetwork() error {
return util.PrepareHNSNetwork(subnetCIDR, i.nodeConfig.NodeIPAddr, adapter)
}

// updateNodeMACAnnotation updates the Node's MAC address in the Annotations of the Node. The MAC address will be used
// for direct routing via Openflow in noencap case.
func (i *Initializer) updateNodeMACAnnotation() error {
if !i.networkConfig.TrafficEncapMode.SupportsNoEncap() {
return nil
}
patch, _ := json.Marshal(map[string]interface{}{
"metadata": map[string]interface{}{
"annotations": map[string]string{
types.NodeMACAddressAnnotationKey: i.nodeConfig.UplinkNetConfig.MAC.String(),
},
},
})
var err error
for attempt := 0; attempt < 3; attempt++ {
_, err = i.client.CoreV1().Nodes().Patch(context.TODO(), i.nodeConfig.Name, apitypes.MergePatchType, patch, metav1.PatchOptions{})
if err != nil {
if !errors.IsConflict(err) {
return err
}
klog.Warningf("Updating Node MAC annotation failed: %v, will retry", err)
continue
}
klog.Infof("Updating Node MAC annotation succeeded")
return nil
}
return err
}

// prepareOVSBridge adds local port and uplink to ovs bridge.
// This function will delete OVS bridge and HNS network created by antrea on failure.
func (i *Initializer) prepareOVSBridge() error {
Expand Down
20 changes: 20 additions & 0 deletions pkg/agent/types/annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2021 Antrea Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

const (
// NodeMACAddressAnnotationKey represents the key of the Node's MAC address in the Annotations of the Node.
NodeMACAddressAnnotationKey string = "node.antrea.io/mac-address"
)

0 comments on commit 9c5a7da

Please sign in to comment.