Skip to content

Commit

Permalink
Bump Infoblox go client to v2 (2.1.2-0.20220727224704-88a5ba602dbf)
Browse files Browse the repository at this point in the history
The latest released version of this go client doesn't have the full
support for CRUDING the TXT records (get is missing) so we need to depend on a git sha.

It was a major version upgrade so some API was changed and some method signatures were modified.

Namely:
 - inicialization of the client is different, it now requires the auth config to be passed as a separate struct
 - creating TXT record requires a view argument
 - `uint -> uint32` for ttl in method signatures
 - `*ibcl.ObjectManager -> ibcl.IBObjectManager`

Signed-off-by: Jirka Kremser <[email protected]>
  • Loading branch information
jkremser committed Aug 2, 2022
1 parent 8820bba commit 699f226
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ mocks:
mockgen -source=controllers/providers/dns/dns.go -destination=controllers/providers/dns/dns_mock.go -package=dns
mockgen -source=controllers/providers/dns/infoblox-client.go -destination=controllers/providers/dns/infoblox-client_mock.go -package=dns
mockgen -source=controllers/depresolver/resolver.go -destination=controllers/depresolver/resolver_mock.go -package=depresolver
mockgen -destination=controllers/providers/dns/infoblox-connection_mock.go -package=dns github.com/infobloxopen/infoblox-go-client IBConnector
mockgen -destination=controllers/providers/dns/infoblox-connection_mock.go -package=dns github.com/infobloxopen/infoblox-go-client/v2 IBConnector
$(call golic)

# remove clusters and redeploy
Expand Down
34 changes: 17 additions & 17 deletions controllers/depresolver/resolver_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions controllers/providers/dns/infoblox-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
import (
"strconv"

ibclient "github.com/infobloxopen/infoblox-go-client"
ibclient "github.com/infobloxopen/infoblox-go-client/v2"
"github.com/k8gb-io/k8gb/controllers/depresolver"
)

type InfobloxClient interface {
GetObjectManager() (objMgr *ibclient.ObjectManager, err error)
GetObjectManager() (objMgr ibclient.IBObjectManager, err error)
}

type Client struct {
objMgr *ibclient.ObjectManager
objMgr ibclient.IBObjectManager
config depresolver.Config
}

Expand All @@ -40,18 +40,17 @@ func NewInfobloxClient(config depresolver.Config) *Client {
}
}

func (c *Client) GetObjectManager() (objMgr *ibclient.ObjectManager, err error) {
func (c *Client) GetObjectManager() (objMgr ibclient.IBObjectManager, err error) {
hostConfig := ibclient.HostConfig{
Host: c.config.Infoblox.Host,
Version: c.config.Infoblox.Version,
Port: strconv.Itoa(c.config.Infoblox.Port),
Username: c.config.Infoblox.Username,
Password: c.config.Infoblox.Password,
}
authConfig := ibclient.AuthConfig{Username: c.config.Infoblox.Username, Password: c.config.Infoblox.Password}
transportConfig := ibclient.NewTransportConfig("false", c.config.Infoblox.HTTPRequestTimeout, c.config.Infoblox.HTTPPoolConnections)
requestBuilder := &ibclient.WapiRequestBuilder{}
requestor := &ibclient.WapiHttpRequestor{}
conn, err := ibclient.NewConnector(hostConfig, transportConfig, requestBuilder, requestor)
conn, err := ibclient.NewConnector(hostConfig, authConfig, transportConfig, requestBuilder, requestor)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/providers/dns/infoblox-client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions controllers/providers/dns/infoblox-connection_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controllers/providers/dns/infoblox-sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Generated by GoLic, for more details see: https://github.com/AbsaOSS/golic
import (
"sort"

ibclient "github.com/infobloxopen/infoblox-go-client"
ibclient "github.com/infobloxopen/infoblox-go-client/v2"
)

type byAddress []ibclient.NameServer
Expand Down
30 changes: 15 additions & 15 deletions controllers/providers/dns/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

externaldns "sigs.k8s.io/external-dns/endpoint"

ibcl "github.com/infobloxopen/infoblox-go-client"
ibcl "github.com/infobloxopen/infoblox-go-client/v2"
k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
"github.com/k8gb-io/k8gb/controllers/depresolver"
"github.com/k8gb-io/k8gb/controllers/providers/assistant"
Expand Down Expand Up @@ -212,7 +212,7 @@ func (p *InfobloxProvider) String() string {
return "Infoblox"
}

func (p *InfobloxProvider) saveHeartbeatTXTRecord(objMgr *ibcl.ObjectManager, gslb *k8gbv1beta1.Gslb) (err error) {
func (p *InfobloxProvider) saveHeartbeatTXTRecord(objMgr ibcl.IBObjectManager, gslb *k8gbv1beta1.Gslb) (err error) {
var heartbeatTXTRecord *ibcl.RecordTXT
edgeTimestamp := fmt.Sprint(time.Now().UTC().Format("2006-01-02T15:04:05"))
heartbeatTXTName := p.config.GetClusterHeartbeatFQDN(gslb.Name)
Expand All @@ -224,7 +224,7 @@ func (p *InfobloxProvider) saveHeartbeatTXTRecord(objMgr *ibcl.ObjectManager, gs
log.Info().
Str("HeartbeatTXTName", heartbeatTXTName).
Msg("Creating split brain TXT record")
_, err = p.createTXTRecord(objMgr, heartbeatTXTName, edgeTimestamp, uint(gslb.Spec.Strategy.DNSTtlSeconds))
_, err = p.createTXTRecord(objMgr, heartbeatTXTName, edgeTimestamp, uint32(gslb.Spec.Strategy.DNSTtlSeconds))
if err != nil {
m.InfobloxIncrementHeartbeatError(gslb)
return
Expand All @@ -233,7 +233,7 @@ func (p *InfobloxProvider) saveHeartbeatTXTRecord(objMgr *ibcl.ObjectManager, gs
log.Info().
Str("HeartbeatTXTName", heartbeatTXTName).
Msg("Updating split brain TXT record")
_, err = p.updateTXTRecord(objMgr, heartbeatTXTName, edgeTimestamp)
_, err = p.updateTXTRecord(objMgr, heartbeatTXTName, edgeTimestamp, uint32(gslb.Spec.Strategy.DNSTtlSeconds))
if err != nil {
m.InfobloxIncrementHeartbeatError(gslb)
return
Expand Down Expand Up @@ -262,56 +262,56 @@ func (p *InfobloxProvider) filterOutDelegateTo(delegateTo []ibcl.NameServer, fqd
return
}

func (p *InfobloxProvider) createZoneDelegated(o *ibcl.ObjectManager, fqdn string, d []ibcl.NameServer) (res *ibcl.ZoneDelegated, err error) {
func (p *InfobloxProvider) createZoneDelegated(o ibcl.IBObjectManager, fqdn string, d []ibcl.NameServer) (res *ibcl.ZoneDelegated, err error) {
start := time.Now()
res, err = o.CreateZoneDelegated(fqdn, d)
m.InfobloxObserveRequestDuration(start, metrics.CreateZoneDelegated, err == nil)
return
}

func (p *InfobloxProvider) getZoneDelegated(o *ibcl.ObjectManager, fqdn string) (res *ibcl.ZoneDelegated, err error) {
func (p *InfobloxProvider) getZoneDelegated(o ibcl.IBObjectManager, fqdn string) (res *ibcl.ZoneDelegated, err error) {
start := time.Now()
res, err = o.GetZoneDelegated(fqdn)
m.InfobloxObserveRequestDuration(start, metrics.GetZoneDelegated, err == nil)
return
}

func (p *InfobloxProvider) updateZoneDelegated(o *ibcl.ObjectManager, fqdn string, d []ibcl.NameServer) (res *ibcl.ZoneDelegated, err error) {
func (p *InfobloxProvider) updateZoneDelegated(o ibcl.IBObjectManager, fqdn string, d []ibcl.NameServer) (res *ibcl.ZoneDelegated, err error) {
start := time.Now()
res, err = o.UpdateZoneDelegated(fqdn, d)
m.InfobloxObserveRequestDuration(start, metrics.UpdateZoneDelegated, err == nil)
return
}

func (p *InfobloxProvider) deleteZoneDelegated(o *ibcl.ObjectManager, fqdn string) (res string, err error) {
func (p *InfobloxProvider) deleteZoneDelegated(o ibcl.IBObjectManager, fqdn string) (res string, err error) {
start := time.Now()
res, err = o.DeleteZoneDelegated(fqdn)
m.InfobloxObserveRequestDuration(start, metrics.DeleteZoneDelegated, err == nil)
return
}

func (p *InfobloxProvider) createTXTRecord(o *ibcl.ObjectManager, name string, text string, ttl uint) (res *ibcl.RecordTXT, err error) {
func (p *InfobloxProvider) createTXTRecord(o ibcl.IBObjectManager, name string, text string, ttl uint32) (res *ibcl.RecordTXT, err error) {
start := time.Now()
res, err = o.CreateTXTRecord(name, text, ttl, "default")
res, err = o.CreateTXTRecord("", name, text, ttl, true, "default", nil)
m.InfobloxObserveRequestDuration(start, metrics.CreateTXTRecord, err == nil)
return
}

func (p *InfobloxProvider) getTXTRecord(o *ibcl.ObjectManager, name string) (res *ibcl.RecordTXT, err error) {
func (p *InfobloxProvider) getTXTRecord(o ibcl.IBObjectManager, name string) (res *ibcl.RecordTXT, err error) {
start := time.Now()
res, err = o.GetTXTRecord(name)
res, err = o.GetTXTRecord("", name)
m.InfobloxObserveRequestDuration(start, metrics.GetTXTRecord, err == nil)
return
}

func (p *InfobloxProvider) updateTXTRecord(o *ibcl.ObjectManager, name string, text string) (res *ibcl.RecordTXT, err error) {
func (p *InfobloxProvider) updateTXTRecord(o ibcl.IBObjectManager, name string, text string, ttl uint32) (res *ibcl.RecordTXT, err error) {
start := time.Now()
res, err = o.UpdateTXTRecord(name, text)
res, err = o.UpdateTXTRecord("", name, text, ttl, true, "default", nil)
m.InfobloxObserveRequestDuration(start, metrics.UpdateTXTRecord, err == nil)
return
}

func (p *InfobloxProvider) deleteTXTRecord(o *ibcl.ObjectManager, name string) (res string, err error) {
func (p *InfobloxProvider) deleteTXTRecord(o ibcl.IBObjectManager, name string) (res string, err error) {
start := time.Now()
res, err = o.DeleteTXTRecord(name)
m.InfobloxObserveRequestDuration(start, metrics.DeleteTXTRecord, err == nil)
Expand Down
16 changes: 8 additions & 8 deletions controllers/providers/dns/infoblox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"testing"

"github.com/golang/mock/gomock"
ibclient "github.com/infobloxopen/infoblox-go-client"
ibclient "github.com/infobloxopen/infoblox-go-client/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -170,7 +170,7 @@ func TestInfobloxCreateZoneDelegationForExternalDNS(t *testing.T) {
a.EXPECT().GslbIngressExposedIPs(gomock.Any()).Return(ipRange, nil).Times(1)
con.EXPECT().CreateObject(gomock.Any()).Return(ref, nil).AnyTimes()
con.EXPECT().UpdateObject(gomock.Any(), gomock.Any()).Return(ref, nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
cl.EXPECT().GetObjectManager().Return(ibclient.NewObjectManager(con, "k8gbclient", ""), nil).Times(1)
config := defaultConfig
provider := NewInfobloxDNS(config, a, cl)
Expand All @@ -194,9 +194,9 @@ func TestInfobloxCreateZoneDelegationForExternalDNSWithSplitBrainEnabled(t *test
}).Return(nil).Times(1)
con.EXPECT().CreateObject(gomock.Any()).Return(ref, nil).AnyTimes()
con.EXPECT().UpdateObject(gomock.Any(), gomock.Any()).Return(ref, nil).Times(2)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
cl.EXPECT().GetObjectManager().Return(ibclient.NewObjectManager(con, "k8gbclient", ""), nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{{Ref: ref}}).
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{{Ref: ref}}).
Return(nil).Do(func(arg0 *ibclient.RecordTXT, arg1, arg2 interface{}) {
require.Equal(t, "test-gslb-heartbeat-us-west-1.example.com", arg0.Name)
}).AnyTimes()
Expand All @@ -221,9 +221,9 @@ func TestInfobloxCreateZoneDelegationForExternalDNSWithSplitBrainEnabledCreating
a.EXPECT().InspectTXTThreshold(gomock.Any(), gomock.Any()).Return(nil).Times(1)
con.EXPECT().CreateObject(gomock.Any()).Return(ref, nil).AnyTimes()
con.EXPECT().UpdateObject(gomock.Any(), gomock.Any()).Return(ref, nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).Return(nil)
cl.EXPECT().GetObjectManager().Return(ibclient.NewObjectManager(con, "k8gbclient", ""), nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{}).Return(nil).AnyTimes()
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{}).Return(nil).AnyTimes()
config := defaultConfig
config.SplitBrainCheck = true
provider := NewInfobloxDNS(config, a, cl)
Expand All @@ -244,9 +244,9 @@ func TestInfobloxFinalize(t *testing.T) {
con.EXPECT().DeleteObject(gomock.Any()).Return(ref, nil).Do(func(arg0 string) {
require.Equal(t, arg0, ref)
}).AnyTimes()
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.ZoneDelegated{defaultDelegatedZone}).
Return(nil).Times(1)
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{{Ref: ref}}).
con.EXPECT().GetObject(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).SetArg(2, []ibclient.RecordTXT{{Ref: ref}}).
Return(nil).Do(func(arg0 *ibclient.RecordTXT, arg1, arg2 interface{}) {
require.Equal(t, "test-gslb-heartbeat-us-west-1.example.com", arg0.Name)
}).Times(1)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/google/uuid v1.1.2 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/infobloxopen/infoblox-go-client/v2 v2.1.2-0.20220727224704-88a5ba602dbf // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,10 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
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.2-0.20220407114022-6f4c71443168 h1:EXKtVoP/44ckXpw3v2/vrtMEdKx/PA+YBl+REoV27XQ=
github.com/infobloxopen/infoblox-go-client/v2 v2.1.2-0.20220407114022-6f4c71443168/go.mod h1:+lznx4ASBSUZ2i6qwlgyn0v3eKDxBHNU5aRJzghAFbw=
github.com/infobloxopen/infoblox-go-client/v2 v2.1.2-0.20220727224704-88a5ba602dbf h1:/4CHlCAQbzdED7T6YZ1ht7uQ8HNBR+eeR5hW44+du54=
github.com/infobloxopen/infoblox-go-client/v2 v2.1.2-0.20220727224704-88a5ba602dbf/go.mod h1:+lznx4ASBSUZ2i6qwlgyn0v3eKDxBHNU5aRJzghAFbw=
github.com/jcmturner/aescts/v2 v2.0.0/go.mod h1:AiaICIRyfYg35RUkr8yESTqvSy7csK90qZ5xfvvsoNs=
github.com/jcmturner/dnsutils/v2 v2.0.0/go.mod h1:b0TnjGOvI/n42bZa+hmXL+kFJZsFT7G4t3HTlQ184QM=
github.com/jcmturner/gofork v1.0.0/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
Expand Down

0 comments on commit 699f226

Please sign in to comment.