@@ -1260,20 +1260,25 @@ func (service *HTTPRestService) UpdateEndpointHelper(endpointID string, req map[
12601260 return ErrStoreEmpty
12611261 }
12621262 logger .Printf ("[updateEndpoint] Updating endpoint state for infra container %s" , endpointID )
1263- if endpointInfo , ok := service .EndpointState [endpointID ]; ok {
1264- // Updating the InterfaceInfo map of endpoint states with the interfaceInfo map that is given by Stateless Azure CNI
1265- for ifName , interfaceInfo := range req {
1266- // updating the ipInfoMap
1267- updateIPInfoMap (endpointInfo .IfnameToIPMap , interfaceInfo , ifName , endpointID )
1268- }
1269- err := service .EndpointStateStore .Write (EndpointStoreKey , service .EndpointState )
1270- if err != nil {
1271- return fmt .Errorf ("[updateEndpoint] failed to write endpoint state to store for pod %s : %w" , endpointInfo .PodName , err )
1272- }
1273- logger .Printf ("[updateEndpoint] successfully write the state to the file %s" , endpointID )
1274- return nil
1263+ endpointInfo , endpointExist := service .EndpointState [endpointID ]
1264+ // create a new entry in case the ednpoint does not exist in the statefile.
1265+ // this applies to the ACI scenario when the endpoint is not added to the statefile when the goalstate is sent to CNI
1266+ if ! endpointExist {
1267+ logger .Printf ("[updateEndpoint] endpoint could not be found in the statefile %s, new entry is being added" , endpointID )
1268+ endpointInfo = & EndpointInfo {PodName : "" , PodNamespace : "" , IfnameToIPMap : make (map [string ]* IPInfo )}
1269+ service .EndpointState [endpointID ] = endpointInfo
1270+ }
1271+ // updating the InterfaceInfo map of endpoint states with the interfaceInfo map that is given by Stateless Azure CNI
1272+ for ifName , interfaceInfo := range req {
1273+ // updating the ipInfoMap
1274+ updateIPInfoMap (endpointInfo .IfnameToIPMap , interfaceInfo , ifName , endpointID )
1275+ }
1276+ err := service .EndpointStateStore .Write (EndpointStoreKey , service .EndpointState )
1277+ if err != nil {
1278+ return fmt .Errorf ("[updateEndpoint] failed to write endpoint state to store for pod %s : %w" , endpointInfo .PodName , err )
12751279 }
1276- return errors .New ("[updateEndpoint] endpoint could not be found in the statefile" )
1280+ logger .Printf ("[updateEndpoint] successfully write the state to the file %s" , endpointID )
1281+ return nil
12771282}
12781283
12791284// updateIPInfoMap updates the IfnameToIPMap of endpoint states with the interfaceInfo map that is given by Stateless Azure CNI
0 commit comments