Skip to content

Commit 35ee85b

Browse files
committed
fixing 'not found' error problem when there is no records in an existing zone
1 parent 63b7a0e commit 35ee85b

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

provider/infoblox/infoblox.go

+15-11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ const (
4040
providerSpecificInfobloxPtrRecord = "infoblox-ptr-record-exists"
4141
)
4242

43+
func isNotFoundError(err error) bool {
44+
_, ok := err.(*ibclient.NotFoundError)
45+
return ok
46+
}
47+
4348
// InfobloxConfig clarifies the method signature
4449
type InfobloxConfig struct {
4550
DomainFilter endpoint.DomainFilter
@@ -175,7 +180,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
175180
objA.View = p.view
176181
objA.Zone = zone.Fqdn
177182
err = p.client.GetObject(objA, "", ibclient.NewQueryParams(false, nil), &resA)
178-
if err != nil {
183+
if err != nil && !isNotFoundError(err) {
179184
return nil, fmt.Errorf("could not fetch A records from zone '%s': %s", zone.Fqdn, err)
180185
}
181186
for _, res := range resA {
@@ -208,7 +213,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
208213
objH.View = p.view
209214
objH.Zone = zone.Fqdn
210215
err = p.client.GetObject(objH, "", ibclient.NewQueryParams(false, nil), &resH)
211-
if err != nil {
216+
if err != nil && !isNotFoundError(err) {
212217
return nil, fmt.Errorf("could not fetch host records from zone '%s': %s", zone.Fqdn, err)
213218
}
214219
for _, res := range resH {
@@ -230,7 +235,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
230235
objC.View = p.view
231236
objC.Zone = zone.Fqdn
232237
err = p.client.GetObject(objC, "", ibclient.NewQueryParams(false, nil), &resC)
233-
if err != nil {
238+
if err != nil && !isNotFoundError(err) {
234239
return nil, fmt.Errorf("could not fetch CNAME records from zone '%s': %s", zone.Fqdn, err)
235240
}
236241
for _, res := range resC {
@@ -249,7 +254,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
249254
objP.Zone = arpaZone
250255
objP.View = p.view
251256
err = p.client.GetObject(objP, "", ibclient.NewQueryParams(false, nil), &resP)
252-
if err != nil {
257+
if err != nil && !isNotFoundError(err) {
253258
return nil, fmt.Errorf("could not fetch PTR records from zone '%s': %s", zone.Fqdn, err)
254259
}
255260
for _, res := range resP {
@@ -266,7 +271,7 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
266271
},
267272
)
268273
err = p.client.GetObject(objT, "", ibclient.NewQueryParams(false, nil), &resT)
269-
if err != nil {
274+
if err != nil && !isNotFoundError(err) {
270275
return nil, fmt.Errorf("could not fetch TXT records from zone '%s': %s", zone.Fqdn, err)
271276
}
272277
for _, res := range resT {
@@ -366,8 +371,7 @@ func (p *InfobloxProvider) zones() ([]ibclient.ZoneAuth, error) {
366371
},
367372
)
368373
err := p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
369-
370-
if err != nil {
374+
if err != nil && !isNotFoundError(err) {
371375
return nil, err
372376
}
373377

@@ -480,7 +484,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
480484
obj.View = p.view
481485
if getObject {
482486
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
483-
if err != nil {
487+
if err != nil && !isNotFoundError(err) {
484488
return
485489
}
486490
}
@@ -496,7 +500,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
496500
obj.View = p.view
497501
if getObject {
498502
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
499-
if err != nil {
503+
if err != nil && !isNotFoundError(err) {
500504
return
501505
}
502506
}
@@ -512,7 +516,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
512516
obj.View = p.view
513517
if getObject {
514518
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
515-
if err != nil {
519+
if err != nil && !isNotFoundError(err) {
516520
return
517521
}
518522
}
@@ -536,7 +540,7 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
536540
)
537541
if getObject {
538542
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
539-
if err != nil {
543+
if err != nil && !isNotFoundError(err) {
540544
return
541545
}
542546
}

0 commit comments

Comments
 (0)