Skip to content

Commit e61ff25

Browse files
committed
cleaning up branch eni queue before deleting node. (#574)
1 parent a53b7e3 commit e61ff25

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

mocks/amazon-vcp-resource-controller-k8s/pkg/k8s/mock_k8swrapper.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/amazon-vcp-resource-controller-k8s/pkg/provider/branch/trunk/mock_trunk.go

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/provider/branch/provider.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,14 +244,12 @@ func (b *branchENIProvider) ProcessAsyncJob(job interface{}) (ctrl.Result, error
244244

245245
// DeleteNode deletes all the cached branch ENIs associated with the trunk and removes the trunk from the cache.
246246
func (b *branchENIProvider) DeleteNode(nodeName string) (ctrl.Result, error) {
247-
_, isPresent := b.getTrunkFromCache(nodeName)
247+
trunkENI, isPresent := b.getTrunkFromCache(nodeName)
248248
if !isPresent {
249249
return ctrl.Result{}, fmt.Errorf("failed to find node %s", nodeName)
250250
}
251251

252-
// At this point, the finalizer routine should have deleted all available branch ENIs
253-
// Any leaked ENIs will be deleted by the periodic cleanup routine if cluster is active
254-
// remove trunk from cache and de-initializer the resource provider
252+
trunkENI.DeleteAllBranchENIs()
255253
b.removeTrunkFromCache(nodeName)
256254

257255
b.log.Info("de-initialized resource provider successfully", "nodeName", nodeName)

pkg/provider/branch/trunk/trunk.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ type TrunkENI interface {
103103
Reconcile(pods []v1.Pod) bool
104104
// PushENIsToFrontOfDeleteQueue pushes the eni network interfaces to the front of the delete queue
105105
PushENIsToFrontOfDeleteQueue(*v1.Pod, []*ENIDetails)
106+
// DeleteAllBranchENIs deletes all the branch ENI associated with the trunk and also clears the cool down queue
107+
DeleteAllBranchENIs()
106108
// Introspect returns the state of the Trunk ENI
107109
Introspect() IntrospectResponse
108110
}
@@ -481,6 +483,31 @@ func (t *trunkENI) CreateAndAssociateBranchENIs(pod *v1.Pod, securityGroups []st
481483
return newENIs, nil
482484
}
483485

486+
// DeleteAllBranchENIs deletes all the branch ENIs associated with the trunk and all the ENIs present in the cool down
487+
// queue, this is the last API call to the the Trunk ENI before it is removed from cache
488+
func (t *trunkENI) DeleteAllBranchENIs() {
489+
// Delete all the branch used by the pod on this trunk ENI
490+
// Since after this call, the trunk will be removed from cache. No need to clean up its branch map
491+
for _, podENIs := range t.uidToBranchENIMap {
492+
for _, eni := range podENIs {
493+
err := t.deleteENI(eni)
494+
if err != nil {
495+
// Just log, if the ENI still exists it can be removed by the dangling ENI cleaner routine
496+
t.log.Error(err, "failed to delete eni", "eni id", eni.ID)
497+
}
498+
}
499+
}
500+
501+
// Delete all the branch ENI present in the cool down queue
502+
for _, eni := range t.deleteQueue {
503+
err := t.deleteENI(eni)
504+
if err != nil {
505+
// Just log, if the ENI still exists it can be removed by the dangling ENI cleaner routine
506+
t.log.Error(err, "failed to delete eni", "eni id", eni.ID)
507+
}
508+
}
509+
}
510+
484511
// DeleteBranchNetworkInterface deletes the branch network interface and returns an error in case of failure to delete
485512
func (t *trunkENI) PushBranchENIsToCoolDownQueue(UID string) {
486513
// Lock is required as Reconciler is also performing operation concurrently

0 commit comments

Comments
 (0)