From 8dc667a2f6d470e04840377ff6a4a4be8ee6a7e1 Mon Sep 17 00:00:00 2001 From: Mikhail Rozentsvayg Date: Tue, 18 Feb 2025 15:04:15 -0800 Subject: [PATCH] review suggestions based improvements --- provider/cloudflare/cloudflare.go | 15 +++++++-------- provider/cloudflare/cloudflare_test.go | 2 +- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/provider/cloudflare/cloudflare.go b/provider/cloudflare/cloudflare.go index 21ca5f719..75582aabe 100644 --- a/provider/cloudflare/cloudflare.go +++ b/provider/cloudflare/cloudflare.go @@ -307,7 +307,7 @@ func (p *CloudFlareProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, // As CloudFlare does not support "sets" of targets, but instead returns // a single entry for each name/type/target, we have to group by name // and record to allow the planner to calculate the correct plan. See #992. - endpoints = append(endpoints, groupByNameAndTypeWithCh(records, chs)...) + endpoints = append(endpoints, groupByNameAndTypeWithCustomHostnames(records, chs)...) } return endpoints, nil @@ -674,11 +674,7 @@ func getEndpointCustomHostname(endpoint *endpoint.Endpoint) string { return "" } -func groupByNameAndType(records []cloudflare.DNSRecord) []*endpoint.Endpoint { - return groupByNameAndTypeWithCh(records, []cloudflare.CustomHostname{}) -} - -func groupByNameAndTypeWithCh(records []cloudflare.DNSRecord, chs []cloudflare.CustomHostname) []*endpoint.Endpoint { +func groupByNameAndTypeWithCustomHostnames(records []cloudflare.DNSRecord, chs []cloudflare.CustomHostname) []*endpoint.Endpoint { endpoints := []*endpoint.Endpoint{} // group supported records by name and type @@ -723,9 +719,12 @@ func groupByNameAndTypeWithCh(records []cloudflare.DNSRecord, chs []cloudflare.C if records[0].Proxied != nil { proxied = *records[0].Proxied } + if ep == nil { + continue + } ep.WithProviderSpecific(source.CloudflareProxiedKey, strconv.FormatBool(proxied)) - if _, ok := customOriginServers[records[0].Name]; ok { - ep.WithProviderSpecific(source.CloudflareCustomHostnameKey, customOriginServers[records[0].Name]) + if customHostname, ok := customOriginServers[records[0].Name]; ok { + ep.WithProviderSpecific(source.CloudflareCustomHostnameKey, customHostname) } endpoints = append(endpoints, ep) diff --git a/provider/cloudflare/cloudflare_test.go b/provider/cloudflare/cloudflare_test.go index 10ea837c4..6529d5dca 100644 --- a/provider/cloudflare/cloudflare_test.go +++ b/provider/cloudflare/cloudflare_test.go @@ -1208,7 +1208,7 @@ func TestCloudflareGroupByNameAndType(t *testing.T) { } for _, tc := range testCases { - assert.ElementsMatch(t, groupByNameAndType(tc.Records), tc.ExpectedEndpoints) + assert.ElementsMatch(t, groupByNameAndTypeWithCustomHostnames(tc.Records, []cloudflare.CustomHostname{}), tc.ExpectedEndpoints) } }