Skip to content

Commit 7bb198a

Browse files
Fixes leftover podref issue
Signed-off-by: Muhammad Adil Ghaffar <[email protected]>
1 parent c4d2f71 commit 7bb198a

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

pkg/controlloop/pod.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,10 @@ func (pc *PodController) garbageCollectPodIPs(pod *v1.Pod) error {
224224
if allocation.PodRef == podID(podNamespace, podName) {
225225
logging.Verbosef("stale allocation to cleanup: %+v", allocation)
226226

227-
client := *wbclient.NewKubernetesClient(nil, pc.k8sClient)
228-
wbClient := &wbclient.KubernetesIPAM{
229-
Client: client,
230-
Config: *ipamConfig,
231-
}
227+
client := *wbclient.NewKubernetesClient(pc.wbClient, pc.k8sClient)
228+
k8sIPAM := wbclient.NewKubernetesIPAMWithClient(allocation.ContainerID, allocation.IfName, *ipamConfig, pool.Namespace, client)
232229

233-
if err != nil {
234-
logging.Debugf("error while generating the IPAM client: %v", err)
235-
continue
236-
}
237-
if _, err := pc.cleanupFunc(context.TODO(), types.Deallocate, *ipamConfig, wbClient); err != nil {
230+
if _, err := pc.cleanupFunc(context.TODO(), types.Deallocate, *ipamConfig, k8sIPAM); err != nil {
238231
logging.Errorf("failed to cleanup allocation: %v", err)
239232
}
240233
if err := pc.addressGarbageCollected(pod, nad.GetName(), pool.Spec.Range, allocationIndex); err != nil {
@@ -244,7 +237,6 @@ func (pc *PodController) garbageCollectPodIPs(pod *v1.Pod) error {
244237
}
245238
}
246239
}
247-
248240
return nil
249241
}
250242

pkg/storage/kubernetes/ipam.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ func NewKubernetesIPAM(containerID, ifName string, ipamConf whereaboutstypes.IPA
7070
return k8sIPAM, nil
7171
}
7272

73+
// NewKubernetesIPAMWithClient returns a new KubernetesIPAM Client configured to a kubernetes CRD backend
74+
func NewKubernetesIPAMWithClient(containerID, ifName string, ipamConf whereaboutstypes.IPAMConfig, namespace string, kubernetesClient Client) *KubernetesIPAM {
75+
return &KubernetesIPAM{
76+
Config: ipamConf,
77+
containerID: containerID,
78+
IfName: ifName,
79+
namespace: namespace,
80+
Client: kubernetesClient,
81+
}
82+
}
83+
7384
// NewKubernetesIPAMWithNamespace returns a new KubernetesIPAM Client configured to a kubernetes CRD backend
7485
func NewKubernetesIPAMWithNamespace(containerID, ifName string, ipamConf whereaboutstypes.IPAMConfig, namespace string) (*KubernetesIPAM, error) {
7586
k8sIPAM, err := NewKubernetesIPAM(containerID, ifName, ipamConf)
@@ -180,7 +191,7 @@ type KubernetesIPPool struct {
180191

181192
// Allocations returns the initially retrieved set of allocations for this pool
182193
func (p *KubernetesIPPool) Allocations() []whereaboutstypes.IPReservation {
183-
return toIPReservationList(p.pool.Spec.Allocations, p.firstIP)
194+
return ToIPReservationList(p.pool.Spec.Allocations, p.firstIP)
184195
}
185196

186197
// Update sets the pool allocated IP list to the given IP reservations
@@ -240,7 +251,7 @@ func (p *KubernetesIPPool) Update(ctx context.Context, reservations []whereabout
240251
return nil
241252
}
242253

243-
func toIPReservationList(allocations map[string]whereaboutsv1alpha1.IPAllocation, firstip net.IP) []whereaboutstypes.IPReservation {
254+
func ToIPReservationList(allocations map[string]whereaboutsv1alpha1.IPAllocation, firstip net.IP) []whereaboutstypes.IPReservation {
244255
reservelist := []whereaboutstypes.IPReservation{}
245256
for offset, a := range allocations {
246257
numOffset, err := strconv.ParseInt(offset, 10, 64)

0 commit comments

Comments
 (0)