@@ -89,11 +89,15 @@ func (c *PodController) needSync(eventType string, obj interface{}) (string, boo
8989 return key , needSync
9090 }
9191
92+ klog .Infof ("[POD %s EVENT] for %s in %s" , eventType , podObj .Name , podObj .Namespace )
93+
9294 if ! hasValidPodIP (podObj ) {
9395 return key , needSync
9496 }
9597
9698 if isHostNetworkPod (podObj ) {
99+ klog .Infof ("[POD %s EVENT] HostNetwork POD IGNORED: [%s/%s/%s/%+v%s]" ,
100+ eventType , podObj .GetObjectMeta ().GetUID (), podObj .Namespace , podObj .Name , podObj .Labels , podObj .Status .PodIP )
97101 return key , needSync
98102 }
99103
@@ -128,6 +132,7 @@ func (c *PodController) addPod(obj interface{}) {
128132func (c * PodController ) updatePod (old , newp interface {}) {
129133 key , needSync := c .needSync ("UPDATE" , newp )
130134 if ! needSync {
135+ klog .Infof ("[POD UPDATE EVENT] No need to sync this pod" )
131136 return
132137 }
133138
@@ -138,6 +143,7 @@ func (c *PodController) updatePod(old, newp interface{}) {
138143 if oldPod .ResourceVersion == newPod .ResourceVersion {
139144 // Periodic resync will send update events for all known pods.
140145 // Two different versions of the same pods will always have different RVs.
146+ klog .Infof ("[POD UPDATE EVENT] Two pods have the same RVs" )
141147 return
142148 }
143149 }
@@ -164,7 +170,9 @@ func (c *PodController) deletePod(obj interface{}) {
164170 }
165171 }
166172
173+ klog .Infof ("[POD DELETE EVENT] for %s in %s" , podObj .Name , podObj .Namespace )
167174 if isHostNetworkPod (podObj ) {
175+ klog .Infof ("[POD DELETE EVENT] HostNetwork POD IGNORED: [%s/%s/%s/%+v%s]" , podObj .UID , podObj .Namespace , podObj .Name , podObj .Labels , podObj .Status .PodIP )
168176 return
169177 }
170178
@@ -184,9 +192,12 @@ func (c *PodController) Run(stopCh <-chan struct{}) {
184192 defer utilruntime .HandleCrash ()
185193 defer c .workqueue .ShutDown ()
186194
195+ klog .Infof ("Starting Pod worker" )
187196 go wait .Until (c .runWorker , time .Second , stopCh )
188197
198+ klog .Info ("Started Pod workers" )
189199 <- stopCh
200+ klog .Info ("Shutting down Pod workers" )
190201}
191202
192203func (c * PodController ) runWorker () {
@@ -224,6 +235,7 @@ func (c *PodController) processNextWorkItem() bool {
224235 // Finally, if no error occurs we Forget this item so it does not
225236 // get queued again until another change happens.
226237 c .workqueue .Forget (obj )
238+ klog .Infof ("Successfully synced '%s'" , key )
227239 return nil
228240 }(obj )
229241 if err != nil {
@@ -313,11 +325,14 @@ func (c *PodController) syncPod(key string) error {
313325}
314326
315327func (c * PodController ) syncAddedPod (podObj * corev1.Pod ) error {
328+ klog .Infof ("POD CREATING: [%s%s/%s/%s%+v%s]" , string (podObj .GetUID ()), podObj .Namespace ,
329+ podObj .Name , podObj .Spec .NodeName , podObj .Labels , podObj .Status .PodIP )
316330
317331 var err error
318332 podNs := util .GetNSNameWithPrefix (podObj .Namespace )
319333 podKey , _ := cache .MetaNamespaceKeyFunc (podObj )
320334 // Add the pod ip information into namespace's ipset.
335+ klog .Infof ("Adding pod %s to ipset %s" , podObj .Status .PodIP , podNs )
321336 if err = c .ipsMgr .AddToSet (podNs , podObj .Status .PodIP , util .IpsetNetHashFlag , podKey ); err != nil {
322337 return fmt .Errorf ("[syncAddedPod] Error: failed to add pod to namespace ipset with err: %w" , err )
323338 }
@@ -328,18 +343,21 @@ func (c *PodController) syncAddedPod(podObj *corev1.Pod) error {
328343
329344 // Get lists of podLabelKey and podLabelKey + podLavelValue ,and then start adding them to ipsets.
330345 for labelKey , labelVal := range podObj .Labels {
346+ klog .Infof ("Adding pod %s to ipset %s" , npmPodObj .PodIP , labelKey )
331347 if err = c .ipsMgr .AddToSet (labelKey , npmPodObj .PodIP , util .IpsetNetHashFlag , podKey ); err != nil {
332348 return fmt .Errorf ("[syncAddedPod] Error: failed to add pod to label ipset with err: %w" , err )
333349 }
334350
335351 podIPSetName := util .GetIpSetFromLabelKV (labelKey , labelVal )
352+ klog .Infof ("Adding pod %s to ipset %s" , npmPodObj .PodIP , podIPSetName )
336353 if err = c .ipsMgr .AddToSet (podIPSetName , npmPodObj .PodIP , util .IpsetNetHashFlag , podKey ); err != nil {
337354 return fmt .Errorf ("[syncAddedPod] Error: failed to add pod to label ipset with err: %w" , err )
338355 }
339356 npmPodObj .AppendLabels (map [string ]string {labelKey : labelVal }, common .AppendToExistingLabels )
340357 }
341358
342359 // Add pod's named ports from its ipset.
360+ klog .Infof ("Adding named port ipsets" )
343361 containerPorts := common .GetContainerPortList (podObj )
344362 if err = c .manageNamedPortIpsets (containerPorts , podKey , npmPodObj .PodIP , addNamedPort ); err != nil {
345363 return fmt .Errorf ("[syncAddedPod] Error: failed to add pod to named port ipset with err: %w" , err )
@@ -378,6 +396,7 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
378396
379397 podKey , _ := cache .MetaNamespaceKeyFunc (newPodObj )
380398 cachedNpmPod , exists := c .podMap [podKey ]
399+ klog .Infof ("[syncAddAndUpdatePod] updating Pod with key %s" , podKey )
381400 // No cached npmPod exists. start adding the pod in a cache
382401 if ! exists {
383402 if err = c .syncAddedPod (newPodObj ); err != nil {
@@ -396,10 +415,15 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
396415 // NPM should clean up existing references of cached pod obj and its IP.
397416 // then, re-add new pod obj.
398417 if cachedNpmPod .PodIP != newPodObj .Status .PodIP {
418+ klog .Infof ("Pod (Namespace:%s, Name:%s, newUid:%s), has cachedPodIp:%s which is different from PodIp:%s" ,
419+ newPodObj .Namespace , newPodObj .Name , string (newPodObj .UID ), cachedNpmPod .PodIP , newPodObj .Status .PodIP )
420+
421+ klog .Infof ("Deleting cached Pod with key:%s first due to IP Mistmatch" , podKey )
399422 if err = c .cleanUpDeletedPod (podKey ); err != nil {
400423 return metrics .UpdateOp , err
401424 }
402425
426+ klog .Infof ("Adding back Pod with key:%s after IP Mistmatch" , podKey )
403427 if err = c .syncAddedPod (newPodObj ); err != nil {
404428 return metrics .UpdateOp , err
405429 }
@@ -414,6 +438,7 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
414438
415439 // Delete the pod from its label's ipset.
416440 for _ , podIPSetName := range deleteFromIPSets {
441+ klog .Infof ("Deleting pod %s from ipset %s" , cachedNpmPod .PodIP , podIPSetName )
417442 if err = c .ipsMgr .DeleteFromSet (podIPSetName , cachedNpmPod .PodIP , podKey ); err != nil {
418443 return metrics .UpdateOp , fmt .Errorf ("[syncAddAndUpdatePod] Error: failed to delete pod from label ipset with err: %w" , err )
419444 }
@@ -427,6 +452,7 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
427452
428453 // Add the pod to its label's ipset.
429454 for _ , addIPSetName := range addToIPSets {
455+ klog .Infof ("Adding pod %s to ipset %s" , newPodObj .Status .PodIP , addIPSetName )
430456 if err = c .ipsMgr .AddToSet (addIPSetName , newPodObj .Status .PodIP , util .IpsetNetHashFlag , podKey ); err != nil {
431457 return metrics .UpdateOp , fmt .Errorf ("[syncAddAndUpdatePod] Error: failed to add pod to label ipset with err: %w" , err )
432458 }
@@ -469,6 +495,7 @@ func (c *PodController) syncAddAndUpdatePod(newPodObj *corev1.Pod) (metrics.Oper
469495
470496// cleanUpDeletedPod cleans up all ipset associated with this pod
471497func (c * PodController ) cleanUpDeletedPod (cachedNpmPodKey string ) error {
498+ klog .Infof ("[cleanUpDeletedPod] deleting Pod with key %s" , cachedNpmPodKey )
472499 // If cached npmPod does not exist, return nil
473500 cachedNpmPod , exist := c .podMap [cachedNpmPodKey ]
474501 if ! exist {
@@ -484,11 +511,13 @@ func (c *PodController) cleanUpDeletedPod(cachedNpmPodKey string) error {
484511
485512 // Get lists of podLabelKey and podLabelKey + podLavelValue ,and then start deleting them from ipsets
486513 for labelKey , labelVal := range cachedNpmPod .Labels {
514+ klog .Infof ("Deleting pod %s from ipset %s" , cachedNpmPod .PodIP , labelKey )
487515 if err = c .ipsMgr .DeleteFromSet (labelKey , cachedNpmPod .PodIP , cachedNpmPodKey ); err != nil {
488516 return fmt .Errorf ("[cleanUpDeletedPod] Error: failed to delete pod from label ipset with err: %w" , err )
489517 }
490518
491519 podIPSetName := util .GetIpSetFromLabelKV (labelKey , labelVal )
520+ klog .Infof ("Deleting pod %s from ipset %s" , cachedNpmPod .PodIP , podIPSetName )
492521 if err = c .ipsMgr .DeleteFromSet (podIPSetName , cachedNpmPod .PodIP , cachedNpmPodKey ); err != nil {
493522 return fmt .Errorf ("[cleanUpDeletedPod] Error: failed to delete pod from label ipset with err: %w" , err )
494523 }
@@ -509,6 +538,7 @@ func (c *PodController) cleanUpDeletedPod(cachedNpmPodKey string) error {
509538func (c * PodController ) manageNamedPortIpsets (portList []corev1.ContainerPort , podKey string ,
510539 podIP string , namedPortOperation NamedPortOperation ) error {
511540 for _ , port := range portList {
541+ klog .Infof ("port is %+v" , port )
512542 if port .Name == "" {
513543 continue
514544 }
0 commit comments