@@ -195,7 +195,7 @@ func planChangesByZoneName(zones []string, changes *plan.Changes) map[string]*pl
195
195
return output
196
196
}
197
197
198
- func (p OVHProvider ) computeSingleZoneChanges (_ context.Context , zoneName string , existingRecords []ovhRecord , changes * plan.Changes ) []ovhChange {
198
+ func (p OVHProvider ) computeSingleZoneChanges (_ context.Context , zoneName string , existingRecords []ovhRecord , changes * plan.Changes ) ( []ovhChange , error ) {
199
199
allChanges := []ovhChange {}
200
200
var computedChanges []ovhChange
201
201
@@ -204,14 +204,21 @@ func (p OVHProvider) computeSingleZoneChanges(_ context.Context, zoneName string
204
204
computedChanges , existingRecords = p .newOvhChangeCreateDelete (ovhDelete , changes .Delete , zoneName , existingRecords )
205
205
allChanges = append (allChanges , computedChanges ... )
206
206
207
- computedChanges = p .newOvhChangeUpdate (changes .UpdateOld , changes .UpdateNew , zoneName , existingRecords )
207
+ var err error
208
+ computedChanges , err = p .newOvhChangeUpdate (changes .UpdateOld , changes .UpdateNew , zoneName , existingRecords )
209
+ if err != nil {
210
+ return nil , err
211
+ }
208
212
allChanges = append (allChanges , computedChanges ... )
209
213
210
- return allChanges
214
+ return allChanges , nil
211
215
}
212
216
213
217
func (p * OVHProvider ) handleSingleZoneUpdate (ctx context.Context , zoneName string , existingRecords []ovhRecord , changes * plan.Changes ) error {
214
- allChanges := p .computeSingleZoneChanges (ctx , zoneName , existingRecords , changes )
218
+ allChanges , err := p .computeSingleZoneChanges (ctx , zoneName , existingRecords , changes )
219
+ if err != nil {
220
+ return err
221
+ }
215
222
log .Infof ("OVH: %q: %d changes will be done" , zoneName , len (allChanges ))
216
223
217
224
eg , ctxErrGroup := errgroup .WithContext (ctx )
@@ -222,7 +229,7 @@ func (p *OVHProvider) handleSingleZoneUpdate(ctx context.Context, zoneName strin
222
229
})
223
230
}
224
231
225
- err : = eg .Wait ()
232
+ err = eg .Wait ()
226
233
227
234
// do not refresh zone if errors: some records might haven't been processed yet, hence the zone will be in an inconsistent state
228
235
// if modification of the zone was in error, invalidating the cache to make sure next run will start freshly
@@ -554,7 +561,11 @@ func convertDNSNameIntoSubDomain(DNSName string, zoneName string) string {
554
561
return strings .TrimSuffix (DNSName , "." + zoneName )
555
562
}
556
563
557
- func (p OVHProvider ) newOvhChangeUpdate (endpointsOld []* endpoint.Endpoint , endpointsNew []* endpoint.Endpoint , zone string , existingRecords []ovhRecord ) []ovhChange {
564
+ func normalizeDNSName (dnsName string ) string {
565
+ return strings .TrimSpace (strings .ToLower (dnsName ))
566
+ }
567
+
568
+ func (p OVHProvider ) newOvhChangeUpdate (endpointsOld []* endpoint.Endpoint , endpointsNew []* endpoint.Endpoint , zone string , existingRecords []ovhRecord ) ([]ovhChange , error ) {
558
569
zoneNameIDMapper := provider.ZoneIDName {}
559
570
zoneNameIDMapper .Add (zone , zone )
560
571
@@ -564,16 +575,16 @@ func (p OVHProvider) newOvhChangeUpdate(endpointsOld []*endpoint.Endpoint, endpo
564
575
565
576
for _ , e := range endpointsOld {
566
577
sub := convertDNSNameIntoSubDomain (e .DNSName , zone )
567
- oldEndpointByTypeAndName [e .RecordType + "//" + sub ] = e
578
+ oldEndpointByTypeAndName [normalizeDNSName ( e .RecordType + "//" + sub ) ] = e
568
579
}
569
580
for _ , e := range endpointsNew {
570
581
sub := convertDNSNameIntoSubDomain (e .DNSName , zone )
571
- newEndpointByTypeAndName [e .RecordType + "//" + sub ] = e
582
+ newEndpointByTypeAndName [normalizeDNSName ( e .RecordType + "//" + sub ) ] = e
572
583
}
573
584
574
585
for id := range oldEndpointByTypeAndName {
575
586
for _ , record := range existingRecords {
576
- if id == record .FieldType + "//" + record .SubDomain {
587
+ if id == normalizeDNSName ( record .FieldType + "//" + record .SubDomain ) {
577
588
oldRecordsInZone [id ] = append (oldRecordsInZone [id ], record )
578
589
}
579
590
}
@@ -583,7 +594,10 @@ func (p OVHProvider) newOvhChangeUpdate(endpointsOld []*endpoint.Endpoint, endpo
583
594
584
595
for id := range oldEndpointByTypeAndName {
585
596
oldRecords := slices .Clone (oldRecordsInZone [id ])
586
- endpointsNew := newEndpointByTypeAndName [id ]
597
+ endpointsNew , ok := newEndpointByTypeAndName [id ]
598
+ if ! ok {
599
+ return nil , errors .New ("unrecoverable error: couldn't find the matching record in the update.New" )
600
+ }
587
601
588
602
var toInsertTarget []string
589
603
@@ -668,7 +682,7 @@ func (p OVHProvider) newOvhChangeUpdate(endpointsOld []*endpoint.Endpoint, endpo
668
682
}
669
683
}
670
684
671
- return changes
685
+ return changes , nil
672
686
}
673
687
674
688
func (c * ovhChange ) String () string {
0 commit comments