Skip to content

Commit

Permalink
Fix pagination of auth zones and missing record view
Browse files Browse the repository at this point in the history
  • Loading branch information
jskrill committed Oct 3, 2024
1 parent 3fddeb4 commit 12abe4b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ jobs:
CI_COMMIT_TIMESTAMP: ${{ github.event.repository.updated_at }}
CI_COMMIT_SHA: ${{ github.sha }}
CI_COMMIT_TAG: ${{ needs.release.outputs.tag_name }}
REPO_NAME: ${{ github.repository }}
30 changes: 15 additions & 15 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ dockers:
goos: linux
goarch: amd64
image_templates:
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-amd64
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-amd64
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-amd64
- ghcr.io/{{ .Env.REPO_NAME }}:latest-amd64
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-amd64
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-amd64
build_flag_templates:
- --pull
- --platform=linux/amd64
Expand All @@ -56,28 +56,28 @@ dockers:
goos: linux
goarch: arm64
image_templates:
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-arm64
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-arm64
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-arm64
- ghcr.io/{{ .Env.REPO_NAME }}:latest-arm64
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-arm64
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-arm64
build_flag_templates:
- --pull
- --platform=linux/arm64
- --build-arg=CI_COMMIT_TIMESTAMP="{{ .Env.CI_COMMIT_TIMESTAMP }}"
- --build-arg=CI_COMMIT_SHA="{{ .Env.CI_COMMIT_SHA }}"
- --build-arg=CI_COMMIT_TAG="{{ .Env.CI_COMMIT_TAG }}"
docker_manifests:
- name_template: ghcr.io/absaoss/external-dns-infoblox-webhook:latest
- name_template: ghcr.io/{{ .Env.REPO_NAME }}:latest
image_templates:
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-amd64
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-arm64
- name_template: ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}
- ghcr.io/{{ .Env.REPO_NAME }}:latest-amd64
- ghcr.io/{{ .Env.REPO_NAME }}:latest-arm64
- name_template: ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}
image_templates:
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-amd64
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-arm64
- name_template: ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-amd64
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-arm64
- name_template: ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}
image_templates:
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-amd64
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-arm64
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-amd64
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-arm64
changelog:
skip: true
use: github
Expand Down
23 changes: 9 additions & 14 deletions internal/infoblox/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,6 @@ func NewInfobloxProvider(cfg *StartupConfig, domainFilter endpoint.DomainFilter)
return provider, nil
}

func recordQueryParams(zone string, view string) *ibclient.QueryParams {
searchFields := map[string]string{}
if zone != "" {
searchFields["zone"] = zone
}

if view != "" {
searchFields["view"] = view
}
return ibclient.NewQueryParams(false, searchFields)
}

// Records gets the current records.
func (p *Provider) Records(_ context.Context) (endpoints []*endpoint.Endpoint, err error) {
zones, err := p.zones()
Expand Down Expand Up @@ -519,8 +507,11 @@ func (p *Provider) zones() ([]ibclient.ZoneAuth, error) {
View: &p.config.View,
},
)
queryParams := recordQueryParams("", p.config.View)
err := p.client.GetObject(obj, "", queryParams, &res)
searchFields := map[string]string{}
if p.config.View != "" {
searchFields["view"] = p.config.View
}
err := PagingGetObject(p.client, obj, "", searchFields, &res)
if err != nil && !isNotFoundError(err) {
return nil, err
}
Expand Down Expand Up @@ -630,6 +621,7 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
obj.Ipv4Addr = &ep.Targets[0]
obj.Ttl = &ttl
obj.UseTtl = &ptrToBoolTrue
obj.View = p.config.View
if getObject {
queryParams := ibclient.NewQueryParams(false, map[string]string{"name": *obj.Name, "ipv4addr": *obj.Ipv4Addr})
err = p.client.GetObject(obj, "", queryParams, &res)
Expand All @@ -650,6 +642,7 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
obj.Ipv4Addr = &ep.Targets[0]
obj.Ttl = &ttl
obj.UseTtl = &ptrToBoolTrue
obj.View = p.config.View
if getObject {
queryParams := ibclient.NewQueryParams(false, map[string]string{"name": *obj.PtrdName})
err = p.client.GetObject(obj, "", queryParams, &res)
Expand All @@ -668,6 +661,7 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
obj.Canonical = &ep.Targets[0]
obj.Ttl = &ttl
obj.UseTtl = &ptrToBoolTrue
obj.View = &p.config.View
if getObject {
queryParams := ibclient.NewQueryParams(false, map[string]string{"name": *obj.Name})
err = p.client.GetObject(obj, "", queryParams, &res)
Expand All @@ -691,6 +685,7 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
obj.Name = &ep.DNSName
obj.Ttl = &ttl
obj.UseTtl = &ptrToBoolTrue
obj.View = &p.config.View
// TODO: Zone?
if getObject {
queryParams := ibclient.NewQueryParams(false, map[string]string{"name": *obj.Name})
Expand Down
19 changes: 16 additions & 3 deletions internal/infoblox/infoblox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ func (client *mockIBConnector) CreateObject(obj ibclient.IBObject) (ref string,
func (client *mockIBConnector) GetObject(obj ibclient.IBObject, ref string, queryParams *ibclient.QueryParams, res interface{}) (err error) {
isPagingType := false
switch res.(type) {
case *pagingResponseStruct[ibclient.ZoneAuth]:
isPagingType = true
case *pagingResponseStruct[ibclient.RecordA]:
isPagingType = true
case *pagingResponseStruct[ibclient.HostRecord]:
Expand Down Expand Up @@ -358,7 +360,11 @@ func (client *mockIBConnector) GetObject(obj ibclient.IBObject, ref string, quer
*res.(*[]ibclient.RecordPTR) = result
}
case "zone_auth":
*res.(*[]ibclient.ZoneAuth) = *client.mockInfobloxZones
if isPagingType {
res.(*pagingResponseStruct[ibclient.ZoneAuth]).Result = *client.mockInfobloxZones
} else {
*res.(*[]ibclient.ZoneAuth) = *client.mockInfobloxZones
}
}
return
}
Expand Down Expand Up @@ -643,7 +649,10 @@ func TestInfobloxRecords(t *testing.T) {
endpoint.NewEndpoint("host.example.com", endpoint.RecordTypeA, "125.1.1.1"),
}
validateEndpoints(t, actual, expected)
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{}).
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{
"_max_results": "1000",
"_paging": "1",
"_return_as_object": "1"}).
ExpectNotRequestURLQueryParam(t, "view").
ExpectNotRequestURLQueryParam(t, "zone")
client.verifyGetObjectRequest(t, "record:a", "", &map[string]string{
Expand Down Expand Up @@ -699,7 +708,11 @@ func TestInfobloxRecordsWithView(t *testing.T) {
endpoint.NewEndpoint("dog.bar.example.com", endpoint.RecordTypeA, "123.123.123.123"),
}
validateEndpoints(t, actual, expected)
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{"view": "Inside"}).
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{
"_max_results": "1000",
"_paging": "1",
"_return_as_object": "1",
"view": "Inside"}).
ExpectRequestURLQueryParam(t, "view", "Inside").
ExpectNotRequestURLQueryParam(t, "zone")
client.verifyGetObjectRequest(t, "record:a", "", &map[string]string{
Expand Down

0 comments on commit 12abe4b

Please sign in to comment.