Skip to content

Commit

Permalink
Normalize IBMCloud provider-specific properties in AdjustEndpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
johngmyers committed Aug 4, 2023
1 parent 4a1f5c6 commit 4fb2c74
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 3 additions & 9 deletions provider/ibmcloud/ibmcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,22 +385,16 @@ func (p *IBMCloudProvider) ApplyChanges(ctx context.Context, changes *plan.Chang
return p.submitChanges(ctx, ibmcloudChanges)
}

func (p *IBMCloudProvider) PropertyValuesEqual(name string, previous string, current string) bool {
if name == proxyFilter {
return plan.CompareBoolean(p.proxiedByDefault, name, previous, current)
}

return p.BaseProvider.PropertyValuesEqual(name, previous, current)
}

// AdjustEndpoints modifies the endpoints as needed by the specific provider
func (p *IBMCloudProvider) AdjustEndpoints(endpoints []*endpoint.Endpoint) []*endpoint.Endpoint {
adjustedEndpoints := []*endpoint.Endpoint{}
for _, e := range endpoints {
log.Debugf("adjusting endpont: %v", *e)
if shouldBeProxied(e, p.proxiedByDefault) {
proxied := shouldBeProxied(e, p.proxiedByDefault)
if proxied {
e.RecordTTL = 0
}
e.SetProviderSpecificProperty(proxyFilter, strconv.FormatBool(proxied))

adjustedEndpoints = append(adjustedEndpoints, e)
}
Expand Down
12 changes: 7 additions & 5 deletions provider/ibmcloud/ibmcloud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func TestPrivate_ApplyChanges(t *testing.T) {
p := newTestIBMCloudProvider(true)

changes := plan.Changes{
Create: []*endpoint.Endpoint{
Create: p.AdjustEndpoints([]*endpoint.Endpoint{
{
DNSName: "newA.example.com",
RecordType: "A",
Expand All @@ -302,7 +302,7 @@ func TestPrivate_ApplyChanges(t *testing.T) {
RecordTTL: 240,
Targets: endpoint.NewTargets("\"heritage=external-dns,external-dns/owner=tower-pdns\""),
},
},
}),
UpdateOld: []*endpoint.Endpoint{
{
DNSName: "test.example.com",
Expand All @@ -311,14 +311,14 @@ func TestPrivate_ApplyChanges(t *testing.T) {
Targets: endpoint.NewTargets("1.2.3.4"),
},
},
UpdateNew: []*endpoint.Endpoint{
UpdateNew: p.AdjustEndpoints([]*endpoint.Endpoint{
{
DNSName: "test.example.com",
RecordType: "A",
RecordTTL: 180,
Targets: endpoint.NewTargets("1.2.3.4", "5.6.7.8"),
},
},
}),
Delete: []*endpoint.Endpoint{
{
DNSName: "test.example.com",
Expand Down Expand Up @@ -347,7 +347,7 @@ func TestAdjustEndpoints(t *testing.T) {
ProviderSpecific: endpoint.ProviderSpecific{
{
Name: "ibmcloud-proxied",
Value: "true",
Value: "1",
},
},
},
Expand All @@ -357,6 +357,8 @@ func TestAdjustEndpoints(t *testing.T) {

assert.Equal(t, endpoint.TTL(0), ep[0].RecordTTL)
assert.Equal(t, "test.example.com", ep[0].DNSName)
proxied, _ := ep[0].GetProviderSpecificProperty("ibmcloud-proxied")
assert.Equal(t, "true", proxied)
}

func TestPrivateZone_withFilterID(t *testing.T) {
Expand Down

0 comments on commit 4fb2c74

Please sign in to comment.