Skip to content

Commit

Permalink
Merge pull request #2670 from skudriavtsev/ib-client-v2
Browse files Browse the repository at this point in the history
migration to infoblox-go-client/v2
  • Loading branch information
k8s-ci-robot authored Apr 19, 2022
2 parents bb635fb + 35ee85b commit bcd6e7f
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 165 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
github.com/google/go-cmp v0.5.7
github.com/gophercloud/gophercloud v0.22.0
github.com/hooklift/gowsdl v0.5.0
github.com/infobloxopen/infoblox-go-client v1.1.1
github.com/infobloxopen/infoblox-go-client/v2 v2.1.1
github.com/linki/instrumented_http v0.3.0
github.com/linode/linodego v0.32.2
github.com/maxatome/go-testdeep v1.11.0
Expand Down
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU=
github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
github.com/infobloxopen/infoblox-go-client v1.1.1 h1:728A6LbLjptj/7kZjHyIxQnm768PWHfGFm0HH8FnbtU=
github.com/infobloxopen/infoblox-go-client v1.1.1/go.mod h1:BXiw7S2b9qJoM8MS40vfgCNB2NLHGusk1DtO16BD9zI=
github.com/infobloxopen/infoblox-go-client/v2 v2.1.1 h1:NYnXOngwW4xMIgUz4bKJ1Ygsmq5K0OOdUEkuLlkR1Ag=
github.com/infobloxopen/infoblox-go-client/v2 v2.1.1/go.mod h1:+lznx4ASBSUZ2i6qwlgyn0v3eKDxBHNU5aRJzghAFbw=
github.com/jcmturner/aescts/v2 v2.0.0 h1:9YKLH6ey7H4eDBXW8khjYslgyqG2xZikXP0EQFKrle8=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0 h1:lltnkeZGL0wILNvrNiVCR6Ro5PGU/SeBvVO/8c/iPbo=
Expand Down Expand Up @@ -841,6 +841,7 @@ github.com/linode/linodego v0.32.2/go.mod h1:BR0gVkCJffEdIGJSl6bHR80Ty+Uvg/2jkjm
github.com/lithammer/dedent v1.1.0/go.mod h1:jrXYCQtgg0nJiN+StA2KgR7w6CiQNv9Fd/Z9BP0jIOc=
github.com/lyft/protoc-gen-star v0.4.10/go.mod h1:mE8fbna26u7aEA2QCVvvfBU/ZrPgocG1206xAFPcs94=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
github.com/magefile/mage v1.10.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
Expand Down Expand Up @@ -964,6 +965,7 @@ github.com/onsi/ginkgo v1.11.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.14.1/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
Expand All @@ -976,6 +978,7 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.14.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+tEHG0=
github.com/onsi/gomega v1.17.0 h1:9Luw4uT5HTjHTN8+aNcSThgH1vdXnmdJ8xIfZ4wyTRE=
Expand Down Expand Up @@ -1125,6 +1128,7 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.8.0/go.mod h1:4GuYW9TZmE769R5STWrRakJc4UqQ3+QQ95fyz7ENv1A=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartystreets/assertions v0.0.0-20180725160413-e900ae048470/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
Expand Down
129 changes: 56 additions & 73 deletions provider/infoblox/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"strings"

transform "github.com/StackExchange/dnscontrol/pkg/transform"
ibclient "github.com/infobloxopen/infoblox-go-client"
ibclient "github.com/infobloxopen/infoblox-go-client/v2"
"github.com/sirupsen/logrus"

"sigs.k8s.io/external-dns/endpoint"
Expand All @@ -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 @@ -95,7 +100,7 @@ func NewExtendedRequestBuilder(maxResults int, fqdnRegEx string) *ExtendedReques

// BuildRequest prepares the api request. it uses BuildRequest of
// WapiRequestBuilder and then add the _max_requests parameter
func (mrb *ExtendedRequestBuilder) BuildRequest(t ibclient.RequestType, obj ibclient.IBObject, ref string, queryParams ibclient.QueryParams) (req *http.Request, err error) {
func (mrb *ExtendedRequestBuilder) BuildRequest(t ibclient.RequestType, obj ibclient.IBObject, ref string, queryParams *ibclient.QueryParams) (req *http.Request, err error) {
req, err = mrb.WapiRequestBuilder.BuildRequest(t, obj, ref, queryParams)
if req.Method == "GET" {
query := req.URL.Query()
Expand Down Expand Up @@ -147,7 +152,7 @@ func NewInfobloxProvider(infobloxConfig InfobloxConfig) (*InfobloxProvider, erro
return nil, err
}

provider := &InfobloxProvider{
providerCfg := &InfobloxProvider{
client: client,
domainFilter: infobloxConfig.DomainFilter,
zoneIDFilter: infobloxConfig.ZoneIDFilter,
Expand All @@ -158,7 +163,7 @@ func NewInfobloxProvider(infobloxConfig InfobloxConfig) (*InfobloxProvider, erro
cacheDuration: infobloxConfig.CacheDuration,
}

return provider, nil
return providerCfg, nil
}

// Records gets the current records.
Expand All @@ -171,14 +176,11 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
for _, zone := range zones {
logrus.Debugf("fetch records from zone '%s'", zone.Fqdn)
var resA []ibclient.RecordA
objA := ibclient.NewRecordA(
ibclient.RecordA{
Zone: zone.Fqdn,
View: p.view,
},
)
err = p.client.GetObject(objA, "", &resA)
if err != nil {
objA := ibclient.NewEmptyRecordA()
objA.View = p.view
objA.Zone = zone.Fqdn
err = p.client.GetObject(objA, "", ibclient.NewQueryParams(false, nil), &resA)
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 @@ -207,14 +209,11 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E

// Include Host records since they should be treated synonymously with A records
var resH []ibclient.HostRecord
objH := ibclient.NewHostRecord(
ibclient.HostRecord{
Zone: zone.Fqdn,
View: p.view,
},
)
err = p.client.GetObject(objH, "", &resH)
if err != nil {
objH := ibclient.NewEmptyHostRecord()
objH.View = p.view
objH.Zone = zone.Fqdn
err = p.client.GetObject(objH, "", ibclient.NewQueryParams(false, nil), &resH)
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 @@ -232,14 +231,11 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
}

var resC []ibclient.RecordCNAME
objC := ibclient.NewRecordCNAME(
ibclient.RecordCNAME{
Zone: zone.Fqdn,
View: p.view,
},
)
err = p.client.GetObject(objC, "", &resC)
if err != nil {
objC := ibclient.NewEmptyRecordCNAME()
objC.View = p.view
objC.Zone = zone.Fqdn
err = p.client.GetObject(objC, "", ibclient.NewQueryParams(false, nil), &resC)
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 @@ -254,14 +250,11 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
arpaZone, err := transform.ReverseDomainName(zone.Fqdn)
if err == nil {
var resP []ibclient.RecordPTR
objP := ibclient.NewRecordPTR(
ibclient.RecordPTR{
Zone: arpaZone,
View: p.view,
},
)
err = p.client.GetObject(objP, "", &resP)
if err != nil {
objP := ibclient.NewEmptyRecordPTR()
objP.Zone = arpaZone
objP.View = p.view
err = p.client.GetObject(objP, "", ibclient.NewQueryParams(false, nil), &resP)
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 @@ -277,8 +270,8 @@ func (p *InfobloxProvider) Records(ctx context.Context) (endpoints []*endpoint.E
View: p.view,
},
)
err = p.client.GetObject(objT, "", &resT)
if err != nil {
err = p.client.GetObject(objT, "", ibclient.NewQueryParams(false, nil), &resT)
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 @@ -377,9 +370,8 @@ func (p *InfobloxProvider) zones() ([]ibclient.ZoneAuth, error) {
View: p.view,
},
)
err := p.client.GetObject(obj, "", &res)

if err != nil {
err := p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil && !isNotFoundError(err) {
return nil, err
}

Expand Down Expand Up @@ -466,12 +458,12 @@ func (p *InfobloxProvider) findReverseZone(zones []ibclient.ZoneAuth, name strin
maxMask := 0

for i, zone := range zones {
_, net, err := net.ParseCIDR(zone.Fqdn)
_, rZoneNet, err := net.ParseCIDR(zone.Fqdn)
if err != nil {
logrus.WithError(err).Debugf("fqdn %s is no cidr", zone.Fqdn)
} else {
if net.Contains(ip) {
_, mask := net.Mask.Size()
if rZoneNet.Contains(ip) {
_, mask := rZoneNet.Mask.Size()
networks[mask] = &zones[i]
if mask > maxMask {
maxMask = mask
Expand All @@ -486,16 +478,13 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
switch ep.RecordType {
case endpoint.RecordTypeA:
var res []ibclient.RecordA
obj := ibclient.NewRecordA(
ibclient.RecordA{
Name: ep.DNSName,
Ipv4Addr: ep.Targets[targetIndex],
View: p.view,
},
)
obj := ibclient.NewEmptyRecordA()
obj.Name = ep.DNSName
obj.Ipv4Addr = ep.Targets[targetIndex]
obj.View = p.view
if getObject {
err = p.client.GetObject(obj, "", &res)
if err != nil {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil && !isNotFoundError(err) {
return
}
}
Expand All @@ -505,16 +494,13 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
}
case endpoint.RecordTypePTR:
var res []ibclient.RecordPTR
obj := ibclient.NewRecordPTR(
ibclient.RecordPTR{
PtrdName: ep.DNSName,
Ipv4Addr: ep.Targets[targetIndex],
View: p.view,
},
)
obj := ibclient.NewEmptyRecordPTR()
obj.PtrdName = ep.DNSName
obj.Ipv4Addr = ep.Targets[targetIndex]
obj.View = p.view
if getObject {
err = p.client.GetObject(obj, "", &res)
if err != nil {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil && !isNotFoundError(err) {
return
}
}
Expand All @@ -524,16 +510,13 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
}
case endpoint.RecordTypeCNAME:
var res []ibclient.RecordCNAME
obj := ibclient.NewRecordCNAME(
ibclient.RecordCNAME{
Name: ep.DNSName,
Canonical: ep.Targets[0],
View: p.view,
},
)
obj := ibclient.NewEmptyRecordCNAME()
obj.Name = ep.DNSName
obj.Canonical = ep.Targets[0]
obj.View = p.view
if getObject {
err = p.client.GetObject(obj, "", &res)
if err != nil {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil && !isNotFoundError(err) {
return
}
}
Expand All @@ -556,8 +539,8 @@ func (p *InfobloxProvider) recordSet(ep *endpoint.Endpoint, getObject bool, targ
},
)
if getObject {
err = p.client.GetObject(obj, "", &res)
if err != nil {
err = p.client.GetObject(obj, "", ibclient.NewQueryParams(false, nil), &res)
if err != nil && !isNotFoundError(err) {
return
}
}
Expand Down
Loading

0 comments on commit bcd6e7f

Please sign in to comment.