Skip to content

Commit

Permalink
Return error if hns network exists for transparent network (#2877)
Browse files Browse the repository at this point in the history
* do not ignore network exist if network type is transparent

* fix the logic

* enhance log

* add log

* fix comments
  • Loading branch information
paulyufan2 authored Jul 26, 2024
1 parent faac178 commit c9b99ed
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion network/network_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,19 @@ func (nm *networkManager) newNetworkImplHnsV2(nwInfo *EndpointInfo, extIf *exter
if err != nil {
return nil, fmt.Errorf("Failed to create hcn network: %s due to error: %v", hcnNetwork.Name, err)
}

logger.Info("Successfully created hcn network with response", zap.Any("hnsResponse", hnsResponse))
} else {
// we can't validate if the network already exists, don't continue
return nil, fmt.Errorf("Failed to create hcn network: %s, failed to query for existing network with error: %v", hcnNetwork.Name, err)
}
} else {
if hcnNetwork.Type == hcn.Transparent {
// CNI triggers Add() for new pod first and then delete older pod later
// for transparent network type, do not ignore network creation if network already exists
// return error to avoid creating second endpoint
logger.Error("HNS network with name already exists. Returning error for transparent network", zap.String("networkName", hcnNetwork.Name))
return nil, fmt.Errorf("HNS network with name:%s already exists. Returning error for transparent network", hcnNetwork.Name) //nolint
}
logger.Info("Network with name already exists", zap.String("name", hcnNetwork.Name))
}

Expand Down

0 comments on commit c9b99ed

Please sign in to comment.