Skip to content

Commit

Permalink
fixing 'not found' error problem when there is no records in an exist…
Browse files Browse the repository at this point in the history
…ing zone
  • Loading branch information
skudriavtsev committed Apr 14, 2022
1 parent 63b7a0e commit 35ee85b
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions provider/infoblox/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ const (
providerSpecificInfobloxPtrRecord = "infoblox-ptr-record-exists"
)

func isNotFoundError(err error) bool {
_, ok := err.(*ibclient.NotFoundError)
return ok
}

// InfobloxConfig clarifies the method signature
type InfobloxConfig struct {
DomainFilter endpoint.DomainFilter
Expand Down Expand Up @@ -175,7 +180,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
objA.View = p.view
objA.Zone = zone.Fqdn
err = p.client.GetObject(objA, "", ibclient.NewQueryParams(false, nil), &resA)
if err != nil {
if err != nil && !isNotFoundError(err) {
return nil, fmt.Errorf("could not fetch A records from zone '%s': %s", zone.Fqdn, err)
}
for _, res := range resA {
Expand Down Expand Up @@ -208,7 +213,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
objH.View = p.view
objH.Zone = zone.Fqdn
err = p.client.GetObject(objH, "", ibclient.NewQueryParams(false, nil), &resH)
if err != nil {
if err != nil && !isNotFoundError(err) {
return nil, fmt.Errorf("could not fetch host records from zone '%s': %s", zone.Fqdn, err)
}
for _, res := range resH {
Expand All @@ -230,7 +235,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
objC.View = p.view
objC.Zone = zone.Fqdn
err = p.client.GetObject(objC, "", ibclient.NewQueryParams(false, nil), &resC)
if err != nil {
if err != nil && !isNotFoundError(err) {
return nil, fmt.Errorf("could not fetch CNAME records from zone '%s': %s", zone.Fqdn, err)
}
for _, res := range resC {
Expand All @@ -249,7 +254,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
objP.Zone = arpaZone
objP.View = p.view
err = p.client.GetObject(objP, "", ibclient.NewQueryParams(false, nil), &resP)
if err != nil {
if err != nil && !isNotFoundError(err) {
return nil, fmt.Errorf("could not fetch PTR records from zone '%s': %s", zone.Fqdn, err)
}
for _, res := range resP {
Expand All @@ -266,7 +271,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
},
)
err = p.client.GetObject(objT, "", ibclient.NewQueryParams(false, nil), &resT)
if err != nil {
if err != nil && !isNotFoundError(err) {
return nil, fmt.Errorf("could not fetch TXT records from zone '%s': %s", zone.Fqdn, err)
}
for _, res := range resT {
Expand Down Expand Up @@ -366,8 +371,7 @@ func (p *InfobloxProvider) zones() ([]ibclient.ZoneAuth, error) {
},
)
err := p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)

if err != nil {
if err != nil && !isNotFoundError(err) {
return nil, err
}

Expand Down Expand Up @@ -480,7 +484,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
obj.View = p.view
if getObject {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil {
if err != nil && !isNotFoundError(err) {
return
}
}
Expand All @@ -496,7 +500,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
obj.View = p.view
if getObject {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil {
if err != nil && !isNotFoundError(err) {
return
}
}
Expand All @@ -512,7 +516,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
obj.View = p.view
if getObject {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil {
if err != nil && !isNotFoundError(err) {
return
}
}
Expand All @@ -536,7 +540,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
)
if getObject {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil {
if err != nil && !isNotFoundError(err) {
return
}
}
Expand Down

0 comments on commit 35ee85b

Please sign in to comment.