@@ -121,12 +121,18 @@ func NewCurrentTargetGroup(o *NewCurrentTargetGroupOptions) (*TargetGroup, error
121
121
return nil , fmt .Errorf ("The Target Group %s does not have the proper tags, can't import: %s" , * o .TargetGroup .TargetGroupArn , err .Error ())
122
122
}
123
123
124
+ attrs , err := albelbv2 .ELBV2svc .DescribeTargetGroupAttributesFiltered (o .TargetGroup .TargetGroupArn )
125
+ if err != nil {
126
+ return nil , fmt .Errorf ("Failed to retrieve attributes for Target Group. Error: %s" , err .Error ())
127
+ }
128
+
124
129
return & TargetGroup {
125
- ID : id ,
126
- SvcName : svcName ,
127
- logger : o .Logger ,
128
- tags : tags {current : tgTags },
129
- tg : tg {current : o .TargetGroup },
130
+ ID : id ,
131
+ SvcName : svcName ,
132
+ logger : o .Logger ,
133
+ attributes : attributes {current : attrs },
134
+ tags : tags {current : tgTags },
135
+ tg : tg {current : o .TargetGroup },
130
136
}, nil
131
137
}
132
138
@@ -234,7 +240,8 @@ func (t *TargetGroup) create(rOpts *ReconcileOptions) error {
234
240
func (t * TargetGroup ) modify (mods tgChange , rOpts * ReconcileOptions ) error {
235
241
desired := t .tg .desired
236
242
if mods & paramsModified != 0 {
237
- in := & elbv2.ModifyTargetGroupInput {
243
+ t .logger .Infof ("Modifying target group parameters." )
244
+ o , err := albelbv2 .ELBV2svc .ModifyTargetGroup (& elbv2.ModifyTargetGroupInput {
238
245
HealthCheckIntervalSeconds : desired .HealthCheckIntervalSeconds ,
239
246
HealthCheckPath : desired .HealthCheckPath ,
240
247
HealthCheckPort : desired .HealthCheckPort ,
@@ -244,13 +251,11 @@ func (t *TargetGroup) modify(mods tgChange, rOpts *ReconcileOptions) error {
244
251
Matcher : desired .Matcher ,
245
252
TargetGroupArn : t .CurrentARN (),
246
253
UnhealthyThresholdCount : desired .UnhealthyThresholdCount ,
247
- }
248
- o , err := albelbv2 .ELBV2svc .ModifyTargetGroup (in )
254
+ })
249
255
if err != nil {
250
256
rOpts .Eventf (api .EventTypeWarning , "ERROR" , "Error modifying target group %s: %s" , t .ID , err .Error ())
251
- t . logger . Errorf ("Failed TargetGroup modification. ARN: %s | Error: %s. " ,
257
+ return fmt . Errorf ("Failed TargetGroup modification. ARN: %s | Error: %s" ,
252
258
* t .CurrentARN (), err .Error ())
253
- return err
254
259
}
255
260
t .tg .current = o .TargetGroups [0 ]
256
261
// AmazonAPI doesn't return an empty HealthCheckPath.
@@ -259,46 +264,45 @@ func (t *TargetGroup) modify(mods tgChange, rOpts *ReconcileOptions) error {
259
264
260
265
// check/change tags
261
266
if mods & tagsModified != 0 {
267
+ t .logger .Infof ("Modifying target group tags." )
262
268
if err := albelbv2 .ELBV2svc .UpdateTags (t .CurrentARN (), t .tags .current , t .tags .desired ); err != nil {
263
269
rOpts .Eventf (api .EventTypeWarning , "ERROR" , "Error changing tags on target group %s: %s" , t .ID , err .Error ())
264
- t . logger . Errorf ("Failed TargetGroup modification. Unable to modify tags. ARN: %s | Error: %s. " ,
270
+ return fmt . Errorf ("Failed TargetGroup modification. Unable to modify tags. ARN: %s | Error: %s" ,
265
271
* t .CurrentARN (), err .Error ())
266
- return err
267
272
}
268
273
t .tags .current = t .tags .desired
269
274
}
270
275
271
276
if mods & targetsModified != 0 {
277
+ t .logger .Infof ("Modifying target group targets." )
272
278
additions := util .Difference (t .targets .desired , t .targets .current )
273
279
removals := util .Difference (t .targets .current , t .targets .desired )
274
280
275
281
// check/change targets
276
282
if len (additions ) > 0 {
277
283
if err := t .registerTargets (additions , rOpts ); err != nil {
278
284
rOpts .Eventf (api .EventTypeWarning , "ERROR" , "Error adding targets to target group %s: %s" , t .ID , err .Error ())
279
- t .logger .Infof ("Failed TargetGroup modification. Unable to add targets: %s." , err .Error ())
280
- return err
285
+ return fmt .Errorf ("Failed TargetGroup modification. Unable to add targets: %s" , err .Error ())
281
286
}
282
287
}
283
288
if len (removals ) > 0 {
284
289
if err := t .deregisterTargets (removals , rOpts ); err != nil {
285
290
rOpts .Eventf (api .EventTypeWarning , "ERROR" , "Error removing targets from target group %s: %s" , t .ID , err .Error ())
286
- t .logger .Infof ("Failed TargetGroup modification. Unable to remove targets: %s." , err .Error ())
287
- return err
291
+ return fmt .Errorf ("Failed TargetGroup modification. Unable to remove targets: %s" , err .Error ())
288
292
}
289
293
}
290
294
t .targets .current = t .targets .desired
291
295
}
292
296
293
297
if mods & attributesModified != 0 {
298
+ t .logger .Infof ("Modifying target group attributes." )
294
299
aOpts := & elbv2.ModifyTargetGroupAttributesInput {
295
300
Attributes : t .attributes .desired ,
296
301
TargetGroupArn : t .CurrentARN (),
297
302
}
298
303
if _ , err := albelbv2 .ELBV2svc .ModifyTargetGroupAttributes (aOpts ); err != nil {
299
304
rOpts .Eventf (api .EventTypeWarning , "ERROR" , "Error modifying attributes in target group %s: %s" , t .ID , err .Error ())
300
- t .logger .Infof ("Failed TargetGroup modification. Unable to change attributes: %s." , err .Error ())
301
- return err
305
+ return fmt .Errorf ("Failed TargetGroup modification. Unable to change attributes: %s" , err .Error ())
302
306
}
303
307
t .attributes .current = t .attributes .desired
304
308
}
@@ -367,15 +371,12 @@ func (t *TargetGroup) needsModification() tgChange {
367
371
changes |= tagsModified
368
372
}
369
373
370
- if ! reflect .DeepEqual (t .attributes .current .Sorted (), t .attributes .desired .Sorted ()) {
374
+ if ! reflect .DeepEqual (t .attributes .current .Filtered (). Sorted (), t .attributes .desired . Filtered () .Sorted ()) {
371
375
t .logger .Debugf ("Attributes need to be changed" )
372
376
changes |= attributesModified
373
377
}
374
378
375
379
return changes
376
- // These fields require a rebuild and are enforced via TG name hash
377
- // Port *int64 `min:"1" type:"integer"`
378
- // Protocol *string `type:"string" enum:"ProtocolEnum"`
379
380
}
380
381
381
382
// Registers Targets (ec2 instances) to TargetGroup, must be called when Current != Desired
0 commit comments