Skip to content

Commit 2dd0c8f

Browse files
Fixes leftover podref issue
Signed-off-by: Muhammad Adil Ghaffar <[email protected]>
1 parent 807db9d commit 2dd0c8f

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

pkg/controlloop/pod.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,16 @@ 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,
227+
client := *wbclient.NewKubernetesClient(pc.wbClient, pc.k8sClient)
228+
k8sIPAM := &wbclient.KubernetesIPAM{
229+
Config: *ipamConfig,
230+
ContainerID: allocation.ContainerID,
231+
IfName: allocation.IfName,
232+
Namespace: pool.Namespace,
233+
Client: client,
231234
}
232235

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 {
236+
if _, err := pc.cleanupFunc(context.TODO(), types.Deallocate, *ipamConfig, k8sIPAM); err != nil {
238237
logging.Errorf("failed to cleanup allocation: %v", err)
239238
}
240239
if err := pc.addressGarbageCollected(pod, nad.GetName(), pool.Spec.Range, allocationIndex); err != nil {
@@ -244,7 +243,6 @@ func (pc *PodController) garbageCollectPodIPs(pod *v1.Pod) error {
244243
}
245244
}
246245
}
247-
248246
return nil
249247
}
250248

pkg/storage/kubernetes/ipam.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ const UnnamedNetwork string = ""
3636
type KubernetesIPAM struct {
3737
Client
3838
Config whereaboutstypes.IPAMConfig
39-
namespace string
40-
containerID string
39+
Namespace string
40+
ContainerID string
4141
IfName string
4242
}
4343

4444
func newKubernetesIPAM(containerID, ifName string, ipamConf whereaboutstypes.IPAMConfig, namespace string, kubernetesClient Client) *KubernetesIPAM {
4545
return &KubernetesIPAM{
4646
Config: ipamConf,
47-
containerID: containerID,
47+
ContainerID: containerID,
4848
IfName: ifName,
49-
namespace: namespace,
49+
Namespace: namespace,
5050
Client: kubernetesClient,
5151
}
5252
}
@@ -76,7 +76,7 @@ func NewKubernetesIPAMWithNamespace(containerID, ifName string, ipamConf whereab
7676
if err != nil {
7777
return nil, err
7878
}
79-
k8sIPAM.namespace = namespace
79+
k8sIPAM.Namespace = namespace
8080
return k8sIPAM, nil
8181
}
8282

@@ -137,14 +137,14 @@ func (i *KubernetesIPAM) getPool(ctx context.Context, name string, iprange strin
137137
ctxWithTimeout, cancel := context.WithTimeout(ctx, storage.RequestTimeout)
138138
defer cancel()
139139

140-
pool, err := i.client.WhereaboutsV1alpha1().IPPools(i.namespace).Get(ctxWithTimeout, name, metav1.GetOptions{})
140+
pool, err := i.client.WhereaboutsV1alpha1().IPPools(i.Namespace).Get(ctxWithTimeout, name, metav1.GetOptions{})
141141
if err != nil && errors.IsNotFound(err) {
142142
// pool does not exist, create it
143143
newPool := &whereaboutsv1alpha1.IPPool{}
144144
newPool.ObjectMeta.Name = name
145145
newPool.Spec.Range = iprange
146146
newPool.Spec.Allocations = make(map[string]whereaboutsv1alpha1.IPAllocation)
147-
_, err = i.client.WhereaboutsV1alpha1().IPPools(i.namespace).Create(ctxWithTimeout, newPool, metav1.CreateOptions{})
147+
_, err = i.client.WhereaboutsV1alpha1().IPPools(i.Namespace).Create(ctxWithTimeout, newPool, metav1.CreateOptions{})
148148
if err != nil && errors.IsAlreadyExists(err) {
149149
// the pool was just created -- allow retry
150150
return nil, &temporaryError{err}
@@ -162,7 +162,7 @@ func (i *KubernetesIPAM) getPool(ctx context.Context, name string, iprange strin
162162

163163
// Status tests connectivity to the kubernetes backend
164164
func (i *KubernetesIPAM) Status(ctx context.Context) error {
165-
_, err := i.client.WhereaboutsV1alpha1().IPPools(i.namespace).List(ctx, metav1.ListOptions{})
165+
_, err := i.client.WhereaboutsV1alpha1().IPPools(i.Namespace).List(ctx, metav1.ListOptions{})
166166
return err
167167
}
168168

@@ -276,7 +276,7 @@ type KubernetesOverlappingRangeStore struct {
276276

277277
// GetOverlappingRangeStore returns a clusterstore interface
278278
func (i *KubernetesIPAM) GetOverlappingRangeStore() (storage.OverlappingRangeStore, error) {
279-
return &KubernetesOverlappingRangeStore{i.client, i.namespace}, nil
279+
return &KubernetesOverlappingRangeStore{i.client, i.Namespace}, nil
280280
}
281281

282282
// IsAllocatedInOverlappingRange checks for IP addresses to see if they're allocated cluster wide, for overlapping
@@ -463,7 +463,7 @@ func IPManagement(ctx context.Context, mode int, ipamConf whereaboutstypes.IPAMC
463463
}
464464

465465
// setup leader election
466-
le, leader, deposed := newLeaderElector(ctx, client.clientSet, client.namespace, client)
466+
le, leader, deposed := newLeaderElector(ctx, client.clientSet, client.Namespace, client)
467467
var wg sync.WaitGroup
468468
wg.Add(2)
469469

@@ -517,10 +517,10 @@ func IPManagement(ctx context.Context, mode int, ipamConf whereaboutstypes.IPAMC
517517
}
518518

519519
func GetNodeSlicePoolRange(ctx context.Context, ipam *KubernetesIPAM, nodeName string) (string, error) {
520-
logging.Debugf("ipam namespace is %v", ipam.namespace)
521-
nodeSlice, err := ipam.client.WhereaboutsV1alpha1().NodeSlicePools(ipam.namespace).Get(ctx, getNodeSliceName(ipam), metav1.GetOptions{})
520+
logging.Debugf("ipam namespace is %v", ipam.Namespace)
521+
nodeSlice, err := ipam.client.WhereaboutsV1alpha1().NodeSlicePools(ipam.Namespace).Get(ctx, getNodeSliceName(ipam), metav1.GetOptions{})
522522
if err != nil {
523-
logging.Errorf("error getting node slice %s/%s %v", ipam.namespace, getNodeSliceName(ipam), err)
523+
logging.Errorf("error getting node slice %s/%s %v", ipam.Namespace, getNodeSliceName(ipam), err)
524524
return "", err
525525
}
526526
for _, allocation := range nodeSlice.Status.Allocations {
@@ -542,7 +542,7 @@ func getNodeSliceName(ipam *KubernetesIPAM) string {
542542

543543
// IPManagementKubernetesUpdate manages k8s updates
544544
func IPManagementKubernetesUpdate(ctx context.Context, mode int, ipam *KubernetesIPAM, ipamConf whereaboutstypes.IPAMConfig) ([]net.IPNet, error) {
545-
logging.Debugf("IPManagement -- mode: %d / containerID: %q / podRef: %q / ifName: %q ", mode, ipam.containerID, ipamConf.GetPodRef(), ipam.IfName)
545+
logging.Debugf("IPManagement -- mode: %d / containerID: %q / podRef: %q / ifName: %q ", mode, ipam.ContainerID, ipamConf.GetPodRef(), ipam.IfName)
546546

547547
var newips []net.IPNet
548548
var newip net.IPNet
@@ -633,7 +633,7 @@ func IPManagementKubernetesUpdate(ctx context.Context, mode int, ipam *Kubernete
633633
var updatedreservelist []whereaboutstypes.IPReservation
634634
switch mode {
635635
case whereaboutstypes.Allocate:
636-
newip, updatedreservelist, err = allocate.AssignIP(ipRange, reservelist, ipam.containerID, ipamConf.GetPodRef(), ipam.IfName)
636+
newip, updatedreservelist, err = allocate.AssignIP(ipRange, reservelist, ipam.ContainerID, ipamConf.GetPodRef(), ipam.IfName)
637637
if err != nil {
638638
logging.Errorf("Error assigning IP: %v", err)
639639
return newips, err
@@ -664,10 +664,10 @@ func IPManagementKubernetesUpdate(ctx context.Context, mode int, ipam *Kubernete
664664
}
665665

666666
case whereaboutstypes.Deallocate:
667-
updatedreservelist, ipforoverlappingrangeupdate = allocate.DeallocateIP(reservelist, ipam.containerID, ipam.IfName)
667+
updatedreservelist, ipforoverlappingrangeupdate = allocate.DeallocateIP(reservelist, ipam.ContainerID, ipam.IfName)
668668
if ipforoverlappingrangeupdate == nil {
669669
// Do not fail if allocation was not found.
670-
logging.Debugf("Failed to find allocation for container ID: %s", ipam.containerID)
670+
logging.Debugf("Failed to find allocation for container ID: %s", ipam.ContainerID)
671671
return nil, nil
672672
}
673673
}

0 commit comments

Comments
 (0)