Skip to content

Commit

Permalink
Merge pull request #827 from anandsinghkunwar/pdns-fix
Browse files Browse the repository at this point in the history
Fixed PowerDNS Domain Filter Bug
  • Loading branch information
k8s-ci-robot authored Feb 18, 2019
2 parents d0dc99f + adfe88a commit 623ecd0
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 2 deletions.
5 changes: 3 additions & 2 deletions provider/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import (
log "github.com/sirupsen/logrus"

"crypto/tls"
"net"

pgo "github.com/ffledgling/pdns-go"
"github.com/kubernetes-incubator/external-dns/endpoint"
"github.com/kubernetes-incubator/external-dns/pkg/tlsutils"
"github.com/kubernetes-incubator/external-dns/plan"
"net"
)

type pdnsChangeType string
Expand Down Expand Up @@ -175,7 +176,7 @@ func (c *PDNSAPIClient) PartitionZones(zones []pgo.Zone) (filteredZones []pgo.Zo
}
}
} else {
residualZones = zones
filteredZones = zones
}
return filteredZones, residualZones
}
Expand Down
84 changes: 84 additions & 0 deletions provider/pdns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package provider

import (
"context"
"errors"
//"fmt"
"net/http"
Expand Down Expand Up @@ -475,6 +476,44 @@ var (
},
},
}

DomainFilterListSingle = DomainFilter{
filters: []string{
"example.com",
},
}

DomainFilterListMultiple = DomainFilter{
filters: []string{
"example.com",
"mock.com",
},
}

DomainFilterListEmpty = DomainFilter{
filters: []string{},
}

DomainFilterEmptyClient = &PDNSAPIClient{
dryRun: false,
authCtx: context.WithValue(context.TODO(), pgo.ContextAPIKey, pgo.APIKey{Key: "TEST-API-KEY"}),
client: pgo.NewAPIClient(pgo.NewConfiguration()),
domainFilter: DomainFilterListEmpty,
}

DomainFilterSingleClient = &PDNSAPIClient{
dryRun: false,
authCtx: context.WithValue(context.TODO(), pgo.ContextAPIKey, pgo.APIKey{Key: "TEST-API-KEY"}),
client: pgo.NewAPIClient(pgo.NewConfiguration()),
domainFilter: DomainFilterListSingle,
}

DomainFilterMultipleClient = &PDNSAPIClient{
dryRun: false,
authCtx: context.WithValue(context.TODO(), pgo.ContextAPIKey, pgo.APIKey{Key: "TEST-API-KEY"}),
client: pgo.NewAPIClient(pgo.NewConfiguration()),
domainFilter: DomainFilterListMultiple,
}
)

/******************************************************************************/
Expand Down Expand Up @@ -912,6 +951,51 @@ func (suite *NewPDNSProviderTestSuite) TestPDNSmutateRecords() {

}

func (suite *NewPDNSProviderTestSuite) TestPDNSClientPartitionZones() {
zoneList := []pgo.Zone{
ZoneEmpty,
ZoneEmpty2,
}

partitionResultFilteredEmptyFilter := []pgo.Zone{
ZoneEmpty,
ZoneEmpty2,
}

partitionResultResidualEmptyFilter := ([]pgo.Zone)(nil)

partitionResultFilteredSingleFilter := []pgo.Zone{
ZoneEmpty,
}

partitionResultResidualSingleFilter := []pgo.Zone{
ZoneEmpty2,
}

partitionResultFilteredMultipleFilter := []pgo.Zone{
ZoneEmpty,
}

partitionResultResidualMultipleFilter := []pgo.Zone{
ZoneEmpty2,
}

// Check filtered, residual zones when no domain filter specified
filteredZones, residualZones := DomainFilterEmptyClient.PartitionZones(zoneList)
assert.Equal(suite.T(), partitionResultFilteredEmptyFilter, filteredZones)
assert.Equal(suite.T(), partitionResultResidualEmptyFilter, residualZones)

// Check filtered, residual zones when a single domain filter specified
filteredZones, residualZones = DomainFilterSingleClient.PartitionZones(zoneList)
assert.Equal(suite.T(), partitionResultFilteredSingleFilter, filteredZones)
assert.Equal(suite.T(), partitionResultResidualSingleFilter, residualZones)

// Check filtered, residual zones when a multiple domain filter specified
filteredZones, residualZones = DomainFilterMultipleClient.PartitionZones(zoneList)
assert.Equal(suite.T(), partitionResultFilteredMultipleFilter, filteredZones)
assert.Equal(suite.T(), partitionResultResidualMultipleFilter, residualZones)
}

func TestNewPDNSProviderTestSuite(t *testing.T) {
suite.Run(t, new(NewPDNSProviderTestSuite))
}

0 comments on commit 623ecd0

Please sign in to comment.