@@ -103,19 +103,73 @@ func (rl *ReconcileLooper) findOrphanedIPsPerPool(ipPools []storage.IPPool) erro
103103func (rl ReconcileLooper ) isPodAlive (podRef string , ip string ) bool {
104104 for livePodRef , livePod := range rl .liveWhereaboutsPods {
105105 if podRef == livePodRef {
106- livePodIPs := livePod .ips
107- logging .Debugf (
108- "pod reference %s matches allocation; Allocation IP: %s; PodIPs: %s" ,
109- livePodRef ,
110- ip ,
111- livePodIPs )
112- _ , isFound := livePodIPs [ip ]
113- return isFound || livePod .phase == v1 .PodPending
106+ isFound := isIpOnPod (& livePod , podRef , ip )
107+ if ! isFound && (livePod .phase == v1 .PodPending ) {
108+ /* Sometimes pods are still coming up, and may not yet have Multus
109+ * annotation added to it yet. We don't want to check the IPs yet
110+ * so re-fetch the Pod 5x
111+ */
112+ podToMatch := & livePod
113+ retries := 0
114+
115+ logging .Debugf ("Re-fetching Pending Pod: %s IP-to-match: %s" , livePodRef , ip )
116+
117+ for retries < storage .PodRefreshRetries {
118+ retries += 1
119+ podToMatch = rl .refreshPod (livePodRef )
120+ if podToMatch == nil {
121+ logging .Debugf ("Cleaning up..." )
122+ return false
123+ } else if podToMatch .phase != v1 .PodPending {
124+ logging .Debugf ("Pending Pod is now in phase: %s" , podToMatch .phase )
125+ break
126+ } else {
127+ isFound = isIpOnPod (podToMatch , podRef , ip )
128+ // Short-circuit - Pending Pod may have IP now
129+ if isFound {
130+ logging .Debugf ("Pod now has IP annotation while in Pending" )
131+ return true
132+ }
133+ time .Sleep (time .Duration (500 ) * time .Millisecond )
134+ }
135+ }
136+ isFound = isIpOnPod (podToMatch , podRef , ip )
137+ }
138+
139+ return isFound
114140 }
115141 }
116142 return false
117143}
118144
145+ func (rl ReconcileLooper ) refreshPod (podRef string ) * podWrapper {
146+ namespace , podName := splitPodRef (podRef )
147+ if namespace == "" || podName == "" {
148+ logging .Errorf ("Invalid podRef format: %s" , podRef )
149+ return nil
150+ }
151+
152+ pod , err := rl .k8sClient .GetPod (namespace , podName )
153+ if err != nil {
154+ logging .Errorf ("Failed to refresh Pod %s: %s\n " , podRef , err )
155+ return nil
156+ }
157+
158+ wrappedPod := wrapPod (* pod )
159+ logging .Debugf ("Got refreshed pod: %v" , wrappedPod )
160+ return wrappedPod
161+ }
162+
163+ func splitPodRef (podRef string ) (string , string ) {
164+ namespacedName := strings .Split (podRef , "/" )
165+ if len (namespacedName ) != 2 {
166+ logging .Errorf ("Failed to split podRef %s" , podRef )
167+ return "" , ""
168+ }
169+
170+ return namespacedName [0 ], namespacedName [1 ]
171+ }
172+
119173func composePodRef (pod v1.Pod ) string {
120174 return fmt .Sprintf ("%s/%s" , pod .GetNamespace (), pod .GetName ())
121175}
0 commit comments