Skip to content

Commit

Permalink
Addressing the comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
behzad-mir committed May 6, 2024
1 parent cf40ba9 commit 03ac9af
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cns/restserver/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,13 +1129,14 @@ func (service *HTTPRestService) UpdateEndpointHandler(w http.ResponseWriter, r *
logger.Response(service.Name, response, response.ReturnCode, err)
}

// UpdateEndpointHelper updates the state of the given endpointId with HNSId or VethName
// UpdateEndpointHelper updates the state of the given endpointId with HNSId, VethName or other InterfaceInfo fields
func (service *HTTPRestService) UpdateEndpointHelper(endpointID string, req map[string]*IPInfo) error {
if service.EndpointStateStore == nil {
return ErrStoreEmpty
}
logger.Printf("[updateEndpoint] Updating endpoint state for infra container %s", endpointID)
if endpointInfo, ok := service.EndpointState[endpointID]; ok {
// Updating the InterfaceInfo map of endpoint states with the interfaceInfo map that is given by Stateless Azure CNI
for ifName, interfaceInfo := range req {
// This codition will create a map for SecodaryNIC and also also creates MAP entry for InfraNic in case that the initial goalState is using empty InterfaceName
if _, keyExist := service.EndpointState[endpointID].IfnameToIPMap[ifName]; !keyExist {
Expand Down
2 changes: 1 addition & 1 deletion network/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ func GetPodNameWithoutSuffix(podName string) string {

// IsEndpointStateInComplete returns true if both HNSEndpointID and HostVethName are missing.
func (epInfo *EndpointInfo) IsEndpointStateIncomplete() bool {
if epInfo.HNSEndpointID == "" && epInfo.IfName == "" {
if epInfo.HNSEndpointID == "" && epInfo.HostIfName == "" {
return true
}
return false
Expand Down
2 changes: 2 additions & 0 deletions network/endpoint_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ func (nm *networkManager) updateEndpointImpl(nw *network, existingEpInfo *Endpoi
// GetEndpointInfoByIPImpl returns an endpointInfo with the corrsponding HNS Endpoint ID that matches an specific IP Address.
func (epInfo *EndpointInfo) GetEndpointInfoByIPImpl(ipAddresses []net.IPNet, networkID string) (*EndpointInfo, error) {
// check if network exists, only create the network does not exist
logger.Info("Fetching missing HNS endpoint id for endpoints in network with id", zap.String("id", networkID))
hnsResponse, err := Hnsv2.GetNetworkByName(networkID)
if err != nil {
return epInfo, errors.Wrapf(err, "HNS Network not found")
Expand All @@ -513,6 +514,7 @@ func (epInfo *EndpointInfo) GetEndpointInfoByIPImpl(ipAddresses []net.IPNet, net
for _, ipAddress := range ipAddresses {
prefixLength, _ := ipAddress.Mask.Size()
if ipConfiguration.IpAddress == ipAddress.IP.String() && ipConfiguration.PrefixLength == uint8(prefixLength) {
logger.Info("Successfully found hcn endpoint id", zap.String("id", hcnEndpoints[i].Id))
epInfo.HNSEndpointID = hcnEndpoints[i].Id
return epInfo, nil
}
Expand Down
5 changes: 4 additions & 1 deletion network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
InfraInterfaceName = "eth0"
ContainerIDLength = 8
EndpointIfIndex = 0 // Azure CNI supports only one interface
DefaultNetworkID = "azure"
)

var Ipv4DefaultRouteDstPrefix = net.IPNet{
Expand Down Expand Up @@ -442,8 +443,10 @@ func (nm *networkManager) GetEndpointState(networkID, endpointID string) (*Endpo
return nil, errors.Wrapf(err, "Get endpoint API returend with error")
}
epInfo := cnsEndpointInfotoCNIEpInfo(endpointResponse.EndpointInfo, endpointID)

if epInfo.IsEndpointStateIncomplete() {
if networkID == "" {
networkID = DefaultNetworkID
}
epInfo, err = epInfo.GetEndpointInfoByIPImpl(epInfo.IPAddresses, networkID)
if err != nil {
return nil, errors.Wrapf(err, "Get endpoint API returend with error")
Expand Down

0 comments on commit 03ac9af

Please sign in to comment.