@@ -61,7 +61,6 @@ type TaskReconciler struct {
6161 MaxConcurrentReconciles int
6262}
6363
64- // var clientsForContainers map[string]*OccClient = make(map[string]*OccClient)
6564var clientsForContainers sync.Map
6665
6766const taskFinalizer string = "aliecs.alice.cern/finalizer"
@@ -139,7 +138,6 @@ func (r *TaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
139138 return ctrl.Result {}, nil
140139 }
141140
142- // if _, exists := clientsForContainers[t.Name]; !exists {
143141 if _ , exists := clientsForContainers .Load (t .Name ); ! exists {
144142 if existingPod .Status .PodIP == "" {
145143 log .Info ("pod doesn't have IP yet, we wait for different event" )
@@ -163,7 +161,6 @@ func (r *TaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
163161 // on them being implemented
164162 if t .Status .State == "" {
165163 log .V (1 ).Info ("Status.State is empty, querying container" )
166- // client, exists := clientsForContainers[t.Name]
167164 client , exists := clientsForContainers .Load (t .Name )
168165 if ! exists {
169166 return ctrl.Result {Requeue : true }, nil
@@ -193,17 +190,17 @@ func (r *TaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
193190
194191 // Handle Spec -> gRPC State Sync
195192 if t .Status .State != t .Spec .State {
196- // client, exists := clientsForContainers[t.Name]
197- client , exists := clientsForContainers .Load (t .Name )
193+ clientAny , exists := clientsForContainers .Load (t .Name )
198194 if ! exists {
199195 return ctrl.Result {Requeue : true }, nil
200196 }
201197
202- stateReply , err := client .(* OccClient ).GetState (ctx )
198+ client := clientAny .(* OccClient )
199+
200+ stateReply , err := client .GetState (ctx )
203201 if err != nil {
204202 log .Info ("Failed to get state for sync, retrying in 5s" , "error" , err .Error ())
205- client .(* OccClient ).Close ()
206- // delete(clientsForContainers, t.Name)
203+ client .Close ()
207204 clientsForContainers .Delete (t .Name )
208205 return ctrl.Result {RequeueAfter : 5 * time .Second }, nil
209206 }
@@ -215,9 +212,9 @@ func (r *TaskReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.
215212 )
216213
217214 if t .Spec .Control .Mode == "fairmq" {
218- newState , transErr = client .( * OccClient ). FairMQTransitionRequest (ctx , stateReply .GetState (), t .Spec .State , t .Spec .Arguments )
215+ newState , transErr = client .FairMQTransitionRequest (ctx , stateReply .GetState (), t .Spec .State , t .Spec .Arguments )
219216 } else {
220- reply , err := client .( * OccClient ). TransitionRequest (ctx , stateReply .GetState (), t .Spec .State , t .Spec .Arguments )
217+ reply , err := client .TransitionRequest (ctx , stateReply .GetState (), t .Spec .State , t .Spec .Arguments )
221218 transErr = err
222219 if err == nil && reply .GetOk () {
223220 newState = strings .ToLower (reply .GetState ())
@@ -275,7 +272,6 @@ func (r *TaskReconciler) createGRPCConsumer(ctx context.Context, t *aliecsv1alph
275272 return ctrl.Result {RequeueAfter : 5 * time .Second }, nil
276273 }
277274
278- // clientsForContainers[t.Name] = client
279275 clientsForContainers .Store (t .Name , client )
280276
281277 if err := r .recordCondition (ctx , t , aliecsv1alpha1 .ConditionGRPCConnected , metav1 .ConditionTrue , "Connected" , fmt .Sprintf ("gRPC connection established to %s" , addr )); err != nil {
@@ -285,7 +281,6 @@ func (r *TaskReconciler) createGRPCConsumer(ctx context.Context, t *aliecsv1alph
285281}
286282
287283func (r * TaskReconciler ) consumeGRPCConsumerIfReady (ctx context.Context , t * aliecsv1alpha1.Task , log logr.Logger ) ctrl.Result {
288- // client, exists := clientsForContainers[t.Name]
289284 client , exists := clientsForContainers .Load (t .Name )
290285
291286 if ! exists {
@@ -351,13 +346,11 @@ func (r *TaskReconciler) deletePod(ctx context.Context, t *aliecsv1alpha1.Task,
351346}
352347
353348func (* TaskReconciler ) cleargRPC (t * aliecsv1alpha1.Task , log logr.Logger ) {
354- // if client, exists := clientsForContainers[t.Name]; exists {
355349 if client , exists := clientsForContainers .Load (t .Name ); exists {
356350 log .Info ("Cleaning up gRPC connection" )
357351 if err := client .(* OccClient ).Close (); err != nil {
358352 log .Error (err , "Failed to close gRPC client during deletion" )
359353 }
360- // delete(clientsForContainers, t.Name)
361354 clientsForContainers .Delete (t .Name )
362355 log .Info ("gRPC cleaned" )
363356 }
0 commit comments