Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions internal/infoblox/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,46 +363,53 @@ func (p *Provider) submitChanges(changes []*infobloxChange) error {
return fmt.Errorf("could not fetch zones: %w", err)
}

var errs []error
changesByZone := p.ChangesByZone(zonePointerConverter(zones), changes)
for zone, changes := range changesByZone {
for _, change := range changes {
record, err := p.buildRecord(change)
if err != nil {
return fmt.Errorf("could not build record: %w", err)
errs = append(errs, fmt.Errorf("could not build record (%s): %w", change, err))
continue
}

refId, logFields, err := getRefID(record)
if err != nil {
return err
if change.Action != infobloxCreate && err != nil {
errs = append(errs, err)
continue
}

logFields["action"] = change.Action
logFields["zone"] = zone
if p.config.DryRun {
log.WithFields(logFields).Info("Dry run: skipping..")
continue
}

log.WithFields(logFields).Info("Changing record")
var actionErr error

switch change.Action {
case infobloxCreate:
_, err = p.client.CreateObject(record.obj)
if err != nil {
return err
}
_, actionErr = p.client.CreateObject(record.obj)
case infobloxDelete:
_, err = p.client.DeleteObject(refId)
if err != nil {
return err
}
_, actionErr = p.client.DeleteObject(refId)
case infobloxUpdate:
_, err = p.client.UpdateObject(record.obj, refId)
if err != nil {
return err
}
_, actionErr = p.client.UpdateObject(record.obj, refId)
default:
return fmt.Errorf("unknown action '%s'", change.Action)
actionErr = fmt.Errorf("unknown action '%s'", change.Action)
}

if actionErr != nil {
errs = append(errs, actionErr)
}
}
}

if len(errs) > 0 {
return fmt.Errorf("encountered errors: %v", errs)
}

return nil
}

Expand Down
6 changes: 5 additions & 1 deletion internal/infoblox/infoblox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,13 @@ func (client *mockIBConnector) GetObject(obj ibclient.IBObject, ref string, quer
}

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

if len(result) < 3 {
return "", fmt.Errorf("invalid reference format: %s", ref)
}

switch result[1] {
case "record:a":
var records []ibclient.RecordA
Expand Down
Loading