mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 09:36:58 +02:00
refactor(provider/cloudflare): use local regionalHostname struct (#5615)
This commit is contained in:
parent
69d3424d4d
commit
5c42ed00c7
@ -220,7 +220,7 @@ type CloudFlareProvider struct {
|
|||||||
type cloudFlareChange struct {
|
type cloudFlareChange struct {
|
||||||
Action changeAction
|
Action changeAction
|
||||||
ResourceRecord cloudflare.DNSRecord
|
ResourceRecord cloudflare.DNSRecord
|
||||||
RegionalHostname cloudflare.RegionalHostname
|
RegionalHostname regionalHostname
|
||||||
CustomHostnames map[string]cloudflare.CustomHostname
|
CustomHostnames map[string]cloudflare.CustomHostname
|
||||||
CustomHostnamesPrev []string
|
CustomHostnamesPrev []string
|
||||||
}
|
}
|
||||||
|
@ -40,12 +40,17 @@ var recordTypeRegionalHostnameSupported = map[string]bool{
|
|||||||
"CNAME": true,
|
"CNAME": true,
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegionalHostnamesMap is a map of regional hostnames keyed by hostname.
|
type regionalHostname struct {
|
||||||
type RegionalHostnamesMap map[string]cloudflare.RegionalHostname
|
hostname string
|
||||||
|
regionKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
// regionalHostnamesMap is a map of regional hostnames keyed by hostname.
|
||||||
|
type regionalHostnamesMap map[string]regionalHostname
|
||||||
|
|
||||||
type regionalHostnameChange struct {
|
type regionalHostnameChange struct {
|
||||||
action changeAction
|
action changeAction
|
||||||
cloudflare.RegionalHostname
|
regionalHostname
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z zoneService) ListDataLocalizationRegionalHostnames(ctx context.Context, rc *cloudflare.ResourceContainer, rp cloudflare.ListDataLocalizationRegionalHostnamesParams) ([]cloudflare.RegionalHostname, error) {
|
func (z zoneService) ListDataLocalizationRegionalHostnames(ctx context.Context, rc *cloudflare.ResourceContainer, rp cloudflare.ListDataLocalizationRegionalHostnamesParams) ([]cloudflare.RegionalHostname, error) {
|
||||||
@ -69,16 +74,16 @@ func (z zoneService) DeleteDataLocalizationRegionalHostname(ctx context.Context,
|
|||||||
// createDataLocalizationRegionalHostnameParams is a function that returns the appropriate RegionalHostname Param based on the cloudFlareChange passed in
|
// createDataLocalizationRegionalHostnameParams is a function that returns the appropriate RegionalHostname Param based on the cloudFlareChange passed in
|
||||||
func createDataLocalizationRegionalHostnameParams(rhc regionalHostnameChange) cloudflare.CreateDataLocalizationRegionalHostnameParams {
|
func createDataLocalizationRegionalHostnameParams(rhc regionalHostnameChange) cloudflare.CreateDataLocalizationRegionalHostnameParams {
|
||||||
return cloudflare.CreateDataLocalizationRegionalHostnameParams{
|
return cloudflare.CreateDataLocalizationRegionalHostnameParams{
|
||||||
Hostname: rhc.Hostname,
|
Hostname: rhc.hostname,
|
||||||
RegionKey: rhc.RegionKey,
|
RegionKey: rhc.regionKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateDataLocalizationRegionalHostnameParams is a function that returns the appropriate RegionalHostname Param based on the cloudFlareChange passed in
|
// updateDataLocalizationRegionalHostnameParams is a function that returns the appropriate RegionalHostname Param based on the cloudFlareChange passed in
|
||||||
func updateDataLocalizationRegionalHostnameParams(rhc regionalHostnameChange) cloudflare.UpdateDataLocalizationRegionalHostnameParams {
|
func updateDataLocalizationRegionalHostnameParams(rhc regionalHostnameChange) cloudflare.UpdateDataLocalizationRegionalHostnameParams {
|
||||||
return cloudflare.UpdateDataLocalizationRegionalHostnameParams{
|
return cloudflare.UpdateDataLocalizationRegionalHostnameParams{
|
||||||
Hostname: rhc.Hostname,
|
Hostname: rhc.hostname,
|
||||||
RegionKey: rhc.RegionKey,
|
RegionKey: rhc.regionKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,8 +103,8 @@ func (p *CloudFlareProvider) submitRegionalHostnameChanges(ctx context.Context,
|
|||||||
// submitRegionalHostnameChange applies a single regional hostname change, returns false if it fails
|
// submitRegionalHostnameChange applies a single regional hostname change, returns false if it fails
|
||||||
func (p *CloudFlareProvider) submitRegionalHostnameChange(ctx context.Context, rhChange regionalHostnameChange, resourceContainer *cloudflare.ResourceContainer) bool {
|
func (p *CloudFlareProvider) submitRegionalHostnameChange(ctx context.Context, rhChange regionalHostnameChange, resourceContainer *cloudflare.ResourceContainer) bool {
|
||||||
changeLog := log.WithFields(log.Fields{
|
changeLog := log.WithFields(log.Fields{
|
||||||
"hostname": rhChange.Hostname,
|
"hostname": rhChange.hostname,
|
||||||
"region_key": rhChange.RegionKey,
|
"region_key": rhChange.regionKey,
|
||||||
"action": rhChange.action.String(),
|
"action": rhChange.action.String(),
|
||||||
"zone": resourceContainer.Identifier,
|
"zone": resourceContainer.Identifier,
|
||||||
})
|
})
|
||||||
@ -124,7 +129,7 @@ func (p *CloudFlareProvider) submitRegionalHostnameChange(ctx context.Context, r
|
|||||||
}
|
}
|
||||||
case cloudFlareDelete:
|
case cloudFlareDelete:
|
||||||
changeLog.Debug("Deleting regional hostname")
|
changeLog.Debug("Deleting regional hostname")
|
||||||
if err := p.Client.DeleteDataLocalizationRegionalHostname(ctx, resourceContainer, rhChange.Hostname); err != nil {
|
if err := p.Client.DeleteDataLocalizationRegionalHostname(ctx, resourceContainer, rhChange.hostname); err != nil {
|
||||||
changeLog.Errorf("failed to delete regional hostname: %v", err)
|
changeLog.Errorf("failed to delete regional hostname: %v", err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -132,34 +137,37 @@ func (p *CloudFlareProvider) submitRegionalHostnameChange(ctx context.Context, r
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *CloudFlareProvider) listDataLocalisationRegionalHostnames(ctx context.Context, resourceContainer *cloudflare.ResourceContainer) (RegionalHostnamesMap, error) {
|
func (p *CloudFlareProvider) listDataLocalisationRegionalHostnames(ctx context.Context, resourceContainer *cloudflare.ResourceContainer) (regionalHostnamesMap, error) {
|
||||||
rhs, err := p.Client.ListDataLocalizationRegionalHostnames(ctx, resourceContainer, cloudflare.ListDataLocalizationRegionalHostnamesParams{})
|
rhs, err := p.Client.ListDataLocalizationRegionalHostnames(ctx, resourceContainer, cloudflare.ListDataLocalizationRegionalHostnamesParams{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, convertCloudflareError(err)
|
return nil, convertCloudflareError(err)
|
||||||
}
|
}
|
||||||
rhsMap := make(RegionalHostnamesMap)
|
rhsMap := make(regionalHostnamesMap)
|
||||||
for _, r := range rhs {
|
for _, rh := range rhs {
|
||||||
rhsMap[r.Hostname] = r
|
rhsMap[rh.Hostname] = regionalHostname{
|
||||||
|
hostname: rh.Hostname,
|
||||||
|
regionKey: rh.RegionKey,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return rhsMap, nil
|
return rhsMap, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// regionalHostname returns a RegionalHostname for the given endpoint.
|
// regionalHostname returns a regionalHostname for the given endpoint.
|
||||||
//
|
//
|
||||||
// If the regional services feature is not enabled or the record type does not support regional hostnames,
|
// If the regional services feature is not enabled or the record type does not support regional hostnames,
|
||||||
// it returns an empty RegionalHostname.
|
// it returns an empty regionalHostname.
|
||||||
// If the endpoint has a specific region key set, it uses that; otherwise, it defaults to the region key configured in the provider.
|
// If the endpoint has a specific region key set, it uses that; otherwise, it defaults to the region key configured in the provider.
|
||||||
func (p *CloudFlareProvider) regionalHostname(ep *endpoint.Endpoint) cloudflare.RegionalHostname {
|
func (p *CloudFlareProvider) regionalHostname(ep *endpoint.Endpoint) regionalHostname {
|
||||||
if !p.RegionalServicesConfig.Enabled || !recordTypeRegionalHostnameSupported[ep.RecordType] {
|
if !p.RegionalServicesConfig.Enabled || !recordTypeRegionalHostnameSupported[ep.RecordType] {
|
||||||
return cloudflare.RegionalHostname{}
|
return regionalHostname{}
|
||||||
}
|
}
|
||||||
regionKey := p.RegionalServicesConfig.RegionKey
|
regionKey := p.RegionalServicesConfig.RegionKey
|
||||||
if epRegionKey, exists := ep.GetProviderSpecificProperty(annotations.CloudflareRegionKey); exists {
|
if epRegionKey, exists := ep.GetProviderSpecificProperty(annotations.CloudflareRegionKey); exists {
|
||||||
regionKey = epRegionKey
|
regionKey = epRegionKey
|
||||||
}
|
}
|
||||||
return cloudflare.RegionalHostname{
|
return regionalHostname{
|
||||||
Hostname: ep.DNSName,
|
hostname: ep.DNSName,
|
||||||
RegionKey: regionKey,
|
regionKey: regionKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +200,7 @@ func (p *CloudFlareProvider) addEnpointsProviderSpecificRegionKeyProperty(ctx co
|
|||||||
|
|
||||||
for _, ep := range supportedEndpoints {
|
for _, ep := range supportedEndpoints {
|
||||||
if rh, found := regionalHostnames[ep.DNSName]; found {
|
if rh, found := regionalHostnames[ep.DNSName]; found {
|
||||||
ep.SetProviderSpecificProperty(annotations.CloudflareRegionKey, rh.RegionKey)
|
ep.SetProviderSpecificProperty(annotations.CloudflareRegionKey, rh.regionKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -203,67 +211,67 @@ func (p *CloudFlareProvider) addEnpointsProviderSpecificRegionKeyProperty(ctx co
|
|||||||
// If there is a delete and a create or update action for the same hostname,
|
// If there is a delete and a create or update action for the same hostname,
|
||||||
// The create or update takes precedence.
|
// The create or update takes precedence.
|
||||||
// Returns an error for conflicting region keys.
|
// Returns an error for conflicting region keys.
|
||||||
func desiredRegionalHostnames(changes []*cloudFlareChange) ([]cloudflare.RegionalHostname, error) {
|
func desiredRegionalHostnames(changes []*cloudFlareChange) ([]regionalHostname, error) {
|
||||||
rhs := make(map[string]cloudflare.RegionalHostname)
|
rhs := make(map[string]regionalHostname)
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
if change.RegionalHostname.Hostname == "" {
|
if change.RegionalHostname.hostname == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rh, found := rhs[change.RegionalHostname.Hostname]
|
rh, found := rhs[change.RegionalHostname.hostname]
|
||||||
if !found {
|
if !found {
|
||||||
if change.Action == cloudFlareDelete {
|
if change.Action == cloudFlareDelete {
|
||||||
rhs[change.RegionalHostname.Hostname] = cloudflare.RegionalHostname{
|
rhs[change.RegionalHostname.hostname] = regionalHostname{
|
||||||
Hostname: change.RegionalHostname.Hostname,
|
hostname: change.RegionalHostname.hostname,
|
||||||
RegionKey: "", // Indicate that this regional hostname should not exists
|
regionKey: "", // Indicate that this regional hostname should not exists
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rhs[change.RegionalHostname.Hostname] = change.RegionalHostname
|
rhs[change.RegionalHostname.hostname] = change.RegionalHostname
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if change.Action == cloudFlareDelete {
|
if change.Action == cloudFlareDelete {
|
||||||
// A previous regional hostname exists so we can skip this delete action
|
// A previous regional hostname exists so we can skip this delete action
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if rh.RegionKey == "" {
|
if rh.regionKey == "" {
|
||||||
// If the existing regional hostname has no region key, we can overwrite it
|
// If the existing regional hostname has no region key, we can overwrite it
|
||||||
rhs[change.RegionalHostname.Hostname] = change.RegionalHostname
|
rhs[change.RegionalHostname.hostname] = change.RegionalHostname
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if rh.RegionKey != change.RegionalHostname.RegionKey {
|
if rh.regionKey != change.RegionalHostname.regionKey {
|
||||||
return nil, fmt.Errorf("conflicting region keys for regional hostname %q: %q and %q", change.RegionalHostname.Hostname, rh.RegionKey, change.RegionalHostname.RegionKey)
|
return nil, fmt.Errorf("conflicting region keys for regional hostname %q: %q and %q", change.RegionalHostname.hostname, rh.regionKey, change.RegionalHostname.regionKey)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return slices.Collect(maps.Values(rhs)), nil
|
return slices.Collect(maps.Values(rhs)), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// regionalHostnamesChanges build a list of changes needed to synchronize the current regional hostnames state with the desired state.
|
// regionalHostnamesChanges build a list of changes needed to synchronize the current regional hostnames state with the desired state.
|
||||||
func regionalHostnamesChanges(desired []cloudflare.RegionalHostname, regionalHostnames RegionalHostnamesMap) []regionalHostnameChange {
|
func regionalHostnamesChanges(desired []regionalHostname, regionalHostnames regionalHostnamesMap) []regionalHostnameChange {
|
||||||
changes := make([]regionalHostnameChange, 0)
|
changes := make([]regionalHostnameChange, 0)
|
||||||
for _, rh := range desired {
|
for _, rh := range desired {
|
||||||
current, found := regionalHostnames[rh.Hostname]
|
current, found := regionalHostnames[rh.hostname]
|
||||||
if rh.RegionKey == "" {
|
if rh.regionKey == "" {
|
||||||
// If the region key is empty, we don't want a regional hostname
|
// If the region key is empty, we don't want a regional hostname
|
||||||
if !found {
|
if !found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
changes = append(changes, regionalHostnameChange{
|
changes = append(changes, regionalHostnameChange{
|
||||||
action: cloudFlareDelete,
|
action: cloudFlareDelete,
|
||||||
RegionalHostname: rh,
|
regionalHostname: rh,
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
changes = append(changes, regionalHostnameChange{
|
changes = append(changes, regionalHostnameChange{
|
||||||
action: cloudFlareCreate,
|
action: cloudFlareCreate,
|
||||||
RegionalHostname: rh,
|
regionalHostname: rh,
|
||||||
})
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if rh.RegionKey != current.RegionKey {
|
if rh.regionKey != current.regionKey {
|
||||||
changes = append(changes, regionalHostnameChange{
|
changes = append(changes, regionalHostnameChange{
|
||||||
action: cloudFlareUpdate,
|
action: cloudFlareUpdate,
|
||||||
RegionalHostname: rh,
|
regionalHostname: rh,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,14 @@ func (m *mockCloudFlareClient) ListDataLocalizationRegionalHostnames(ctx context
|
|||||||
if strings.Contains(rc.Identifier, "rherror") {
|
if strings.Contains(rc.Identifier, "rherror") {
|
||||||
return nil, fmt.Errorf("failed to list regional hostnames")
|
return nil, fmt.Errorf("failed to list regional hostnames")
|
||||||
}
|
}
|
||||||
return m.regionalHostnames[rc.Identifier], nil
|
rhs := make([]cloudflare.RegionalHostname, 0, len(m.regionalHostnames[rc.Identifier]))
|
||||||
|
for _, rh := range m.regionalHostnames[rc.Identifier] {
|
||||||
|
rhs = append(rhs, cloudflare.RegionalHostname{
|
||||||
|
Hostname: rh.hostname,
|
||||||
|
RegionKey: rh.regionKey,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return rhs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockCloudFlareClient) CreateDataLocalizationRegionalHostname(ctx context.Context, rc *cloudflare.ResourceContainer, rp cloudflare.CreateDataLocalizationRegionalHostnameParams) error {
|
func (m *mockCloudFlareClient) CreateDataLocalizationRegionalHostname(ctx context.Context, rc *cloudflare.ResourceContainer, rp cloudflare.CreateDataLocalizationRegionalHostnameParams) error {
|
||||||
@ -49,9 +56,9 @@ func (m *mockCloudFlareClient) CreateDataLocalizationRegionalHostname(ctx contex
|
|||||||
Name: "CreateDataLocalizationRegionalHostname",
|
Name: "CreateDataLocalizationRegionalHostname",
|
||||||
ZoneId: rc.Identifier,
|
ZoneId: rc.Identifier,
|
||||||
RecordId: "",
|
RecordId: "",
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: rp.Hostname,
|
hostname: rp.Hostname,
|
||||||
RegionKey: rp.RegionKey,
|
regionKey: rp.RegionKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
@ -66,9 +73,9 @@ func (m *mockCloudFlareClient) UpdateDataLocalizationRegionalHostname(ctx contex
|
|||||||
Name: "UpdateDataLocalizationRegionalHostname",
|
Name: "UpdateDataLocalizationRegionalHostname",
|
||||||
ZoneId: rc.Identifier,
|
ZoneId: rc.Identifier,
|
||||||
RecordId: "",
|
RecordId: "",
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: rp.Hostname,
|
hostname: rp.Hostname,
|
||||||
RegionKey: rp.RegionKey,
|
regionKey: rp.RegionKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
@ -82,8 +89,8 @@ func (m *mockCloudFlareClient) DeleteDataLocalizationRegionalHostname(ctx contex
|
|||||||
Name: "DeleteDataLocalizationRegionalHostname",
|
Name: "DeleteDataLocalizationRegionalHostname",
|
||||||
ZoneId: rc.Identifier,
|
ZoneId: rc.Identifier,
|
||||||
RecordId: "",
|
RecordId: "",
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: hostname,
|
hostname: hostname,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
@ -93,14 +100,14 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
records map[string]cloudflare.DNSRecord
|
records map[string]cloudflare.DNSRecord
|
||||||
regionalHostnames []cloudflare.RegionalHostname
|
regionalHostnames []regionalHostname
|
||||||
endpoints []*endpoint.Endpoint
|
endpoints []*endpoint.Endpoint
|
||||||
want []MockAction
|
want []MockAction
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "create",
|
name: "create",
|
||||||
records: map[string]cloudflare.DNSRecord{},
|
records: map[string]cloudflare.DNSRecord{},
|
||||||
regionalHostnames: []cloudflare.RegionalHostname{},
|
regionalHostnames: []regionalHostname{},
|
||||||
endpoints: []*endpoint.Endpoint{
|
endpoints: []*endpoint.Endpoint{
|
||||||
{
|
{
|
||||||
RecordType: "A",
|
RecordType: "A",
|
||||||
@ -131,9 +138,9 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Name: "CreateDataLocalizationRegionalHostname",
|
Name: "CreateDataLocalizationRegionalHostname",
|
||||||
ZoneId: "001",
|
ZoneId: "001",
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "create.bar.com",
|
hostname: "create.bar.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -150,10 +157,10 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
Proxied: proxyDisabled,
|
Proxied: proxyDisabled,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
regionalHostnames: []cloudflare.RegionalHostname{
|
regionalHostnames: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "update.bar.com",
|
hostname: "update.bar.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
endpoints: []*endpoint.Endpoint{
|
endpoints: []*endpoint.Endpoint{
|
||||||
@ -186,9 +193,9 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Name: "UpdateDataLocalizationRegionalHostname",
|
Name: "UpdateDataLocalizationRegionalHostname",
|
||||||
ZoneId: "001",
|
ZoneId: "001",
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "update.bar.com",
|
hostname: "update.bar.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -205,10 +212,10 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
Proxied: proxyDisabled,
|
Proxied: proxyDisabled,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
regionalHostnames: []cloudflare.RegionalHostname{
|
regionalHostnames: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "delete.bar.com",
|
hostname: "delete.bar.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
endpoints: []*endpoint.Endpoint{},
|
endpoints: []*endpoint.Endpoint{},
|
||||||
@ -222,8 +229,8 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Name: "DeleteDataLocalizationRegionalHostname",
|
Name: "DeleteDataLocalizationRegionalHostname",
|
||||||
ZoneId: "001",
|
ZoneId: "001",
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "delete.bar.com",
|
hostname: "delete.bar.com",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -240,10 +247,10 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
Proxied: proxyDisabled,
|
Proxied: proxyDisabled,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
regionalHostnames: []cloudflare.RegionalHostname{
|
regionalHostnames: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "nochange.bar.com",
|
hostname: "nochange.bar.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
endpoints: []*endpoint.Endpoint{
|
endpoints: []*endpoint.Endpoint{
|
||||||
@ -273,7 +280,7 @@ func TestCloudflareRegionalHostnameActions(t *testing.T) {
|
|||||||
Records: map[string]map[string]cloudflare.DNSRecord{
|
Records: map[string]map[string]cloudflare.DNSRecord{
|
||||||
"001": tt.records,
|
"001": tt.records,
|
||||||
},
|
},
|
||||||
regionalHostnames: map[string][]cloudflare.RegionalHostname{
|
regionalHostnames: map[string][]regionalHostname{
|
||||||
"001": tt.regionalHostnames,
|
"001": tt.regionalHostnames,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -323,9 +330,9 @@ func TestCloudflareRegionalHostnameDefaults(t *testing.T) {
|
|||||||
{
|
{
|
||||||
Name: "CreateDataLocalizationRegionalHostname",
|
Name: "CreateDataLocalizationRegionalHostname",
|
||||||
ZoneId: "001",
|
ZoneId: "001",
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "bar.com",
|
hostname: "bar.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -341,7 +348,7 @@ func Test_regionalHostname(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
args args
|
args args
|
||||||
want cloudflare.RegionalHostname
|
want regionalHostname
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "no region key",
|
name: "no region key",
|
||||||
@ -355,9 +362,9 @@ func Test_regionalHostname(t *testing.T) {
|
|||||||
RegionKey: "",
|
RegionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: cloudflare.RegionalHostname{
|
want: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -372,9 +379,9 @@ func Test_regionalHostname(t *testing.T) {
|
|||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: cloudflare.RegionalHostname{
|
want: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -395,9 +402,9 @@ func Test_regionalHostname(t *testing.T) {
|
|||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: cloudflare.RegionalHostname{
|
want: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -418,9 +425,9 @@ func Test_regionalHostname(t *testing.T) {
|
|||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: cloudflare.RegionalHostname{
|
want: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -441,7 +448,7 @@ func Test_regionalHostname(t *testing.T) {
|
|||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: cloudflare.RegionalHostname{},
|
want: regionalHostname{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "disabled",
|
name: "disabled",
|
||||||
@ -460,9 +467,9 @@ func Test_regionalHostname(t *testing.T) {
|
|||||||
Enabled: false,
|
Enabled: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: cloudflare.RegionalHostname{
|
want: regionalHostname{
|
||||||
Hostname: "",
|
hostname: "",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -479,7 +486,7 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
changes []*cloudFlareChange
|
changes []*cloudFlareChange
|
||||||
want []cloudflare.RegionalHostname
|
want []regionalHostname
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
@ -501,23 +508,23 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareUpdate,
|
Action: cloudFlareUpdate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []cloudflare.RegionalHostname{
|
want: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -527,16 +534,16 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareUpdate,
|
Action: cloudFlareUpdate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "us", // Different region key
|
regionKey: "us", // Different region key
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -548,38 +555,38 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example1.com",
|
hostname: "example1.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareUpdate,
|
Action: cloudFlareUpdate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example2.com",
|
hostname: "example2.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareDelete,
|
Action: cloudFlareDelete,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example3.com",
|
hostname: "example3.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []cloudflare.RegionalHostname{
|
want: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "example1.com",
|
hostname: "example1.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Hostname: "example2.com",
|
hostname: "example2.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Hostname: "example3.com",
|
hostname: "example3.com",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -589,16 +596,16 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "", // Empty region key
|
regionKey: "", // Empty region key
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []cloudflare.RegionalHostname{
|
want: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -608,23 +615,23 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "", // Empty region key
|
regionKey: "", // Empty region key
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareUpdate,
|
Action: cloudFlareUpdate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []cloudflare.RegionalHostname{
|
want: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -634,23 +641,23 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareUpdate,
|
Action: cloudFlareUpdate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu", // Empty region key
|
regionKey: "eu", // Empty region key
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []cloudflare.RegionalHostname{
|
want: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -660,23 +667,23 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareDelete,
|
Action: cloudFlareDelete,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []cloudflare.RegionalHostname{
|
want: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -686,23 +693,23 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
changes: []*cloudFlareChange{
|
changes: []*cloudFlareChange{
|
||||||
{
|
{
|
||||||
Action: cloudFlareCreate,
|
Action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Action: cloudFlareDelete,
|
Action: cloudFlareDelete,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []cloudflare.RegionalHostname{
|
want: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "example.com",
|
hostname: "example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
wantErr: false,
|
wantErr: false,
|
||||||
@ -718,10 +725,10 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
}
|
}
|
||||||
sort.Slice(got, func(i, j int) bool {
|
sort.Slice(got, func(i, j int) bool {
|
||||||
return got[i].Hostname < got[j].Hostname
|
return got[i].hostname < got[j].hostname
|
||||||
})
|
})
|
||||||
sort.Slice(tt.want, func(i, j int) bool {
|
sort.Slice(tt.want, func(i, j int) bool {
|
||||||
return tt.want[i].Hostname < tt.want[j].Hostname
|
return tt.want[i].hostname < tt.want[j].hostname
|
||||||
})
|
})
|
||||||
assert.Equal(t, tt.want, got)
|
assert.Equal(t, tt.want, got)
|
||||||
})
|
})
|
||||||
@ -731,74 +738,74 @@ func Test_desiredDataLocalizationRegionalHostnames(t *testing.T) {
|
|||||||
func Test_dataLocalizationRegionalHostnamesChanges(t *testing.T) {
|
func Test_dataLocalizationRegionalHostnamesChanges(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
desired []cloudflare.RegionalHostname
|
desired []regionalHostname
|
||||||
regionalHostnames RegionalHostnamesMap
|
regionalHostnames regionalHostnamesMap
|
||||||
want []regionalHostnameChange
|
want []regionalHostnameChange
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "empty desired and current lists",
|
name: "empty desired and current lists",
|
||||||
desired: []cloudflare.RegionalHostname{},
|
desired: []regionalHostname{},
|
||||||
regionalHostnames: RegionalHostnamesMap{},
|
regionalHostnames: regionalHostnamesMap{},
|
||||||
want: []regionalHostnameChange{},
|
want: []regionalHostnameChange{},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "multiple changes",
|
name: "multiple changes",
|
||||||
desired: []cloudflare.RegionalHostname{
|
desired: []regionalHostname{
|
||||||
{
|
{
|
||||||
Hostname: "create.example.com",
|
hostname: "create.example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Hostname: "update.example.com",
|
hostname: "update.example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Hostname: "delete.example.com",
|
hostname: "delete.example.com",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Hostname: "nochange.example.com",
|
hostname: "nochange.example.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Hostname: "absent.example.com",
|
hostname: "absent.example.com",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
regionalHostnames: RegionalHostnamesMap{
|
regionalHostnames: regionalHostnamesMap{
|
||||||
"update.example.com": cloudflare.RegionalHostname{
|
"update.example.com": regionalHostname{
|
||||||
Hostname: "update.example.com",
|
hostname: "update.example.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
"delete.example.com": cloudflare.RegionalHostname{
|
"delete.example.com": regionalHostname{
|
||||||
Hostname: "delete.example.com",
|
hostname: "delete.example.com",
|
||||||
RegionKey: "ap",
|
regionKey: "ap",
|
||||||
},
|
},
|
||||||
"nochange.example.com": cloudflare.RegionalHostname{
|
"nochange.example.com": regionalHostname{
|
||||||
Hostname: "nochange.example.com",
|
hostname: "nochange.example.com",
|
||||||
RegionKey: "us",
|
regionKey: "us",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
want: []regionalHostnameChange{
|
want: []regionalHostnameChange{
|
||||||
{
|
{
|
||||||
action: cloudFlareCreate,
|
action: cloudFlareCreate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
regionalHostname: regionalHostname{
|
||||||
Hostname: "create.example.com",
|
hostname: "create.example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: cloudFlareUpdate,
|
action: cloudFlareUpdate,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
regionalHostname: regionalHostname{
|
||||||
Hostname: "update.example.com",
|
hostname: "update.example.com",
|
||||||
RegionKey: "eu",
|
regionKey: "eu",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
action: cloudFlareDelete,
|
action: cloudFlareDelete,
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
regionalHostname: regionalHostname{
|
||||||
Hostname: "delete.example.com",
|
hostname: "delete.example.com",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -834,7 +841,7 @@ func TestApplyChangesWithRegionalHostnamesFaillures(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
type fields struct {
|
type fields struct {
|
||||||
Records map[string]cloudflare.DNSRecord
|
Records map[string]cloudflare.DNSRecord
|
||||||
RegionalHostnames []cloudflare.RegionalHostname
|
RegionalHostnames []regionalHostname
|
||||||
RegionKey string
|
RegionKey string
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
@ -869,7 +876,7 @@ func TestApplyChangesWithRegionalHostnamesFaillures(t *testing.T) {
|
|||||||
name: "create fails",
|
name: "create fails",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Records: map[string]cloudflare.DNSRecord{},
|
Records: map[string]cloudflare.DNSRecord{},
|
||||||
RegionalHostnames: []cloudflare.RegionalHostname{},
|
RegionalHostnames: []regionalHostname{},
|
||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
@ -899,8 +906,8 @@ func TestApplyChangesWithRegionalHostnamesFaillures(t *testing.T) {
|
|||||||
Content: "127.0.0.1",
|
Content: "127.0.0.1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RegionalHostnames: []cloudflare.RegionalHostname{
|
RegionalHostnames: []regionalHostname{
|
||||||
{Hostname: "rherror.bar.com", RegionKey: "us"},
|
{hostname: "rherror.bar.com", regionKey: "us"},
|
||||||
},
|
},
|
||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
@ -941,8 +948,8 @@ func TestApplyChangesWithRegionalHostnamesFaillures(t *testing.T) {
|
|||||||
Content: "127.0.0.1",
|
Content: "127.0.0.1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RegionalHostnames: []cloudflare.RegionalHostname{
|
RegionalHostnames: []regionalHostname{
|
||||||
{Hostname: "rherror.bar.com", RegionKey: "us"},
|
{hostname: "rherror.bar.com", regionKey: "us"},
|
||||||
},
|
},
|
||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
@ -964,7 +971,7 @@ func TestApplyChangesWithRegionalHostnamesFaillures(t *testing.T) {
|
|||||||
name: "conflicting regional keys",
|
name: "conflicting regional keys",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Records: map[string]cloudflare.DNSRecord{},
|
Records: map[string]cloudflare.DNSRecord{},
|
||||||
RegionalHostnames: []cloudflare.RegionalHostname{},
|
RegionalHostnames: []regionalHostname{},
|
||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
@ -1008,7 +1015,7 @@ func TestApplyChangesWithRegionalHostnamesFaillures(t *testing.T) {
|
|||||||
Records: map[string]map[string]cloudflare.DNSRecord{
|
Records: map[string]map[string]cloudflare.DNSRecord{
|
||||||
"001": records,
|
"001": records,
|
||||||
},
|
},
|
||||||
regionalHostnames: map[string][]cloudflare.RegionalHostname{
|
regionalHostnames: map[string][]regionalHostname{
|
||||||
"001": tt.fields.RegionalHostnames,
|
"001": tt.fields.RegionalHostnames,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -1034,7 +1041,7 @@ func TestApplyChangesWithRegionalHostnamesDryRun(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
type fields struct {
|
type fields struct {
|
||||||
Records map[string]cloudflare.DNSRecord
|
Records map[string]cloudflare.DNSRecord
|
||||||
RegionalHostnames []cloudflare.RegionalHostname
|
RegionalHostnames []regionalHostname
|
||||||
RegionKey string
|
RegionKey string
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
@ -1050,7 +1057,7 @@ func TestApplyChangesWithRegionalHostnamesDryRun(t *testing.T) {
|
|||||||
name: "create dry run",
|
name: "create dry run",
|
||||||
fields: fields{
|
fields: fields{
|
||||||
Records: map[string]cloudflare.DNSRecord{},
|
Records: map[string]cloudflare.DNSRecord{},
|
||||||
RegionalHostnames: []cloudflare.RegionalHostname{},
|
RegionalHostnames: []regionalHostname{},
|
||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
args: args{
|
args: args{
|
||||||
@ -1080,8 +1087,8 @@ func TestApplyChangesWithRegionalHostnamesDryRun(t *testing.T) {
|
|||||||
Content: "127.0.0.1",
|
Content: "127.0.0.1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RegionalHostnames: []cloudflare.RegionalHostname{
|
RegionalHostnames: []regionalHostname{
|
||||||
{Hostname: "foo.bar.com", RegionKey: "us"},
|
{hostname: "foo.bar.com", regionKey: "us"},
|
||||||
},
|
},
|
||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
@ -1122,8 +1129,8 @@ func TestApplyChangesWithRegionalHostnamesDryRun(t *testing.T) {
|
|||||||
Content: "127.0.0.1",
|
Content: "127.0.0.1",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
RegionalHostnames: []cloudflare.RegionalHostname{
|
RegionalHostnames: []regionalHostname{
|
||||||
{Hostname: "foo.bar.com", RegionKey: "us"},
|
{hostname: "foo.bar.com", regionKey: "us"},
|
||||||
},
|
},
|
||||||
RegionKey: "us",
|
RegionKey: "us",
|
||||||
},
|
},
|
||||||
@ -1157,7 +1164,7 @@ func TestApplyChangesWithRegionalHostnamesDryRun(t *testing.T) {
|
|||||||
Records: map[string]map[string]cloudflare.DNSRecord{
|
Records: map[string]map[string]cloudflare.DNSRecord{
|
||||||
"001": records,
|
"001": records,
|
||||||
},
|
},
|
||||||
regionalHostnames: map[string][]cloudflare.RegionalHostname{
|
regionalHostnames: map[string][]regionalHostname{
|
||||||
"001": tt.fields.RegionalHostnames,
|
"001": tt.fields.RegionalHostnames,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -48,7 +48,7 @@ type MockAction struct {
|
|||||||
ZoneId string
|
ZoneId string
|
||||||
RecordId string
|
RecordId string
|
||||||
RecordData cloudflare.DNSRecord
|
RecordData cloudflare.DNSRecord
|
||||||
RegionalHostname cloudflare.RegionalHostname
|
RegionalHostname regionalHostname
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockCloudFlareClient struct {
|
type mockCloudFlareClient struct {
|
||||||
@ -60,7 +60,7 @@ type mockCloudFlareClient struct {
|
|||||||
listZonesContextError error
|
listZonesContextError error
|
||||||
dnsRecordsError error
|
dnsRecordsError error
|
||||||
customHostnames map[string][]cloudflare.CustomHostname
|
customHostnames map[string][]cloudflare.CustomHostname
|
||||||
regionalHostnames map[string][]cloudflare.RegionalHostname
|
regionalHostnames map[string][]regionalHostname
|
||||||
}
|
}
|
||||||
|
|
||||||
var ExampleDomain = []cloudflare.DNSRecord{
|
var ExampleDomain = []cloudflare.DNSRecord{
|
||||||
@ -102,7 +102,7 @@ func NewMockCloudFlareClient() *mockCloudFlareClient {
|
|||||||
"002": {},
|
"002": {},
|
||||||
},
|
},
|
||||||
customHostnames: map[string][]cloudflare.CustomHostname{},
|
customHostnames: map[string][]cloudflare.CustomHostname{},
|
||||||
regionalHostnames: map[string][]cloudflare.RegionalHostname{},
|
regionalHostnames: map[string][]regionalHostname{},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1795,8 +1795,8 @@ func TestCloudFlareProvider_newCloudFlareChange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
change, _ := p.newCloudFlareChange(cloudFlareCreate, ep, ep.Targets[0], nil)
|
change, _ := p.newCloudFlareChange(cloudFlareCreate, ep, ep.Targets[0], nil)
|
||||||
if change.RegionalHostname.RegionKey != "us" {
|
if change.RegionalHostname.regionKey != "us" {
|
||||||
t.Errorf("expected region key to be 'us', but got '%s'", change.RegionalHostname.RegionKey)
|
t.Errorf("expected region key to be 'us', but got '%s'", change.RegionalHostname.regionKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
var freeValidCommentBuilder strings.Builder
|
var freeValidCommentBuilder strings.Builder
|
||||||
@ -1949,8 +1949,8 @@ func TestCloudFlareProvider_submitChangesCNAME(t *testing.T) {
|
|||||||
ID: "1234567890",
|
ID: "1234567890",
|
||||||
Content: "my-tunnel-guid-here.cfargotunnel.com",
|
Content: "my-tunnel-guid-here.cfargotunnel.com",
|
||||||
},
|
},
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "my-domain-here.app",
|
hostname: "my-domain-here.app",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1961,9 +1961,9 @@ func TestCloudFlareProvider_submitChangesCNAME(t *testing.T) {
|
|||||||
ID: "9876543210",
|
ID: "9876543210",
|
||||||
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
|
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
|
||||||
},
|
},
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "my-domain-here.app",
|
hostname: "my-domain-here.app",
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -2012,8 +2012,8 @@ func TestCloudFlareProvider_submitChangesApex(t *testing.T) {
|
|||||||
ID: "1234567890",
|
ID: "1234567890",
|
||||||
Content: "my-tunnel-guid-here.cfargotunnel.com",
|
Content: "my-tunnel-guid-here.cfargotunnel.com",
|
||||||
},
|
},
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "@", // APEX record
|
hostname: "@", // APEX record
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -2024,9 +2024,9 @@ func TestCloudFlareProvider_submitChangesApex(t *testing.T) {
|
|||||||
ID: "9876543210",
|
ID: "9876543210",
|
||||||
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
|
Content: "heritage=external-dns,external-dns/owner=default,external-dns/resource=service/external-dns/my-domain-here-app",
|
||||||
},
|
},
|
||||||
RegionalHostname: cloudflare.RegionalHostname{
|
RegionalHostname: regionalHostname{
|
||||||
Hostname: "@", // APEX record
|
hostname: "@", // APEX record
|
||||||
RegionKey: "",
|
regionKey: "",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user