@@ -73,6 +73,16 @@ type podResolution struct {
7373 err error
7474}
7575
76+ func (pr podResolution ) String () string {
77+ if pr .err != nil {
78+ return fmt .Sprintf ("error: %s" , pr .err )
79+ }
80+ if pr .pod .Status .PodIP == "" {
81+ return "no pod IP available yet"
82+ }
83+ return fmt .Sprintf ("pod resolved to IP %s" , pr .pod .Status .PodIP )
84+ }
85+
7686// podWatcher owns a single Get+Watch loop for a specific (namespace, podName)
7787// pair. Multiple kubeResolvers can subscribe to the same podWatcher.
7888type podWatcher struct {
@@ -109,7 +119,9 @@ func (pw *podWatcher) subscribe(r *kubeResolver, cb func(podResolution)) {
109119 pw .mu .Lock ()
110120 pw .subscribers [r ] = cb
111121 if pw .latestResolution != nil {
122+ log .Infof ("Sending existing state to new subscriber for pod %s/%s. Notification: %s" , pw .namespace , pw .podName , pw .latestResolution )
112123 cb (* pw .latestResolution )
124+ log .Infof ("Finished sending existing state to new subscriber for pod %s/%s." , pw .namespace , pw .podName )
113125 }
114126 pw .mu .Unlock ()
115127}
@@ -131,9 +143,11 @@ func (pw *podWatcher) notifySubscribers(r podResolution) {
131143 }
132144 pw .mu .Unlock ()
133145
146+ log .Infof ("Notifying %d subscribers for pod %s/%s. Notification: %s" , len (callbacks ), pw .namespace , pw .podName , r )
134147 for _ , cb := range callbacks {
135148 cb (r )
136149 }
150+ log .Infof ("Finished notifying %d subscribers for pod %s/%s" , len (callbacks ), pw .namespace , pw .podName )
137151}
138152
139153// resolve does a one-shot List for the pod and notifies subscribers.
@@ -372,7 +386,6 @@ func (r *kubeResolver) updateStateFromPod(pod *corev1.Pod) {
372386 ip := pod .Status .PodIP
373387 // This will happen when a pod restarts.
374388 if ip == "" {
375- log .Infof ("Pod %s/%s doesn't have an IP yet" , r .podTarget .namespace , r .podTarget .podName )
376389 // If we previously reported an IP, reporting an error should cause
377390 // the balancer to close existing connections to the old IP.
378391 r .cc .ReportError (fmt .Errorf ("pod %s/%s doesn't have an IP yet" , r .podTarget .namespace , r .podTarget .podName ))
@@ -384,8 +397,6 @@ func (r *kubeResolver) updateStateFromPod(pod *corev1.Pod) {
384397 addr = ip + ":" + r .podTarget .port
385398 }
386399
387- log .Infof ("Pod %s/%s resolved to IP %s" , r .podTarget .namespace , r .podTarget .podName , ip )
388-
389400 err := r .cc .UpdateState (resolver.State {
390401 Addresses : []resolver.Address {{Addr : addr }},
391402 })
0 commit comments