@@ -1745,6 +1745,60 @@ func TestZoneReconcilerUpsertsRoute53AliasRecordSet(t *testing.T) {
17451745 }
17461746}
17471747
1748+ func TestZoneReconcilerAdoptsMatchingRoute53AliasRecordSet (t * testing.T ) {
1749+ ctx := context .Background ()
1750+ scheme := testScheme (t )
1751+ provider := newFakeProvider ()
1752+ provider .zones ["Z000001" ] = HostedZone {
1753+ ID : "Z000001" ,
1754+ Name : "apps.example.com" ,
1755+ CallerReference : "dns-api:11111111-2222-3333-4444-555555555555" ,
1756+ NameServers : []string {"ns-1.awsdns.example" , "ns-2.awsdns.example" },
1757+ }
1758+ provider .records [recordKey ("Z000001" , "alias.apps.example.com." , dnsv1alpha1 .RecordTypeA )] = RecordSetResource {
1759+ HostedZoneID : "Z000001" ,
1760+ Name : "alias.apps.example.com." ,
1761+ Type : dnsv1alpha1 .RecordTypeA ,
1762+ Alias : & route53v1alpha1.Route53AliasTarget {
1763+ DNSName : "target.apps.example.com" ,
1764+ HostedZoneID : "/hostedzone/Z000001" ,
1765+ EvaluateTargetHealth : false ,
1766+ },
1767+ }
1768+ recordSet := route53AliasARecordSet ("app" , "alias" )
1769+ recordSet .Spec .Adoption = runtime.RawExtension {Raw : []byte (`{"enabled":true}` )}
1770+ objects := route53RecordSetObjects (t , recordSet )
1771+ k8sClient := fake .NewClientBuilder ().
1772+ WithScheme (scheme ).
1773+ WithObjects (objects ... ).
1774+ WithStatusSubresource (& dnsv1alpha1.Zone {}, & dnsv1alpha1.RecordSet {}, & dnsv1alpha1.ZoneClass {}, & route53v1alpha1.Route53Identity {}, & dnsv1alpha1.ZoneUnit {}).
1775+ Build ()
1776+ reconciler := & ZoneReconciler {Client : k8sClient , Provider : provider }
1777+
1778+ result , err := reconcileRoute53AndProject (t , ctx , k8sClient , reconciler , ctrl.Request {NamespacedName : types.NamespacedName {Namespace : "app" , Name : "apps-example-com" }})
1779+ if err != nil {
1780+ t .Fatalf ("Reconcile returned error: %v" , err )
1781+ }
1782+ if result .Requeue {
1783+ t .Fatalf ("Reconcile result = %#v, want no immediate requeue" , result )
1784+ }
1785+ if len (provider .upserted ) != 0 {
1786+ t .Fatalf ("upserted record sets = %d, want 0" , len (provider .upserted ))
1787+ }
1788+
1789+ var unit dnsv1alpha1.ZoneUnit
1790+ if err := k8sClient .Get (ctx , client.ObjectKey {Namespace : "app" , Name : "apps-example-com" }, & unit ); err != nil {
1791+ t .Fatalf ("ZoneUnit was not found: %v" , err )
1792+ }
1793+ index := slices .IndexFunc (unit .Status .RecordSets , func (status dnsv1alpha1.ZoneUnitRecordSetStatus ) bool {
1794+ return status .RecordSetNamespace == recordSet .Namespace && status .RecordSetName == recordSet .Name
1795+ })
1796+ if index < 0 {
1797+ t .Fatalf ("ZoneUnit status.recordSets has no entry for %s/%s: %#v" , recordSet .Namespace , recordSet .Name , unit .Status .RecordSets )
1798+ }
1799+ assertCondition (t , unit .Status .RecordSets [index ].Conditions , string (dnsv1alpha1 .ConditionProgrammed ), metav1 .ConditionTrue , "Programmed" )
1800+ }
1801+
17481802func TestZoneReconcilerRejectsRecordSetWhenCNAMEZoneUnitItemOwnsSameName (t * testing.T ) {
17491803 ctx := context .Background ()
17501804 scheme := testScheme (t )
0 commit comments