Skip to content

Commit 79fd586

Browse files
authored
pass adapter name to hns create network call (#813)
* pass adapter name to hns create network call * add comments and log
1 parent ba83940 commit 79fd586

File tree

5 files changed

+30
-2
lines changed

5 files changed

+30
-2
lines changed

cni/azure-windows.conflist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"cniVersion": "0.3.0",
33
"name": "azure",
4+
"adapterName" : "",
45
"plugins": [
56
{
67
"type": "azure-vnet",

cni/netconfig.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type NetworkConfig struct {
4747
Type string `json:"type,omitempty"`
4848
Mode string `json:"mode,omitempty"`
4949
Master string `json:"master,omitempty"`
50+
AdapterName string `json:"adapterName,omitempty"`
5051
Bridge string `json:"bridge,omitempty"`
5152
LogLevel string `json:"logLevel,omitempty"`
5253
LogTarget string `json:"logTarget,omitempty"`

cni/network/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,7 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
489489
Id: networkId,
490490
Mode: nwCfg.Mode,
491491
MasterIfName: masterIfName,
492+
AdapterName: nwCfg.AdapterName,
492493
Subnets: []network.SubnetInfo{
493494
{
494495
Family: platform.AfINET,

network/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type network struct {
5757
// NetworkInfo contains read-only information about a container network.
5858
type NetworkInfo struct {
5959
MasterIfName string
60+
AdapterName string
6061
Id string
6162
Mode string
6263
Subnets []SubnetInfo

network/network_windows.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,22 @@ func (nm *networkManager) newNetworkImplHnsV1(nwInfo *NetworkInfo, extIf *extern
6363
)
6464

6565
networkAdapterName := extIf.Name
66+
67+
// Pass adapter name here if it is not empty, this is cause if we don't tell HNS which adapter to use
68+
// it will just pick one randomly, this is a problem for customers that have multiple adapters
69+
if nwInfo.AdapterName != "" {
70+
networkAdapterName = nwInfo.AdapterName
71+
}
72+
6673
// FixMe: Find a better way to check if a nic that is selected is not part of a vSwitch
74+
// per hns team, the hns calls fails if passed a vSwitch interface
6775
if strings.HasPrefix(networkAdapterName, vEthernetAdapterPrefix) {
76+
log.Printf("[net] vSwitch detected, setting adapter name to empty")
6877
networkAdapterName = ""
6978
}
79+
80+
log.Printf("[net] Adapter name used with HNS is : %s", networkAdapterName)
81+
7082
// Initialize HNS network.
7183
hnsNetwork := &hcsshim.HNSNetwork{
7284
Name: nwInfo.Id,
@@ -216,8 +228,20 @@ func (nm *networkManager) configureHcnNetwork(nwInfo *NetworkInfo, extIf *extern
216228

217229
// Set hcn network adaptor name policy
218230
// FixMe: Find a better way to check if a nic that is selected is not part of a vSwitch
219-
if !strings.HasPrefix(extIf.Name, vEthernetAdapterPrefix) {
220-
netAdapterNamePolicy, err := policy.GetHcnNetAdapterPolicy(extIf.Name)
231+
// per hns team, the hns calls fails if passed a vSwitch interface
232+
// Pass adapter name here if it is not empty, this is cause if we don't tell HNS which adapter to use
233+
// it will just pick one randomly, this is a problem for customers that have multiple adapters
234+
if nwInfo.AdapterName != "" || !strings.HasPrefix(extIf.Name, vEthernetAdapterPrefix) {
235+
var adapterName string
236+
if nwInfo.AdapterName != "" {
237+
adapterName = nwInfo.AdapterName
238+
} else {
239+
adapterName = extIf.Name
240+
}
241+
242+
log.Printf("[net] Adapter name used with HNS is : %s", adapterName)
243+
244+
netAdapterNamePolicy, err := policy.GetHcnNetAdapterPolicy(adapterName)
221245
if err != nil {
222246
log.Printf("[net] Failed to serialize network adapter policy due to error: %v", err)
223247
return nil, err

0 commit comments

Comments
 (0)