Skip to content

Commit 241dcc9

Browse files
authored
Fix pagination of auth zones and missing record view (#21)
1 parent 30ab566 commit 241dcc9

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,4 @@ jobs:
9191
CI_COMMIT_TIMESTAMP: ${{ github.event.repository.updated_at }}
9292
CI_COMMIT_SHA: ${{ github.sha }}
9393
CI_COMMIT_TAG: ${{ needs.release.outputs.tag_name }}
94+
REPO_NAME: ${{ github.repository }}

.goreleaser.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ dockers:
4343
goos: linux
4444
goarch: amd64
4545
image_templates:
46-
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-amd64
47-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-amd64
48-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-amd64
46+
- ghcr.io/{{ .Env.REPO_NAME }}:latest-amd64
47+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-amd64
48+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-amd64
4949
build_flag_templates:
5050
- --pull
5151
- --platform=linux/amd64
@@ -56,28 +56,28 @@ dockers:
5656
goos: linux
5757
goarch: arm64
5858
image_templates:
59-
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-arm64
60-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-arm64
61-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-arm64
59+
- ghcr.io/{{ .Env.REPO_NAME }}:latest-arm64
60+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-arm64
61+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-arm64
6262
build_flag_templates:
6363
- --pull
6464
- --platform=linux/arm64
6565
- --build-arg=CI_COMMIT_TIMESTAMP="{{ .Env.CI_COMMIT_TIMESTAMP }}"
6666
- --build-arg=CI_COMMIT_SHA="{{ .Env.CI_COMMIT_SHA }}"
6767
- --build-arg=CI_COMMIT_TAG="{{ .Env.CI_COMMIT_TAG }}"
6868
docker_manifests:
69-
- name_template: ghcr.io/absaoss/external-dns-infoblox-webhook:latest
69+
- name_template: ghcr.io/{{ .Env.REPO_NAME }}:latest
7070
image_templates:
71-
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-amd64
72-
- ghcr.io/absaoss/external-dns-infoblox-webhook:latest-arm64
73-
- name_template: ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}
71+
- ghcr.io/{{ .Env.REPO_NAME }}:latest-amd64
72+
- ghcr.io/{{ .Env.REPO_NAME }}:latest-arm64
73+
- name_template: ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}
7474
image_templates:
75-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-amd64
76-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_SHA }}-arm64
77-
- name_template: ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}
75+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-amd64
76+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_SHA }}-arm64
77+
- name_template: ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}
7878
image_templates:
79-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-amd64
80-
- ghcr.io/absaoss/external-dns-infoblox-webhook:{{ .Env.CI_COMMIT_TAG }}-arm64
79+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-amd64
80+
- ghcr.io/{{ .Env.REPO_NAME }}:{{ .Env.CI_COMMIT_TAG }}-arm64
8181
changelog:
8282
skip: true
8383
use: github

internal/infoblox/infoblox.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,6 @@ func NewInfobloxProvider(cfg *StartupConfig, domainFilter endpoint.DomainFilter)
175175
return provider, nil
176176
}
177177

178-
func recordQueryParams(zone string, view string) *ibclient.QueryParams {
179-
searchFields := map[string]string{}
180-
if zone != "" {
181-
searchFields["zone"] = zone
182-
}
183-
184-
if view != "" {
185-
searchFields["view"] = view
186-
}
187-
return ibclient.NewQueryParams(false, searchFields)
188-
}
189-
190178
// Records gets the current records.
191179
func (p *Provider) Records(_ context.Context) (endpoints []*endpoint.Endpoint, err error) {
192180
zones, err := p.zones()
@@ -568,8 +556,11 @@ func (p *Provider) zones() ([]ibclient.ZoneAuth, error) {
568556
View: &p.config.View,
569557
},
570558
)
571-
queryParams := recordQueryParams("", p.config.View)
572-
err := p.client.GetObject(obj, "", queryParams, &res)
559+
searchFields := map[string]string{}
560+
if p.config.View != "" {
561+
searchFields["view"] = p.config.View
562+
}
563+
err := PagingGetObject(p.client, obj, "", searchFields, &res)
573564
if err != nil && !isNotFoundError(err) {
574565
return nil, err
575566
}
@@ -686,6 +677,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
686677
err = fmt.Errorf("could not fetch A record ['%s':'%s'] : %w", *obj.Name, *obj.Ipv4Addr, err)
687678
return
688679
}
680+
} else {
681+
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
682+
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
683+
obj.View = p.config.View
689684
}
690685
recordSet = infobloxRecordSet{
691686
obj: obj,
@@ -705,6 +700,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
705700
if err != nil && !isNotFoundError(err) {
706701
return
707702
}
703+
} else {
704+
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
705+
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
706+
obj.View = p.config.View
708707
}
709708
recordSet = infobloxRecordSet{
710709
obj: obj,
@@ -723,6 +722,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
723722
if err != nil && !isNotFoundError(err) {
724723
return
725724
}
725+
} else {
726+
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
727+
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
728+
obj.View = &p.config.View
726729
}
727730
recordSet = infobloxRecordSet{
728731
obj: obj,
@@ -747,6 +750,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
747750
if err != nil && !isNotFoundError(err) {
748751
return
749752
}
753+
} else {
754+
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
755+
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
756+
obj.View = &p.config.View
750757
}
751758
recordSet = infobloxRecordSet{
752759
obj: obj,

internal/infoblox/infoblox_test.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ func (client *mockIBConnector) CreateObject(obj ibclient.IBObject) (ref string,
192192
func (client *mockIBConnector) GetObject(obj ibclient.IBObject, ref string, queryParams *ibclient.QueryParams, res interface{}) (err error) {
193193
isPagingType := false
194194
switch res.(type) {
195+
case *pagingResponseStruct[ibclient.ZoneAuth]:
196+
isPagingType = true
195197
case *pagingResponseStruct[ibclient.RecordA]:
196198
isPagingType = true
197199
case *pagingResponseStruct[ibclient.HostRecord]:
@@ -357,7 +359,11 @@ func (client *mockIBConnector) GetObject(obj ibclient.IBObject, ref string, quer
357359
*res.(*[]ibclient.RecordPTR) = result
358360
}
359361
case "zone_auth":
360-
*res.(*[]ibclient.ZoneAuth) = *client.mockInfobloxZones
362+
if isPagingType {
363+
res.(*pagingResponseStruct[ibclient.ZoneAuth]).Result = *client.mockInfobloxZones
364+
} else {
365+
*res.(*[]ibclient.ZoneAuth) = *client.mockInfobloxZones
366+
}
361367
}
362368
return
363369
}
@@ -642,7 +648,10 @@ func TestInfobloxRecords(t *testing.T) {
642648
endpoint.NewEndpoint("host.example.com", endpoint.RecordTypeA, "125.1.1.1"),
643649
}
644650
validateEndpoints(t, actual, expected)
645-
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{}).
651+
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{
652+
"_max_results": "1000",
653+
"_paging": "1",
654+
"_return_as_object": "1"}).
646655
ExpectNotRequestURLQueryParam(t, "view").
647656
ExpectNotRequestURLQueryParam(t, "zone")
648657
client.verifyGetObjectRequest(t, "record:a", "", &map[string]string{
@@ -698,7 +707,11 @@ func TestInfobloxRecordsWithView(t *testing.T) {
698707
endpoint.NewEndpoint("dog.bar.example.com", endpoint.RecordTypeA, "123.123.123.123"),
699708
}
700709
validateEndpoints(t, actual, expected)
701-
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{"view": "Inside"}).
710+
client.verifyGetObjectRequest(t, "zone_auth", "", &map[string]string{
711+
"_max_results": "1000",
712+
"_paging": "1",
713+
"_return_as_object": "1",
714+
"view": "Inside"}).
702715
ExpectRequestURLQueryParam(t, "view", "Inside").
703716
ExpectNotRequestURLQueryParam(t, "zone")
704717
client.verifyGetObjectRequest(t, "record:a", "", &map[string]string{

0 commit comments

Comments
 (0)