Skip to content

Commit 4f541e1

Browse files
committed
feat: adding stateless CNI support for ACI
1 parent 571afbc commit 4f541e1

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

cns/restserver/ipam.go

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,20 +1254,25 @@ func (service *HTTPRestService) UpdateEndpointHelper(endpointID string, req map[
12541254
return ErrStoreEmpty
12551255
}
12561256
logger.Printf("[updateEndpoint] Updating endpoint state for infra container %s", endpointID)
1257-
if endpointInfo, ok := service.EndpointState[endpointID]; ok {
1258-
// Updating the InterfaceInfo map of endpoint states with the interfaceInfo map that is given by Stateless Azure CNI
1259-
for ifName, interfaceInfo := range req {
1260-
// updating the ipInfoMap
1261-
updateIPInfoMap(endpointInfo.IfnameToIPMap, interfaceInfo, ifName, endpointID)
1262-
}
1263-
err := service.EndpointStateStore.Write(EndpointStoreKey, service.EndpointState)
1264-
if err != nil {
1265-
return fmt.Errorf("[updateEndpoint] failed to write endpoint state to store for pod %s : %w", endpointInfo.PodName, err)
1266-
}
1267-
logger.Printf("[updateEndpoint] successfully write the state to the file %s", endpointID)
1268-
return nil
1257+
endpointInfo, endpointExist := service.EndpointState[endpointID]
1258+
// create a new entry in case the ednpoint does not exist in the statefile.
1259+
// this applies to the ACI scenario when the endpoint is not added to the statefile when the goalstate is sent to CNI
1260+
if !endpointExist {
1261+
logger.Printf("[updateEndpoint] endpoint could not be found in the statefile %s, new entry is being added", endpointID)
1262+
endpointInfo = &EndpointInfo{PodName: "", PodNamespace: "", IfnameToIPMap: make(map[string]*IPInfo)}
1263+
service.EndpointState[endpointID] = endpointInfo
1264+
}
1265+
// updating the InterfaceInfo map of endpoint states with the interfaceInfo map that is given by Stateless Azure CNI
1266+
for ifName, interfaceInfo := range req {
1267+
// updating the ipInfoMap
1268+
updateIPInfoMap(endpointInfo.IfnameToIPMap, interfaceInfo, ifName, endpointID)
1269+
}
1270+
err := service.EndpointStateStore.Write(EndpointStoreKey, service.EndpointState)
1271+
if err != nil {
1272+
return fmt.Errorf("[updateEndpoint] failed to write endpoint state to store for pod %s : %w", endpointInfo.PodName, err)
12691273
}
1270-
return errors.New("[updateEndpoint] endpoint could not be found in the statefile")
1274+
logger.Printf("[updateEndpoint] successfully write the state to the file %s", endpointID)
1275+
return nil
12711276
}
12721277

12731278
// updateIPInfoMap updates the IfnameToIPMap of endpoint states with the interfaceInfo map that is given by Stateless Azure CNI

0 commit comments

Comments
 (0)