@@ -215,36 +215,42 @@ func (npMgr *NetworkPolicyManager) AddPod(podObj *corev1.Pod) error {
215215 npMgr .NsMap [podNs ], err = newNs (podNs )
216216 if err != nil {
217217 metrics .SendErrorLogAndMetric (util .PodID , "[AddPod] Error: failed to create namespace %s with err: %v" , podNs , err )
218+ return err
218219 }
219220 log .Logf ("Creating set: %v, hashedSet: %v" , podNs , util .GetHashedName (podNs ))
220221 if err = ipsMgr .CreateSet (podNs , append ([]string {util .IpsetNetHashFlag })); err != nil {
221222 metrics .SendErrorLogAndMetric (util .PodID , "[AddPod] Error: creating ipset %s with err: %v" , podNs , err )
223+ return err
222224 }
223225 }
224226
225227 // Add the pod to its namespace's ipset.
226228 log .Logf ("Adding pod %s to ipset %s" , podIP , podNs )
227229 if err = ipsMgr .AddToSet (podNs , podIP , util .IpsetNetHashFlag , podUID ); err != nil {
228230 metrics .SendErrorLogAndMetric (util .PodID , "[AddPod] Error: failed to add pod to namespace ipset with err: %v" , err )
231+ return err
229232 }
230233
231234 // Add the pod to its label's ipset.
232235 for podLabelKey , podLabelVal := range podLabels {
233236 log .Logf ("Adding pod %s to ipset %s" , podIP , podLabelKey )
234237 if err = ipsMgr .AddToSet (podLabelKey , podIP , util .IpsetNetHashFlag , podUID ); err != nil {
235238 metrics .SendErrorLogAndMetric (util .PodID , "[AddPod] Error: failed to add pod to label ipset with err: %v" , err )
239+ return err
236240 }
237241
238242 label := podLabelKey + ":" + podLabelVal
239243 log .Logf ("Adding pod %s to ipset %s" , podIP , label )
240244 if err = ipsMgr .AddToSet (label , podIP , util .IpsetNetHashFlag , podUID ); err != nil {
241245 metrics .SendErrorLogAndMetric (util .PodID , "[AddPod] Error: failed to add pod to label ipset with err: %v" , err )
246+ return err
242247 }
243248 }
244249
245250 // Add pod's named ports from its ipset.
246251 if err = appendNamedPortIpsets (ipsMgr , podContainerPorts , podUID , podIP , false ); err != nil {
247252 metrics .SendErrorLogAndMetric (util .PodID , "[AddPod] Error: failed to add pod to namespace ipset with err: %v" , err )
253+ return err
248254 }
249255
250256 // add the Pod info to the podMap
@@ -291,17 +297,20 @@ func (npMgr *NetworkPolicyManager) UpdatePod(newPodObj *corev1.Pod) error {
291297 npMgr .NsMap [newPodObjNs ], err = newNs (newPodObjNs )
292298 if err != nil {
293299 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to create namespace %s with err: %v" , newPodObjNs , err )
300+ return err
294301 }
295302 log .Logf ("Creating set: %v, hashedSet: %v" , newPodObjNs , util .GetHashedName (newPodObjNs ))
296303 if err = ipsMgr .CreateSet (newPodObjNs , append ([]string {util .IpsetNetHashFlag })); err != nil {
297304 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error creating ipset %s with err: %v" , newPodObjNs , err )
305+ return err
298306 }
299307 }
300308
301309 cachedPodObj , exists := npMgr .PodMap [podKey ]
302310 if ! exists {
303311 if addErr := npMgr .AddPod (newPodObj ); addErr != nil {
304312 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to add pod during update with error %+v" , addErr )
313+ return addErr
305314 }
306315 return nil
307316 }
@@ -328,6 +337,7 @@ func (npMgr *NetworkPolicyManager) UpdatePod(newPodObj *corev1.Pod) error {
328337 if newPodObj .Status .Phase == v1 .PodSucceeded || newPodObj .Status .Phase == v1 .PodFailed {
329338 if delErr := npMgr .DeletePod (newPodObj ); delErr != nil {
330339 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to add pod during update with error %+v" , delErr )
340+ return delErr
331341 }
332342
333343 return nil
@@ -369,10 +379,12 @@ func (npMgr *NetworkPolicyManager) UpdatePod(newPodObj *corev1.Pod) error {
369379 )
370380 if err = ipsMgr .DeleteFromSet (cachedPodObj .Namespace , cachedPodIP , cachedPodObj .PodUID ); err != nil {
371381 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to delete pod from namespace ipset with err: %v" , err )
382+ return err
372383 }
373384 // Add the pod to its namespace's ipset.
374385 if err = ipsMgr .AddToSet (newPodObjNs , newPodObjIP , util .IpsetNetHashFlag , cachedPodObj .PodUID ); err != nil {
375386 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to add pod to namespace ipset with err: %v" , err )
387+ return err
376388 }
377389 } else {
378390 //if no change in labels then return
@@ -392,6 +404,7 @@ func (npMgr *NetworkPolicyManager) UpdatePod(newPodObj *corev1.Pod) error {
392404 log .Logf ("Deleting pod %s from ipset %s" , cachedPodIP , podIPSetName )
393405 if err = ipsMgr .DeleteFromSet (podIPSetName , cachedPodIP , cachedPodObj .PodUID ); err != nil {
394406 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to delete pod from label ipset with err: %v" , err )
407+ return err
395408 }
396409 }
397410
@@ -400,6 +413,7 @@ func (npMgr *NetworkPolicyManager) UpdatePod(newPodObj *corev1.Pod) error {
400413 log .Logf ("Adding pod %s to ipset %s" , newPodObjIP , addIPSetName )
401414 if err = ipsMgr .AddToSet (addIPSetName , newPodObjIP , util .IpsetNetHashFlag , cachedPodObj .PodUID ); err != nil {
402415 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to add pod to label ipset with err: %v" , err )
416+ return err
403417 }
404418 }
405419
@@ -411,10 +425,12 @@ func (npMgr *NetworkPolicyManager) UpdatePod(newPodObj *corev1.Pod) error {
411425 // Delete cached pod's named ports from its ipset.
412426 if err = appendNamedPortIpsets (ipsMgr , cachedPodObj .ContainerPorts , cachedPodObj .PodUID , cachedPodIP , true ); err != nil {
413427 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to delete pod from namespace ipset with err: %v" , err )
428+ return err
414429 }
415430 // Add new pod's named ports from its ipset.
416431 if err = appendNamedPortIpsets (ipsMgr , newPodPorts , cachedPodObj .PodUID , newPodObjIP , false ); err != nil {
417432 metrics .SendErrorLogAndMetric (util .PodID , "[UpdatePod] Error: failed to add pod to namespace ipset with err: %v" , err )
433+ return err
418434 }
419435 }
420436
@@ -470,25 +486,29 @@ func (npMgr *NetworkPolicyManager) DeletePod(podObj *corev1.Pod) error {
470486 // Delete the pod from its namespace's ipset.
471487 if err = ipsMgr .DeleteFromSet (podNs , cachedPodIP , podUID ); err != nil {
472488 metrics .SendErrorLogAndMetric (util .PodID , "[DeletePod] Error: failed to delete pod from namespace ipset with err: %v" , err )
489+ return err
473490 }
474491
475492 // Delete the pod from its label's ipset.
476493 for podLabelKey , podLabelVal := range podLabels {
477494 log .Logf ("Deleting pod %s from ipset %s" , cachedPodIP , podLabelKey )
478495 if err = ipsMgr .DeleteFromSet (podLabelKey , cachedPodIP , podUID ); err != nil {
479496 metrics .SendErrorLogAndMetric (util .PodID , "[DeletePod] Error: failed to delete pod from label ipset with err: %v" , err )
497+ return err
480498 }
481499
482500 label := podLabelKey + ":" + podLabelVal
483501 log .Logf ("Deleting pod %s from ipset %s" , cachedPodIP , label )
484502 if err = ipsMgr .DeleteFromSet (label , cachedPodIP , podUID ); err != nil {
485503 metrics .SendErrorLogAndMetric (util .PodID , "[DeletePod] Error: failed to delete pod from label ipset with err: %v" , err )
504+ return err
486505 }
487506 }
488507
489508 // Delete pod's named ports from its ipset. Delete is TRUE
490509 if err = appendNamedPortIpsets (ipsMgr , containerPorts , podUID , cachedPodIP , true ); err != nil {
491510 metrics .SendErrorLogAndMetric (util .PodID , "[DeletePod] Error: failed to delete pod from namespace ipset with err: %v" , err )
511+ return err
492512 }
493513
494514 delete (npMgr .PodMap , podKey )
0 commit comments