@@ -140,6 +140,7 @@ func (a *AWSHubActuator) Reconcile(cd *hivev1.ClusterDeployment, metadata *hivev
140
140
if err != nil {
141
141
return reconcile.Result {}, errors .Wrap (err , "failed to update condition on cluster deployment" )
142
142
}
143
+ return reconcile.Result {Requeue : true }, nil
143
144
}
144
145
145
146
logger .Debug ("reconciling Hosted Zone Records" )
@@ -158,6 +159,7 @@ func (a *AWSHubActuator) Reconcile(cd *hivev1.ClusterDeployment, metadata *hivev
158
159
if err != nil {
159
160
return reconcile.Result {}, errors .Wrap (err , "failed to update condition on cluster deployment" )
160
161
}
162
+ return reconcile.Result {Requeue : true }, nil
161
163
}
162
164
163
165
logger .Debug ("reconciling Hosted Zone Associations" )
@@ -177,6 +179,7 @@ func (a *AWSHubActuator) Reconcile(cd *hivev1.ClusterDeployment, metadata *hivev
177
179
if err != nil {
178
180
return reconcile.Result {}, errors .Wrap (err , "failed to update condition on cluster deployment" )
179
181
}
182
+ return reconcile.Result {Requeue : true }, nil
180
183
}
181
184
182
185
return reconcile.Result {}, nil
@@ -374,11 +377,112 @@ func (a *AWSHubActuator) cleanupHostedZone(cd *hivev1.ClusterDeployment, metadat
374
377
}
375
378
376
379
func (a * AWSHubActuator ) ReconcileHostedZoneRecords (cd * hivev1.ClusterDeployment , hostedZoneID string , dnsRecord * actuator.DnsRecord , apiDomain string , logger log.FieldLogger ) (bool , error ) {
380
+ hzLog := logger .WithField ("hostedZoneID" , hostedZoneID )
381
+ modified := false
382
+
377
383
rSet , err := a .recordSet (cd , apiDomain , dnsRecord )
378
384
if err != nil {
379
385
return false , errors .Wrap (err , "error generating DNS records" )
380
386
}
381
387
388
+ recordsResp , err := a .awsClientHub .ListResourceRecordSets (& route53.ListResourceRecordSetsInput {
389
+ HostedZoneId : aws .String (hostedZoneID ),
390
+ })
391
+ if err != nil {
392
+ return false , errors .Wrapf (err , "failed to list the hosted zone %s" , hostedZoneID )
393
+ }
394
+
395
+ for _ , record := range recordsResp .ResourceRecordSets {
396
+ if * record .Name == * rSet .Name {
397
+ if rSet .ResourceRecords != nil {
398
+ if aws .StringValue (record .Type ) != aws .StringValue (rSet .Type ) {
399
+ modified = true
400
+ hzLog .WithFields (log.Fields {
401
+ "record" : aws .StringValue (rSet .Name ),
402
+ "type" : aws .StringValue (rSet .Type ),
403
+ }).Debug ("updating record type" )
404
+ }
405
+ if aws .Int64Value (record .TTL ) != aws .Int64Value (rSet .TTL ) {
406
+ modified = true
407
+ hzLog .WithFields (log.Fields {
408
+ "record" : aws .StringValue (rSet .Name ),
409
+ "ttl" : aws .Int64Value (rSet .TTL ),
410
+ }).Debug ("updating record ttl" )
411
+ }
412
+
413
+ oldRecords := sets .NewString ()
414
+ for _ , record := range record .ResourceRecords {
415
+ oldRecords .Insert (aws .StringValue (record .Value ))
416
+ }
417
+
418
+ desiredRecords := sets .NewString ()
419
+ for _ , record := range rSet .ResourceRecords {
420
+ desiredRecords .Insert (aws .StringValue (record .Value ))
421
+ }
422
+
423
+ added := desiredRecords .Difference (oldRecords ).List ()
424
+ removed := oldRecords .Difference (desiredRecords ).List ()
425
+
426
+ if len (added ) > 0 || len (removed ) > 0 {
427
+ modified = true
428
+ hzLog .WithFields (log.Fields {
429
+ "added" : added ,
430
+ "removed" : removed ,
431
+ }).Debug ("updating the addresses assigned to the dns record" )
432
+ }
433
+
434
+ if ! modified {
435
+ return false , nil
436
+ }
437
+ } else if rSet .AliasTarget != nil {
438
+ logger .Debugf ("AliasTarget" )
439
+ if record .AliasTarget == nil {
440
+ modified = true
441
+ hzLog .WithFields (log.Fields {
442
+ "record" : aws .StringValue (rSet .Name ),
443
+ }).Debug ("updating the record to use alias target" )
444
+ break
445
+ }
446
+
447
+ if aws .StringValue (record .Type ) != aws .StringValue (rSet .Type ) {
448
+ modified = true
449
+ hzLog .WithFields (log.Fields {
450
+ "record" : aws .StringValue (rSet .Name ),
451
+ "type" : aws .StringValue (rSet .Type ),
452
+ }).Debug ("updating record type" )
453
+ }
454
+
455
+ if aws .StringValue (record .AliasTarget .DNSName ) != aws .StringValue (rSet .AliasTarget .DNSName ) {
456
+ modified = true
457
+ hzLog .WithFields (log.Fields {
458
+ "record" : aws .StringValue (rSet .Name ),
459
+ "dnsName" : aws .StringValue (rSet .AliasTarget .DNSName ),
460
+ }).Debug ("updating the aliasTarget dnsName" )
461
+ }
462
+
463
+ if aws .StringValue (record .AliasTarget .HostedZoneId ) != aws .StringValue (rSet .AliasTarget .HostedZoneId ) {
464
+ modified = true
465
+ hzLog .WithFields (log.Fields {
466
+ "record" : aws .StringValue (rSet .Name ),
467
+ "hostedZoneId" : aws .StringValue (rSet .AliasTarget .HostedZoneId ),
468
+ }).Debug ("updating the aliasTarget hostedZoneId" )
469
+ }
470
+
471
+ if aws .BoolValue (record .AliasTarget .EvaluateTargetHealth ) != aws .BoolValue (rSet .AliasTarget .EvaluateTargetHealth ) {
472
+ modified = true
473
+ hzLog .WithFields (log.Fields {
474
+ "record" : aws .StringValue (rSet .Name ),
475
+ "evaluateTargetHealth" : aws .BoolValue (rSet .AliasTarget .EvaluateTargetHealth ),
476
+ }).Debug ("updating the aliasTarget evaluateTargetHealth" )
477
+ }
478
+
479
+ if ! modified {
480
+ return false , nil
481
+ }
482
+ }
483
+ break
484
+ }
485
+ }
382
486
_ , err = a .awsClientHub .ChangeResourceRecordSets (& route53.ChangeResourceRecordSetsInput {
383
487
HostedZoneId : aws .String (hostedZoneID ),
384
488
ChangeBatch : & route53.ChangeBatch {
0 commit comments