Skip to content

Commit

Permalink
Enhance HNS network initialization
Browse files Browse the repository at this point in the history
The current windows agent initialization couldn't guarantee that the `EnableHNSNetworkExtension` was executed
after creating the HNS network.
In certain corner cases where the Windows agent pod was restarted after creating HNS network, the agent might miss
executing `EnableHNSNetworkExtension`.

To address this issue, this enhancement runs `EnableHNSNetworkExtension` even if the HNS network has been created,
which ensures the OVS Extension is properly enabled.

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
  • Loading branch information
XinShuYang committed Jan 9, 2024
1 parent 7702924 commit fd2cb58
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ func (i *Initializer) prepareHNSNetworkAndOVSExtension() error {
// If the HNS Network already exists, return immediately.
hnsNetwork, err := hcsshim.GetHNSNetworkByName(util.LocalHNSNetwork)
if err == nil {
// Enable OVS Extension on the HNS Network.
/*
if err = util.EnableHNSNetworkExtension(hnsNetwork.Id, util.OVSExtensionID); err != nil {
return err
}
*/
// Enable RSC for existing vSwitch.
if err = util.EnableRSCOnVSwitch(util.LocalHNSNetwork); err != nil {
return err
Expand Down
26 changes: 24 additions & 2 deletions pkg/agent/util/net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ type Route struct {
RouteMetric int
}

type AntreaHNSNetwork struct {
Id string `json:"ID,omitempty"`
Name string `json:",omitempty"`
Type string `json:",omitempty"`
NetworkAdapterName string `json:",omitempty"`
SourceMac string `json:",omitempty"`
MacPools []MacPool `json:",omitempty"`

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Analyze on Windows (go)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Build Antrea and antctl binaries

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Unit test (windows-2022)

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Build Antrea Windows binaries

undefined: MacPool

Check failure on line 99 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / golicense

undefined: MacPool
Subnets []Subnet `json:",omitempty"`

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Analyze on Windows (go)

undefined: Subnet

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Build Antrea and antctl binaries

undefined: Subnet

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: Subnet) (typecheck)

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: Subnet) (typecheck)

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (macos-latest)

undefined: Subnet) (typecheck)

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: Subnet) (typecheck)

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: Subnet) (typecheck)

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Golangci-lint (ubuntu-latest)

undefined: Subnet) (typecheck)

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Unit test (windows-2022)

undefined: Subnet

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / Build Antrea Windows binaries

undefined: Subnet

Check failure on line 100 in pkg/agent/util/net_windows.go

View workflow job for this annotation

GitHub Actions / golicense

undefined: Subnet
DNSSuffix string `json:",omitempty"`
DNSServerList string `json:",omitempty"`
DNSServerCompartment uint32 `json:",omitempty"`
ManagementIP string `json:",omitempty"`
AutomaticDNS bool `json:",omitempty"`
Extensions []vSwitchExtensionPolicy `json:"Extensions"`
}

func (r *Route) String() string {
return fmt.Sprintf("LinkIndex: %d, DestinationSubnet: %s, GatewayAddress: %s, RouteMetric: %d",
r.LinkIndex, r.DestinationSubnet, r.GatewayAddress, r.RouteMetric)
Expand Down Expand Up @@ -290,7 +306,11 @@ func CreateHNSNetwork(hnsNetName string, subnetCIDR *net.IPNet, nodeIP *net.IPNe
adapterMAC := adapter.HardwareAddr
adapterName := adapter.Name
gateway := ip.NextIP(subnetCIDR.IP.Mask(subnetCIDR.Mask))
network := &hcsshim.HNSNetwork{
extensionPolicy := vSwitchExtensionPolicy{
ExtensionID: OVSExtensionID,
IsEnabled: true,
}
network := &AntreaHNSNetwork{
Name: hnsNetName,
Type: HNSNetworkType,
NetworkAdapterName: adapterName,
Expand All @@ -302,8 +322,10 @@ func CreateHNSNetwork(hnsNetName string, subnetCIDR *net.IPNet, nodeIP *net.IPNe
},
ManagementIP: nodeIP.String(),
SourceMac: adapterMAC.String(),
Extensions: []vSwitchExtensionPolicy{extensionPolicy},
}
hnsNet, err := hnsNetworkCreate(network)
jsonString, _ := json.Marshal(network)
hnsNet, err := hnsNetworkRequest("POST", "", string(jsonString))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit fd2cb58

Please sign in to comment.