@@ -332,14 +332,15 @@ func (l *LoadBalancer) Reconcile(rOpts *ReconcileOptions) []error {
332
332
Eventf : rOpts .Eventf ,
333
333
VpcID : l .lb .current .VpcId ,
334
334
ManagedSGInstance : l .options .current .managedInstanceSG ,
335
+ IgnoreDeletes : true ,
335
336
}
336
337
337
- tgs , deletedTG , err := l .targetgroups .Reconcile (tgsOpts )
338
+ tgs , err := l .targetgroups .Reconcile (tgsOpts )
338
339
if err != nil {
339
340
errors = append (errors , err )
340
- return errors
341
+ } else {
342
+ l .targetgroups = tgs
341
343
}
342
- l .targetgroups = tgs
343
344
344
345
lsOpts := & ls.ReconcileOptions {
345
346
Eventf : rOpts .Eventf ,
@@ -352,33 +353,19 @@ func (l *LoadBalancer) Reconcile(rOpts *ReconcileOptions) []error {
352
353
l .listeners = ltnrs
353
354
}
354
355
355
- // REFACTOR!
356
- // This chunk of code has some questionable logic and we should probably move
357
- // the TG clean up out of here and into tg. I also dont think that lb.listeners < 1 is a valid check
358
- //
359
- // Return now if listeners are already deleted, signifies has already been destructed and
360
- // TG clean-up, based on rules below does not need to occur.
361
- if len (l .listeners ) < 1 {
362
- for _ , t := range deletedTG {
363
- if err := albelbv2 .ELBV2svc .RemoveTargetGroup (t .CurrentARN ()); err != nil {
364
- errors = append (errors , err )
365
- return errors
366
- }
367
- index , _ := l .targetgroups .FindById (t .ID )
368
- l .targetgroups = append (l .targetgroups [:index ], l .targetgroups [index + 1 :]... )
369
- }
370
- return errors
356
+ // Decide: Is this still needed?
357
+ for _ , listener := range l .listeners {
358
+ unusedTGs := listener .GetRules ().FindUnusedTGs (l .targetgroups )
359
+ unusedTGs .StripDesiredState ()
371
360
}
372
- unusedTGs := l .listeners [0 ].GetRules ().FindUnusedTGs (l .targetgroups )
373
- for _ , t := range unusedTGs {
374
- if err := albelbv2 .ELBV2svc .RemoveTargetGroup (t .CurrentARN ()); err != nil {
375
- errors = append (errors , err )
376
- return errors
377
- }
378
- index , _ := l .targetgroups .FindById (t .ID )
379
- l .targetgroups = append (l .targetgroups [:index ], l .targetgroups [index + 1 :]... )
361
+
362
+ tgsOpts .IgnoreDeletes = false
363
+ tgs , err = l .targetgroups .Reconcile (tgsOpts )
364
+ if err != nil {
365
+ errors = append (errors , err )
366
+ } else {
367
+ l .targetgroups = tgs
380
368
}
381
- // END REFACTOR
382
369
383
370
return errors
384
371
}
@@ -564,7 +551,7 @@ func (l *LoadBalancer) modify(rOpts *ReconcileOptions) error {
564
551
565
552
// Modify Tags
566
553
if needsMod & tagsModified != 0 {
567
- l .logger .Infof ("Modifying ELBV2 tags to %v." , log .Prettify (l .tags .current ))
554
+ l .logger .Infof ("Modifying ELBV2 tags to %v." , log .Prettify (l .tags .desired ))
568
555
if err := albelbv2 .ELBV2svc .UpdateTags (l .lb .current .LoadBalancerArn , l .tags .current , l .tags .desired ); err != nil {
569
556
rOpts .Eventf (api .EventTypeWarning , "ERROR" , "%s tag modification failed: %s" , * l .lb .current .LoadBalancerName , err .Error ())
570
557
return fmt .Errorf ("Failed ELBV2 tag modification: %s" , err .Error ())
0 commit comments