Skip to content

Commit 9f376ad

Browse files
BobVanBkuritka
authored andcommitted
fix: continue on buildRecord error
1 parent 9f29e5a commit 9f376ad

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

internal/infoblox/infoblox.go

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -363,46 +363,53 @@ func (p *Provider) submitChanges(changes []*infobloxChange) error {
363363
return fmt.Errorf("could not fetch zones: %w", err)
364364
}
365365

366+
var errs []error
366367
changesByZone := p.ChangesByZone(zonePointerConverter(zones), changes)
367368
for zone, changes := range changesByZone {
368369
for _, change := range changes {
369370
record, err := p.buildRecord(change)
370371
if err != nil {
371-
return fmt.Errorf("could not build record: %w", err)
372+
errs = append(errs, fmt.Errorf("could not build record (%s): %w", change, err))
373+
continue
372374
}
375+
373376
refId, logFields, err := getRefID(record)
374-
if err != nil {
375-
return err
377+
if change.Action != infobloxCreate && err != nil {
378+
errs = append(errs, err)
379+
continue
376380
}
381+
377382
logFields["action"] = change.Action
378383
logFields["zone"] = zone
379384
if p.config.DryRun {
380385
log.WithFields(logFields).Info("Dry run: skipping..")
381386
continue
382387
}
388+
383389
log.WithFields(logFields).Info("Changing record")
390+
var actionErr error
391+
384392
switch change.Action {
385393
case infobloxCreate:
386-
_, err = p.client.CreateObject(record.obj)
387-
if err != nil {
388-
return err
389-
}
394+
_, actionErr = p.client.CreateObject(record.obj)
390395
case infobloxDelete:
391-
_, err = p.client.DeleteObject(refId)
392-
if err != nil {
393-
return err
394-
}
396+
_, actionErr = p.client.DeleteObject(refId)
395397
case infobloxUpdate:
396-
_, err = p.client.UpdateObject(record.obj, refId)
397-
if err != nil {
398-
return err
399-
}
398+
_, actionErr = p.client.UpdateObject(record.obj, refId)
400399
default:
401-
return fmt.Errorf("unknown action '%s'", change.Action)
400+
actionErr = fmt.Errorf("unknown action '%s'", change.Action)
401+
}
402+
403+
if actionErr != nil {
404+
errs = append(errs, actionErr)
402405
}
403406
}
404407
}
405408

409+
if len(errs) > 0 {
410+
return fmt.Errorf("encountered errors: %v", errs)
411+
}
412+
406413
return nil
407414
}
408415

internal/infoblox/infoblox_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,13 @@ func (client *mockIBConnector) GetObject(obj ibclient.IBObject, ref string, quer
369369
}
370370

371371
func (client *mockIBConnector) DeleteObject(ref string) (refRes string, err error) {
372-
re := regexp.MustCompile(`([^/]+)/[^:]+:([^/]+)/default`)
372+
re := regexp.MustCompile(`^([^/]+)/[^:]+:([^/]+)/default$`)
373373
result := re.FindStringSubmatch(ref)
374374

375+
if len(result) < 3 {
376+
return "", fmt.Errorf("invalid reference format: %s", ref)
377+
}
378+
375379
switch result[1] {
376380
case "record:a":
377381
var records []ibclient.RecordA

0 commit comments

Comments
 (0)