@@ -360,10 +360,20 @@ func (nm *networkManager) newNetworkImplHnsV2(nwInfo *EndpointInfo, extIf *exter
360360 if errors .As (err , & hcn.NetworkNotFoundError {}) {
361361 logger .Info ("Creating hcn network" , zap .Any ("hcnNetwork" , hcnNetwork ))
362362 hnsResponse , err = Hnsv2 .CreateNetwork (hcnNetwork )
363- if err != nil {
364- return nil , fmt .Errorf ("Failed to create hcn network: %s due to error: %v" , hcnNetwork .Name , err )
363+ if err == nil {
364+ logger .Info ("Successfully created hcn network with response" , zap .Any ("hnsResponse" , hnsResponse ))
365+ } else {
366+ if strings .Contains (err .Error (), "already exists" ) {
367+ // fetch the network name again since the paralel CNI Add call has created the HNS network
368+ hnsResponse , err = Hnsv2 .GetNetworkByName (hcnNetwork .Name )
369+ if err != nil {
370+ return nil , fmt .Errorf ("Failed to get hcn network: %s due to error: %v" , hcnNetwork .Name , err )
371+ }
372+ logger .Info ("Successfully fetched hcn network with response" , zap .Any ("hnsResponse" , hnsResponse ))
373+ } else {
374+ return nil , fmt .Errorf ("Failed to create hcn network: %s due to error: %v" , hcnNetwork .Name , err )
375+ }
365376 }
366- logger .Info ("Successfully created hcn network with response" , zap .Any ("hnsResponse" , hnsResponse ))
367377 } else {
368378 // we can't validate if the network already exists, don't continue
369379 return nil , fmt .Errorf ("Failed to create hcn network: %s, failed to query for existing network with error: %v" , hcnNetwork .Name , err )
0 commit comments