@@ -19,13 +19,11 @@ import (
1919
2020 "github.com/aws/amazon-vpc-resource-controller-k8s/apis/vpcresources/v1alpha1"
2121 ec2API "github.com/aws/amazon-vpc-resource-controller-k8s/pkg/aws/ec2/api"
22- "github.com/aws/amazon-vpc-resource-controller-k8s/pkg/aws/ec2/api/cleanup"
2322 "github.com/aws/amazon-vpc-resource-controller-k8s/pkg/config"
2423 "github.com/aws/amazon-vpc-resource-controller-k8s/pkg/k8s"
2524 "github.com/aws/amazon-vpc-resource-controller-k8s/pkg/utils"
2625 "github.com/go-logr/logr"
2726 "github.com/prometheus/client_golang/prometheus"
28- "golang.org/x/sync/semaphore"
2927 v1 "k8s.io/api/core/v1"
3028 apierrors "k8s.io/apimachinery/pkg/api/errors"
3129 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -37,6 +35,7 @@ import (
3735 "sigs.k8s.io/controller-runtime/pkg/client"
3836 "sigs.k8s.io/controller-runtime/pkg/controller"
3937 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
38+ "sigs.k8s.io/controller-runtime/pkg/event"
4039 "sigs.k8s.io/controller-runtime/pkg/metrics"
4140)
4241
@@ -69,16 +68,15 @@ func prometheusRegister() {
6968// CNINodeReconciler reconciles a CNINode object
7069type CNINodeReconciler struct {
7170 client.Client
72- scheme * runtime.Scheme
73- context context.Context
74- log logr.Logger
75- eC2Wrapper ec2API.EC2Wrapper
76- k8sAPI k8s.K8sWrapper
77- clusterName string
78- vpcId string
79- finalizerManager k8s.FinalizerManager
80- deletePool * semaphore.Weighted
81- newResourceCleaner func (nodeID string , eC2Wrapper ec2API.EC2Wrapper , vpcID string , log logr.Logger ) cleanup.ResourceCleaner
71+ scheme * runtime.Scheme
72+ context context.Context
73+ log logr.Logger
74+ eC2Wrapper ec2API.EC2Wrapper
75+ k8sAPI k8s.K8sWrapper
76+ clusterName string
77+ vpcId string
78+ finalizerManager k8s.FinalizerManager
79+ nodeCleanupQueue * ENICleanup
8280}
8381
8482func NewCNINodeReconciler (
@@ -92,20 +90,19 @@ func NewCNINodeReconciler(
9290 vpcId string ,
9391 finalizerManager k8s.FinalizerManager ,
9492 maxConcurrentWorkers int ,
95- newResourceCleaner func ( nodeID string , eC2Wrapper ec2API. EC2Wrapper , vpcID string , log logr. Logger ) cleanup. ResourceCleaner ,
93+ nodeCleanupQueue * ENICleanup ,
9694) * CNINodeReconciler {
9795 return & CNINodeReconciler {
98- Client : client ,
99- scheme : scheme ,
100- context : ctx ,
101- log : logger ,
102- eC2Wrapper : ec2Wrapper ,
103- k8sAPI : k8sWrapper ,
104- clusterName : clusterName ,
105- vpcId : vpcId ,
106- finalizerManager : finalizerManager ,
107- deletePool : semaphore .NewWeighted (int64 (maxConcurrentWorkers )),
108- newResourceCleaner : newResourceCleaner ,
96+ Client : client ,
97+ scheme : scheme ,
98+ context : ctx ,
99+ log : logger ,
100+ eC2Wrapper : ec2Wrapper ,
101+ k8sAPI : k8sWrapper ,
102+ clusterName : clusterName ,
103+ vpcId : vpcId ,
104+ finalizerManager : finalizerManager ,
105+ nodeCleanupQueue : nodeCleanupQueue ,
109106 }
110107}
111108
@@ -156,19 +153,16 @@ func (r *CNINodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
156153 r .log .Info ("running the finalizer routine on cniNode" , "cniNode" , cniNode .Name )
157154 // run cleanup when node id is present
158155 if nodeID , ok := cniNode .Spec .Tags [config .NetworkInterfaceNodeIDKey ]; ok && nodeID != "" {
159- if ! r .deletePool .TryAcquire (1 ) {
160- r .log .Info ("d, will requeue request" )
161- return ctrl.Result {RequeueAfter : 10 * time .Second }, nil
156+ obj := & NodeCleanupObject {
157+ ObjectMeta : metav1.ObjectMeta {
158+ Name : nodeID ,
159+ Namespace : "" ,
160+ },
161+ NodeID : nodeID ,
162+ }
163+ r .nodeCleanupQueue .Events <- event.GenericEvent {
164+ Object : obj ,
162165 }
163- go func (nodeID string ) {
164- defer r .deletePool .Release (1 )
165- childCtx , cancel := context .WithTimeout (ctx , config .NodeTerminationTimeout )
166- defer cancel ()
167- if err := r .newResourceCleaner (nodeID , r .eC2Wrapper , r .vpcId , r .log ).DeleteLeakedResources (childCtx ); err != nil {
168- r .log .Error (err , "failed to cleanup resources during node termination" )
169- ec2API .NodeTerminationENICleanupFailure .Inc ()
170- }
171- }(nodeID )
172166 }
173167 }
174168
0 commit comments