From a354f80879c1d727cc22fb5d5973bea04d95745e Mon Sep 17 00:00:00 2001 From: dbxbbm Date: Mon, 3 Jan 2022 06:35:37 +0100 Subject: [PATCH 1/3] [Infoblox] Granular level of logging --- provider/infoblox/infoblox.go | 101 ++++++++++++++++++++-------------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/provider/infoblox/infoblox.go b/provider/infoblox/infoblox.go index f38f7a67f..1e6720eb3 100644 --- a/provider/infoblox/infoblox.go +++ b/provider/infoblox/infoblox.go @@ -216,6 +216,8 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E } for _, res := range resH { for _, ip := range res.Ipv4Addrs { + logrus.Debugf("Record='%s' A(H):'%s'", res.Name, ip.Ipv4Addr) + // host record is an abstraction in infoblox that combines A and PTR records // for any host record we already should have a PTR record in infoblox, so mark it as created newEndpoint := endpoint.NewEndpoint(res.Name, endpoint.RecordTypeA, ip.Ipv4Addr) @@ -238,6 +240,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E return nil, fmt.Errorf("could not fetch CNAME records from zone '%s': %s", zone.Fqdn, err) } for _, res := range resC { + logrus.Debugf("Record='%s' CNAME:'%s'", res.Name, res.Canonical) endpoints = append(endpoints, endpoint.NewEndpoint(res.Name, endpoint.RecordTypeCNAME, res.Canonical)) } @@ -281,6 +284,8 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E if _, err := strconv.Unquote(res.Text); err != nil { res.Text = strconv.Quote(res.Text) } + + logrus.Debugf("Record='%s' TXT:'%s'", res.Name, res.Text) endpoints = append(endpoints, endpoint.NewEndpoint(res.Name, endpoint.RecordTypeTXT, res.Text)) } } @@ -611,50 +616,66 @@ func (p *InfobloxProvider) deleteRecords(deleted infobloxChangeMap) { // Delete records first for zone, endpoints := range deleted { for _, ep := range endpoints { - if p.dryRun { - logrus.Infof("Would delete %s record named '%s' for Infoblox DNS zone '%s'.", ep.RecordType, ep.DNSName, zone) - } else { - logrus.Infof("Deleting %s record named '%s' for Infoblox DNS zone '%s'.", ep.RecordType, ep.DNSName, zone) - for targetIndex := range ep.Targets { - recordSet, err := p.recordSet(ep, true, targetIndex) - if err != nil { - logrus.Errorf( - "Failed to retrieve %s record named '%s' to '%s' for DNS zone '%s': %v", - ep.RecordType, - ep.DNSName, - ep.Targets[targetIndex], - zone, - err, - ) - continue - } - switch ep.RecordType { - case endpoint.RecordTypeA: - for _, record := range *recordSet.res.(*[]ibclient.RecordA) { - _, err = p.client.DeleteObject(record.Ref) - } - case endpoint.RecordTypePTR: - for _, record := range *recordSet.res.(*[]ibclient.RecordPTR) { - _, err = p.client.DeleteObject(record.Ref) - } - case endpoint.RecordTypeCNAME: - for _, record := range *recordSet.res.(*[]ibclient.RecordCNAME) { - _, err = p.client.DeleteObject(record.Ref) - } - case endpoint.RecordTypeTXT: - for _, record := range *recordSet.res.(*[]ibclient.RecordTXT) { + for targetIndex := range ep.Targets { + recordSet, err := p.recordSet(ep, true, targetIndex) + if err != nil { + logrus.Errorf( + "Failed to retrieve %s record named '%s' to '%s' for DNS zone '%s': %v", + ep.RecordType, + ep.DNSName, + ep.Targets[targetIndex], + zone, + err, + ) + continue + } + switch ep.RecordType { + case endpoint.RecordTypeA: + for _, record := range *recordSet.res.(*[]ibclient.RecordA) { + if p.dryRun { + logrus.Infof("Would delete %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "A", record.Name, record.Ipv4Addr, record.Zone) + } else { + logrus.Debugf("Deleting %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "A", record.Name, record.Ipv4Addr, record.Zone) _, err = p.client.DeleteObject(record.Ref) } } - if err != nil { - logrus.Errorf( - "Failed to delete %s record named '%s' for Infoblox DNS zone '%s': %v", - ep.RecordType, - ep.DNSName, - zone, - err, - ) + case endpoint.RecordTypePTR: + for _, record := range *recordSet.res.(*[]ibclient.RecordPTR) { + if p.dryRun { + logrus.Infof("Would delete %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "PTR", record.PtrdName, record.Ipv4Addr, record.Zone) + } else { + logrus.Debugf("Deleting %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "PTR", record.PtrdName, record.Ipv4Addr, record.Zone) + _, err = p.client.DeleteObject(record.Ref) + } } + case endpoint.RecordTypeCNAME: + for _, record := range *recordSet.res.(*[]ibclient.RecordCNAME) { + if p.dryRun { + logrus.Infof("Would delete %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "CNAME", record.Name, record.Canonical, record.Zone) + } else { + logrus.Debugf("Deleting %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "CNAME", record.Name, record.Canonical, record.Zone) + _, err = p.client.DeleteObject(record.Ref) + } + } + case endpoint.RecordTypeTXT: + for _, record := range *recordSet.res.(*[]ibclient.RecordTXT) { + if p.dryRun { + logrus.Infof("Would delete %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "TXT", record.Name, record.Text, record.Zone) + } else { + logrus.Debugf("Deleting %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "TXT", record.Name, record.Text, record.Zone) + _, err = p.client.DeleteObject(record.Ref) + } + } + } + if err != nil { + logrus.Errorf( + "Failed to delete %s record named '%s' to '%s' for Infoblox DNS zone '%s': %v", + ep.RecordType, + ep.DNSName, + ep.Targets[targetIndex], + zone, + err, + ) } } } From 28c17118733d97713ae4b0b4f98e4062cfa2c205 Mon Sep 17 00:00:00 2001 From: dbxbbm Date: Wed, 5 Jan 2022 10:25:37 +0100 Subject: [PATCH 2/3] squash: gofmt infoblox.go --- provider/infoblox/infoblox.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/provider/infoblox/infoblox.go b/provider/infoblox/infoblox.go index 1e6720eb3..70fa35779 100644 --- a/provider/infoblox/infoblox.go +++ b/provider/infoblox/infoblox.go @@ -663,7 +663,7 @@ func (p *InfobloxProvider) deleteRecords(deleted infobloxChangeMap) { logrus.Infof("Would delete %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "TXT", record.Name, record.Text, record.Zone) } else { logrus.Debugf("Deleting %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", "TXT", record.Name, record.Text, record.Zone) - _, err = p.client.DeleteObject(record.Ref) + _, err = p.client.DeleteObject(record.Ref) } } } From ffa1263b437d945537ec288c4bc8767d35c6871d Mon Sep 17 00:00:00 2001 From: dbxbbm Date: Wed, 5 Jan 2022 12:12:17 +0100 Subject: [PATCH 3/3] squash: log create per target --- provider/infoblox/infoblox.go | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/provider/infoblox/infoblox.go b/provider/infoblox/infoblox.go index 70fa35779..fa391e9a9 100644 --- a/provider/infoblox/infoblox.go +++ b/provider/infoblox/infoblox.go @@ -564,26 +564,27 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ func (p *InfobloxProvider) createRecords(created infobloxChangeMap) { for zone, endpoints := range created { for _, ep := range endpoints { - if p.dryRun { + for targetIndex := range ep.Targets { + if p.dryRun { + logrus.Infof( + + "Would create %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", + ep.RecordType, + ep.DNSName, + ep.Targets[targetIndex], + zone, + ) + continue + } + logrus.Infof( - "Would create %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", + "Creating %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", ep.RecordType, ep.DNSName, - ep.Targets, + ep.Targets[targetIndex], zone, ) - continue - } - logrus.Infof( - "Creating %s record named '%s' to '%s' for Infoblox DNS zone '%s'.", - ep.RecordType, - ep.DNSName, - ep.Targets, - zone, - ) - - for targetIndex := range ep.Targets { recordSet, err := p.recordSet(ep, false, targetIndex) if err != nil { logrus.Errorf(