@@ -75,8 +75,7 @@ func (rl *ReconcileLooper) findOrphanedIPsPerPool(ipPools []storage.IPPool) erro
7575 _ = logging .Errorf ("pod ref missing for Allocations: %s" , ipReservation )
7676 continue
7777 }
78- if ! rl .isOrphanedIP (ipReservation .PodRef , ipReservation .IP .String ()) {
79- logging .Debugf ("pod ref %s is not listed in the live pods list" , ipReservation .PodRef )
78+ if rl .isOrphanedIP (ipReservation .PodRef , ipReservation .IP .String ()) {
8079 orphanIP .Allocations = append (orphanIP .Allocations , ipReservation )
8180 }
8281 }
@@ -88,49 +87,51 @@ func (rl *ReconcileLooper) findOrphanedIPsPerPool(ipPools []storage.IPPool) erro
8887 return nil
8988}
9089
91- func (rl ReconcileLooper ) isOrphanedIP (podRef string , ip string ) bool {
92- for livePodRef , livePod := range rl .liveWhereaboutsPods {
93- if podRef == livePodRef {
94- isFound := isIpOnPod (& livePod , podRef , ip )
95- if ! isFound && (livePod .phase == v1 .PodPending ) {
96- /* Sometimes pods are still coming up, and may not yet have Multus
97- * annotation added to it yet. We don't want to check the IPs yet
98- * so re-fetch the Pod 5x
99- */
100- podToMatch := & livePod
101- retries := 0
102-
103- logging .Debugf ("Re-fetching Pending Pod: %s IP-to-match: %s" , livePodRef , ip )
104-
105- for retries < storage .PodRefreshRetries {
106- retries += 1
107- podToMatch = rl .refreshPod (livePodRef )
108- if podToMatch == nil {
109- logging .Debugf ("Cleaning up..." )
110- return false
111- } else if podToMatch .phase != v1 .PodPending {
112- logging .Debugf ("Pending Pod is now in phase: %s" , podToMatch .phase )
113- break
114- } else {
115- isFound = isIpOnPod (podToMatch , podRef , ip )
116- // Short-circuit - Pending Pod may have IP now
117- if isFound {
118- logging .Debugf ("Pod now has IP annotation while in Pending" )
119- return true
120- }
121- time .Sleep (time .Duration (250 ) * time .Millisecond )
122- }
123- }
124- isFound = isIpOnPod (podToMatch , podRef , ip )
90+ func (rl * ReconcileLooper ) isOrphanedIP (podRef string , ip string ) bool {
91+ livePod , exists := rl .liveWhereaboutsPods [podRef ]
92+ if ! exists {
93+ logging .Debugf ("Pod %s not found in live pod list, IP %s is orphaned" , podRef , ip )
94+ return true
95+ }
96+
97+ isIPFoundOnPod := isIpOnPod (& livePod , podRef , ip )
98+ if isIPFoundOnPod {
99+ return false
100+ }
101+
102+ if livePod .phase == v1 .PodPending {
103+ podToMatch := & livePod
104+ retries := 0
105+
106+ logging .Debugf ("Re-fetching Pending Pod: %s IP-to-match: %s" , podRef , ip )
107+
108+ for retries < storage .PodRefreshRetries {
109+ retries ++
110+ podToMatch = rl .refreshPod (podRef )
111+ if podToMatch == nil {
112+ logging .Debugf ("Pod refresh could not fetch Pod, retrying %d more times" , (storage .PodRefreshRetries - retries ))
113+ continue
114+ }
115+ if podToMatch .phase != v1 .PodPending {
116+ logging .Debugf ("Pending Pod is now in phase: %s" , podToMatch .phase )
117+ break
125118 }
126119
127- return isFound
120+ isIPFoundOnPod = isIpOnPod (podToMatch , podRef , ip )
121+ if isIPFoundOnPod {
122+ logging .Debugf ("Found IP on refreshed pending pod, not orphaned" )
123+ return false
124+ }
125+ time .Sleep (time .Duration (250 ) * time .Millisecond )
128126 }
127+
128+ isIPFoundOnPod = isIpOnPod (podToMatch , podRef , ip )
129129 }
130- return false
130+
131+ return ! isIPFoundOnPod
131132}
132133
133- func (rl ReconcileLooper ) refreshPod (podRef string ) * podWrapper {
134+ func (rl * ReconcileLooper ) refreshPod (podRef string ) * podWrapper {
134135 namespace , podName := splitPodRef (podRef )
135136 if namespace == "" || podName == "" {
136137 logging .Errorf ("Invalid podRef format: %s" , podRef )
@@ -162,7 +163,7 @@ func composePodRef(pod v1.Pod) string {
162163 return fmt .Sprintf ("%s/%s" , pod .GetNamespace (), pod .GetName ())
163164}
164165
165- func (rl ReconcileLooper ) ReconcileIPPools () ([]net.IP , error ) {
166+ func (rl * ReconcileLooper ) ReconcileIPPools () ([]net.IP , error ) {
166167 findAllocationIndex := func (reservation types.IPReservation , reservations []types.IPReservation ) int {
167168 for idx , r := range reservations {
168169 if r .PodRef == reservation .PodRef && r .IP .Equal (reservation .IP ) {
@@ -225,16 +226,15 @@ func (rl *ReconcileLooper) findClusterWideIPReservations() error {
225226
226227 podRef := clusterWideIPReservation .Spec .PodRef
227228
228- if ! rl .isOrphanedIP (podRef , denormalizedip ) {
229- logging .Debugf ("pod ref %s is not listed in the live pods list" , podRef )
229+ if rl .isOrphanedIP (podRef , denormalizedip ) {
230230 rl .orphanedClusterWideIPs = append (rl .orphanedClusterWideIPs , clusterWideIPReservation )
231231 }
232232 }
233233
234234 return nil
235235}
236236
237- func (rl ReconcileLooper ) ReconcileOverlappingIPAddresses () error {
237+ func (rl * ReconcileLooper ) ReconcileOverlappingIPAddresses () error {
238238 var failedReconciledClusterWideIPs []string
239239
240240 for _ , overlappingIPStruct := range rl .orphanedClusterWideIPs {
0 commit comments