Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination of auth zones and missing record view #21

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
35 changes: 21 additions & 14 deletions internal/infoblox/infoblox.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,18 +175,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 @@ -568,8 +556,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 @@ -686,6 +677,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
err = fmt.Errorf("could not fetch A record ['%s':'%s'] : %w", *obj.Name, *obj.Ipv4Addr, err)
return
}
} else {
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
obj.View = p.config.View
}
recordSet = infobloxRecordSet{
obj: obj,
Expand All @@ -705,6 +700,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
if err != nil && !isNotFoundError(err) {
return
}
} else {
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
obj.View = p.config.View
}
recordSet = infobloxRecordSet{
obj: obj,
Expand All @@ -723,6 +722,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
if err != nil && !isNotFoundError(err) {
return
}
} else {
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
obj.View = &p.config.View
}
recordSet = infobloxRecordSet{
obj: obj,
Expand All @@ -747,6 +750,10 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
if err != nil && !isNotFoundError(err) {
return
}
} else {
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
obj.View = &p.config.View
}
recordSet = infobloxRecordSet{
obj: obj,
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 @@ -357,7 +359,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 @@ -642,7 +648,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 @@ -698,7 +707,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
Loading