mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 17:46:57 +02:00
improve linter quality for external-dns
This commit is contained in:
parent
ec6e1e2fdc
commit
3388e3ddf1
@ -1,23 +1,81 @@
|
|||||||
run:
|
|
||||||
concurrency: 4
|
|
||||||
|
|
||||||
modules-download-mode: readonly
|
|
||||||
|
|
||||||
linters-settings:
|
linters-settings:
|
||||||
|
exhaustive:
|
||||||
|
default-signifies-exhaustive: false
|
||||||
|
goimports:
|
||||||
|
local-prefixes: github.com/kubernetes-sigs/external-dns
|
||||||
golint:
|
golint:
|
||||||
min-confidence: 0.9
|
min-confidence: 0.9
|
||||||
|
maligned:
|
||||||
gocyclo:
|
suggest-new: true
|
||||||
min-complexity: 15
|
misspell:
|
||||||
|
locale: US
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
|
# please, do not use `enable-all`: it's deprecated and will be removed soon.
|
||||||
|
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
|
||||||
disable-all: true
|
disable-all: true
|
||||||
enable:
|
enable:
|
||||||
|
- deadcode
|
||||||
|
- depguard
|
||||||
|
- dogsled
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- golint
|
||||||
|
- goprintffuncname
|
||||||
|
- gosimple
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- golint
|
|
||||||
- goimports
|
|
||||||
- misspell
|
|
||||||
- unconvert
|
|
||||||
- megacheck
|
|
||||||
- interfacer
|
- interfacer
|
||||||
|
- misspell
|
||||||
|
- rowserrcheck
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- stylecheck
|
||||||
|
- typecheck
|
||||||
|
- unconvert
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
- whitespace
|
||||||
|
|
||||||
|
issues:
|
||||||
|
# Excluding configuration per-path, per-linter, per-text and per-source
|
||||||
|
exclude-rules:
|
||||||
|
- path: _test\.go
|
||||||
|
linters:
|
||||||
|
- deadcode
|
||||||
|
- depguard
|
||||||
|
- dogsled
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
- golint
|
||||||
|
- goprintffuncname
|
||||||
|
- gosimple
|
||||||
|
- govet
|
||||||
|
- ineffassign
|
||||||
|
- interfacer
|
||||||
|
- misspell
|
||||||
|
- nolintlint
|
||||||
|
- rowserrcheck
|
||||||
|
- staticcheck
|
||||||
|
- structcheck
|
||||||
|
- stylecheck
|
||||||
|
- typecheck
|
||||||
|
- unconvert
|
||||||
|
- unused
|
||||||
|
- varcheck
|
||||||
|
- whitespace
|
||||||
|
|
||||||
|
|
||||||
|
#run:
|
||||||
|
# skip-dirs:
|
||||||
|
# - test/testdata_etc
|
||||||
|
# - internal/cache
|
||||||
|
# - internal/renameio
|
||||||
|
# - internal/robustio
|
||||||
|
|
||||||
|
# golangci.com configuration
|
||||||
|
# https://github.com/golangci/golangci/wiki/Configuration
|
||||||
|
#service:
|
||||||
|
# golangci-lint-version: 1.23.x # use the fixed version to not introduce new linters unexpectedly
|
||||||
|
# prepare:
|
||||||
|
# - echo "here I can run custom commands, but no preparation needed for this repo"
|
||||||
|
2
Makefile
2
Makefile
@ -31,7 +31,7 @@ cover-html: cover
|
|||||||
|
|
||||||
# Run all the linters
|
# Run all the linters
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run --timeout=5m ./...
|
golangci-lint run --timeout=15m ./...
|
||||||
|
|
||||||
|
|
||||||
# The verify target runs tasks similar to the CI tasks, but without code coverage
|
# The verify target runs tasks similar to the CI tasks, but without code coverage
|
||||||
|
@ -160,14 +160,14 @@ func (c *Controller) RunOnce(ctx context.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MIN_INTERVAL is used as window for batching events
|
// MinInterval is used as window for batching events
|
||||||
const MIN_INTERVAL = 5 * time.Second
|
const MinInterval = 5 * time.Second
|
||||||
|
|
||||||
// RunOnceThrottled makes sure execution happens at most once per interval.
|
// RunOnceThrottled makes sure execution happens at most once per interval.
|
||||||
func (c *Controller) ScheduleRunOnce(now time.Time) {
|
func (c *Controller) ScheduleRunOnce(now time.Time) {
|
||||||
c.nextRunAtMux.Lock()
|
c.nextRunAtMux.Lock()
|
||||||
defer c.nextRunAtMux.Unlock()
|
defer c.nextRunAtMux.Unlock()
|
||||||
c.nextRunAt = now.Add(MIN_INTERVAL)
|
c.nextRunAt = now.Add(MinInterval)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Controller) ShouldRunOnce(now time.Time) bool {
|
func (c *Controller) ShouldRunOnce(now time.Time) bool {
|
||||||
@ -180,7 +180,7 @@ func (c *Controller) ShouldRunOnce(now time.Time) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run runs RunOnce in a loop with a delay until context is cancelled
|
// Run runs RunOnce in a loop with a delay until context is canceled
|
||||||
func (c *Controller) Run(ctx context.Context) {
|
func (c *Controller) Run(ctx context.Context) {
|
||||||
ticker := time.NewTicker(time.Second)
|
ticker := time.NewTicker(time.Second)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
|
@ -174,8 +174,8 @@ func TestShouldRunOnce(t *testing.T) {
|
|||||||
assert.False(t, ctrl.ShouldRunOnce(now))
|
assert.False(t, ctrl.ShouldRunOnce(now))
|
||||||
assert.False(t, ctrl.ShouldRunOnce(now.Add(100*time.Microsecond)))
|
assert.False(t, ctrl.ShouldRunOnce(now.Add(100*time.Microsecond)))
|
||||||
|
|
||||||
// But after MIN_INTERVAL we should run reconciliation
|
// But after MinInterval we should run reconciliation
|
||||||
now = now.Add(MIN_INTERVAL)
|
now = now.Add(MinInterval)
|
||||||
assert.True(t, ctrl.ShouldRunOnce(now))
|
assert.True(t, ctrl.ShouldRunOnce(now))
|
||||||
|
|
||||||
// But just one time
|
// But just one time
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
// FAST_POLL used for fast testing
|
// FastPoll used for fast testing
|
||||||
var FAST_POLL = false
|
var FastPoll = false
|
||||||
|
@ -39,7 +39,6 @@ func (b byAllFields) Less(i, j int) bool {
|
|||||||
return b[i].RecordType <= b[j].RecordType
|
return b[i].RecordType <= b[j].RecordType
|
||||||
}
|
}
|
||||||
return b[i].Targets.String() <= b[j].Targets.String()
|
return b[i].Targets.String() <= b[j].Targets.String()
|
||||||
|
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
config.FAST_POLL = true
|
config.FastPoll = true
|
||||||
if os.Getenv("DEBUG") == "" {
|
if os.Getenv("DEBUG") == "" {
|
||||||
logrus.SetOutput(ioutil.Discard)
|
logrus.SetOutput(ioutil.Discard)
|
||||||
log.SetOutput(ioutil.Discard)
|
log.SetOutput(ioutil.Discard)
|
||||||
|
@ -293,7 +293,6 @@ func (p *AkamaiProvider) newAkamaiRecord(dnsName, recordType string, targets ...
|
|||||||
|
|
||||||
func (p *AkamaiProvider) createRecords(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoint.Endpoint) (created []*endpoint.Endpoint, failed []*endpoint.Endpoint) {
|
func (p *AkamaiProvider) createRecords(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoint.Endpoint) (created []*endpoint.Endpoint, failed []*endpoint.Endpoint) {
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
|
|
||||||
if !p.domainFilter.Match(endpoint.DNSName) {
|
if !p.domainFilter.Match(endpoint.DNSName) {
|
||||||
log.Debugf("Skipping creation at Akamai of endpoint DNSName: '%s' RecordType: '%s', it does not match against Domain filters", endpoint.DNSName, endpoint.RecordType)
|
log.Debugf("Skipping creation at Akamai of endpoint DNSName: '%s' RecordType: '%s', it does not match against Domain filters", endpoint.DNSName, endpoint.RecordType)
|
||||||
continue
|
continue
|
||||||
@ -324,7 +323,6 @@ func (p *AkamaiProvider) createRecords(zoneNameIDMapper provider.ZoneIDName, end
|
|||||||
|
|
||||||
func (p *AkamaiProvider) deleteRecords(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoint.Endpoint) (deleted []*endpoint.Endpoint, failed []*endpoint.Endpoint) {
|
func (p *AkamaiProvider) deleteRecords(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoint.Endpoint) (deleted []*endpoint.Endpoint, failed []*endpoint.Endpoint) {
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
|
|
||||||
if !p.domainFilter.Match(endpoint.DNSName) {
|
if !p.domainFilter.Match(endpoint.DNSName) {
|
||||||
log.Debugf("Skipping deletion at Akamai of endpoint: '%s' type: '%s', it does not match against Domain filters", endpoint.DNSName, endpoint.RecordType)
|
log.Debugf("Skipping deletion at Akamai of endpoint: '%s' type: '%s', it does not match against Domain filters", endpoint.DNSName, endpoint.RecordType)
|
||||||
continue
|
continue
|
||||||
@ -353,7 +351,6 @@ func (p *AkamaiProvider) deleteRecords(zoneNameIDMapper provider.ZoneIDName, end
|
|||||||
|
|
||||||
func (p *AkamaiProvider) updateNewRecords(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoint.Endpoint) (updated []*endpoint.Endpoint, failed []*endpoint.Endpoint) {
|
func (p *AkamaiProvider) updateNewRecords(zoneNameIDMapper provider.ZoneIDName, endpoints []*endpoint.Endpoint) (updated []*endpoint.Endpoint, failed []*endpoint.Endpoint) {
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
|
|
||||||
if !p.domainFilter.Match(endpoint.DNSName) {
|
if !p.domainFilter.Match(endpoint.DNSName) {
|
||||||
log.Debugf("Skipping update at Akamai of endpoint DNSName: '%s' RecordType: '%s', it does not match against Domain filters", endpoint.DNSName, endpoint.RecordType)
|
log.Debugf("Skipping update at Akamai of endpoint DNSName: '%s' RecordType: '%s', it does not match against Domain filters", endpoint.DNSName, endpoint.RecordType)
|
||||||
continue
|
continue
|
||||||
|
@ -100,17 +100,17 @@ func NewAlibabaCloudProvider(configFile string, domainFilter endpoint.DomainFilt
|
|||||||
if configFile != "" {
|
if configFile != "" {
|
||||||
contents, err := ioutil.ReadFile(configFile)
|
contents, err := ioutil.ReadFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to read Alibaba Cloud config file '%s': %v", configFile, err)
|
return nil, fmt.Errorf("failed to read Alibaba Cloud config file '%s': %v", configFile, err)
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal(contents, &cfg)
|
err = yaml.Unmarshal(contents, &cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to parse Alibaba Cloud config file '%s': %v", configFile, err)
|
return nil, fmt.Errorf("failed to parse Alibaba Cloud config file '%s': %v", configFile, err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var tmpError error
|
var tmpError error
|
||||||
cfg, tmpError = getCloudConfigFromStsToken()
|
cfg, tmpError = getCloudConfigFromStsToken()
|
||||||
if tmpError != nil {
|
if tmpError != nil {
|
||||||
return nil, fmt.Errorf("Failed to getCloudConfigFromStsToken: %v", tmpError)
|
return nil, fmt.Errorf("failed to getCloudConfigFromStsToken: %v", tmpError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,19 +182,19 @@ func getCloudConfigFromStsToken() (alibabaCloudConfig, error) {
|
|||||||
roleName := ""
|
roleName := ""
|
||||||
var err error
|
var err error
|
||||||
if roleName, err = m.RoleName(); err != nil {
|
if roleName, err = m.RoleName(); err != nil {
|
||||||
return cfg, fmt.Errorf("Failed to get role name from Metadata Service: %v", err)
|
return cfg, fmt.Errorf("failed to get role name from Metadata Service: %v", err)
|
||||||
}
|
}
|
||||||
vpcID, err := m.VpcID()
|
vpcID, err := m.VpcID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, fmt.Errorf("Failed to get VPC ID from Metadata Service: %v", err)
|
return cfg, fmt.Errorf("failed to get VPC ID from Metadata Service: %v", err)
|
||||||
}
|
}
|
||||||
regionID, err := m.Region()
|
regionID, err := m.Region()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, fmt.Errorf("Failed to get Region ID from Metadata Service: %v", err)
|
return cfg, fmt.Errorf("failed to get Region ID from Metadata Service: %v", err)
|
||||||
}
|
}
|
||||||
role, err := m.RamRoleToken(roleName)
|
role, err := m.RamRoleToken(roleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cfg, fmt.Errorf("Failed to get STS Token from Metadata Service: %v", err)
|
return cfg, fmt.Errorf("failed to get STS Token from Metadata Service: %v", err)
|
||||||
}
|
}
|
||||||
cfg.RegionID = regionID
|
cfg.RegionID = regionID
|
||||||
cfg.RoleName = roleName
|
cfg.RoleName = roleName
|
||||||
@ -317,7 +317,6 @@ func (p *AlibabaCloudProvider) getDNSName(rr, domain string) string {
|
|||||||
//
|
//
|
||||||
// Returns the current records or an error if the operation failed.
|
// Returns the current records or an error if the operation failed.
|
||||||
func (p *AlibabaCloudProvider) recordsForDNS() (endpoints []*endpoint.Endpoint, _ error) {
|
func (p *AlibabaCloudProvider) recordsForDNS() (endpoints []*endpoint.Endpoint, _ error) {
|
||||||
|
|
||||||
records, err := p.records()
|
records, err := p.records()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -346,7 +345,6 @@ func (p *AlibabaCloudProvider) recordsForDNS() (endpoints []*endpoint.Endpoint,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getNextPageNumber(pageNumber, pageSize, totalCount int) int {
|
func getNextPageNumber(pageNumber, pageSize, totalCount int) int {
|
||||||
|
|
||||||
if pageNumber*pageSize >= totalCount {
|
if pageNumber*pageSize >= totalCount {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
@ -365,18 +363,13 @@ func (p *AlibabaCloudProvider) getRecordKeyByEndpoint(endpoint *endpoint.Endpoin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlibabaCloudProvider) groupRecords(records []alidns.Record) (endpointMap map[string][]alidns.Record) {
|
func (p *AlibabaCloudProvider) groupRecords(records []alidns.Record) (endpointMap map[string][]alidns.Record) {
|
||||||
|
|
||||||
endpointMap = make(map[string][]alidns.Record)
|
endpointMap = make(map[string][]alidns.Record)
|
||||||
|
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
|
|
||||||
key := p.getRecordKey(record)
|
key := p.getRecordKey(record)
|
||||||
|
|
||||||
recordList := endpointMap[key]
|
recordList := endpointMap[key]
|
||||||
endpointMap[key] = append(recordList, record)
|
endpointMap[key] = append(recordList, record)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return endpointMap
|
return endpointMap
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,18 +444,15 @@ func (p *AlibabaCloudProvider) getDomainRecords(domainName string) ([]alidns.Rec
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, record := range response.DomainRecords.Record {
|
for _, record := range response.DomainRecords.Record {
|
||||||
|
|
||||||
domainName := record.DomainName
|
domainName := record.DomainName
|
||||||
recordType := record.Type
|
recordType := record.Type
|
||||||
|
|
||||||
if !p.domainFilter.Match(domainName) {
|
if !p.domainFilter.Match(domainName) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !provider.SupportedRecordType(recordType) {
|
if !provider.SupportedRecordType(recordType) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO filter Locked record
|
//TODO filter Locked record
|
||||||
results = append(results, record)
|
results = append(results, record)
|
||||||
}
|
}
|
||||||
@ -624,7 +614,6 @@ func (p *AlibabaCloudProvider) equals(record alidns.Record, endpoint *endpoint.E
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlibabaCloudProvider) updateRecords(recordMap map[string][]alidns.Record, endpoints []*endpoint.Endpoint) error {
|
func (p *AlibabaCloudProvider) updateRecords(recordMap map[string][]alidns.Record, endpoints []*endpoint.Endpoint) error {
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
key := p.getRecordKeyByEndpoint(endpoint)
|
key := p.getRecordKeyByEndpoint(endpoint)
|
||||||
records := recordMap[key]
|
records := recordMap[key]
|
||||||
@ -669,7 +658,6 @@ func (p *AlibabaCloudProvider) updateRecords(recordMap map[string][]alidns.Recor
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlibabaCloudProvider) splitDNSName(endpoint *endpoint.Endpoint) (rr string, domain string) {
|
func (p *AlibabaCloudProvider) splitDNSName(endpoint *endpoint.Endpoint) (rr string, domain string) {
|
||||||
|
|
||||||
name := strings.TrimSuffix(endpoint.DNSName, ".")
|
name := strings.TrimSuffix(endpoint.DNSName, ".")
|
||||||
|
|
||||||
found := false
|
found := false
|
||||||
@ -729,7 +717,6 @@ func (p *AlibabaCloudProvider) matchVPC(zoneID string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlibabaCloudProvider) privateZones() ([]pvtz.Zone, error) {
|
func (p *AlibabaCloudProvider) privateZones() ([]pvtz.Zone, error) {
|
||||||
|
|
||||||
var zones []pvtz.Zone
|
var zones []pvtz.Zone
|
||||||
|
|
||||||
request := pvtz.CreateDescribeZonesRequest()
|
request := pvtz.CreateDescribeZonesRequest()
|
||||||
@ -784,7 +771,6 @@ func (p *AlibabaCloudProvider) getPrivateZones() (map[string]*alibabaPrivateZone
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, zone := range zones {
|
for _, zone := range zones {
|
||||||
|
|
||||||
request := pvtz.CreateDescribeZoneRecordsRequest()
|
request := pvtz.CreateDescribeZoneRecordsRequest()
|
||||||
request.ZoneId = zone.ZoneId
|
request.ZoneId = zone.ZoneId
|
||||||
request.PageSize = requests.NewInteger(defaultAlibabaCloudPageSize)
|
request.PageSize = requests.NewInteger(defaultAlibabaCloudPageSize)
|
||||||
@ -801,7 +787,6 @@ func (p *AlibabaCloudProvider) getPrivateZones() (map[string]*alibabaPrivateZone
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, record := range response.Records.Record {
|
for _, record := range response.Records.Record {
|
||||||
|
|
||||||
recordType := record.Type
|
recordType := record.Type
|
||||||
|
|
||||||
if !provider.SupportedRecordType(recordType) {
|
if !provider.SupportedRecordType(recordType) {
|
||||||
@ -831,7 +816,6 @@ func (p *AlibabaCloudProvider) getPrivateZones() (map[string]*alibabaPrivateZone
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlibabaCloudProvider) groupPrivateZoneRecords(zone *alibabaPrivateZone) (endpointMap map[string][]pvtz.Record) {
|
func (p *AlibabaCloudProvider) groupPrivateZoneRecords(zone *alibabaPrivateZone) (endpointMap map[string][]pvtz.Record) {
|
||||||
|
|
||||||
endpointMap = make(map[string][]pvtz.Record)
|
endpointMap = make(map[string][]pvtz.Record)
|
||||||
|
|
||||||
for _, record := range zone.records {
|
for _, record := range zone.records {
|
||||||
@ -847,7 +831,6 @@ func (p *AlibabaCloudProvider) groupPrivateZoneRecords(zone *alibabaPrivateZone)
|
|||||||
//
|
//
|
||||||
// Returns the current records or an error if the operation failed.
|
// Returns the current records or an error if the operation failed.
|
||||||
func (p *AlibabaCloudProvider) privateZoneRecords() (endpoints []*endpoint.Endpoint, _ error) {
|
func (p *AlibabaCloudProvider) privateZoneRecords() (endpoints []*endpoint.Endpoint, _ error) {
|
||||||
|
|
||||||
zones, err := p.getPrivateZones()
|
zones, err := p.getPrivateZones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -881,7 +864,7 @@ func (p *AlibabaCloudProvider) createPrivateZoneRecord(zones map[string]*alibaba
|
|||||||
rr, domain := p.splitDNSName(endpoint)
|
rr, domain := p.splitDNSName(endpoint)
|
||||||
zone := zones[domain]
|
zone := zones[domain]
|
||||||
if zone == nil {
|
if zone == nil {
|
||||||
err := fmt.Errorf("Failed to find private zone '%s'", domain)
|
err := fmt.Errorf("failed to find private zone '%s'", domain)
|
||||||
log.Errorf("Failed to create %s record named '%s' to '%s' for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, target, err)
|
log.Errorf("Failed to create %s record named '%s' to '%s' for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, target, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -912,7 +895,7 @@ func (p *AlibabaCloudProvider) createPrivateZoneRecord(zones map[string]*alibaba
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
log.Infof("Create %s record named '%s' to '%s' with ttl %d for Alibaba Cloud Private Zone: Record ID=%d", endpoint.RecordType, endpoint.DNSName, target, ttl, response.RecordId)
|
log.Infof("Create %s record named '%s' to '%s' with ttl %d for Alibaba Cloud Private Zone: Record ID=%d", endpoint.RecordType, endpoint.DNSName, target, ttl, response.RecordId)
|
||||||
} else {
|
} else {
|
||||||
log.Errorf("Failed to create %s record named '%s' to '%s' with ttl %d for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, target, ttl, err)
|
log.Errorf("failed to create %s record named '%s' to '%s' with ttl %d for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, target, ttl, err)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -927,7 +910,6 @@ func (p *AlibabaCloudProvider) createPrivateZoneRecords(zones map[string]*alibab
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlibabaCloudProvider) deletePrivateZoneRecord(recordID int) error {
|
func (p *AlibabaCloudProvider) deletePrivateZoneRecord(recordID int) error {
|
||||||
|
|
||||||
if p.dryRun {
|
if p.dryRun {
|
||||||
log.Infof("Dry run: Delete record id '%d' in Alibaba Cloud Private Zone", recordID)
|
log.Infof("Dry run: Delete record id '%d' in Alibaba Cloud Private Zone", recordID)
|
||||||
}
|
}
|
||||||
@ -951,7 +933,7 @@ func (p *AlibabaCloudProvider) deletePrivateZoneRecords(zones map[string]*alibab
|
|||||||
|
|
||||||
zone := zones[domain]
|
zone := zones[domain]
|
||||||
if zone == nil {
|
if zone == nil {
|
||||||
err := fmt.Errorf("Failed to find private zone '%s'", domain)
|
err := fmt.Errorf("failed to find private zone '%s'", domain)
|
||||||
log.Errorf("Failed to delete %s record named '%s' for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, err)
|
log.Errorf("Failed to delete %s record named '%s' for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -1035,12 +1017,11 @@ func (p *AlibabaCloudProvider) equalsPrivateZone(record pvtz.Record, endpoint *e
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *AlibabaCloudProvider) updatePrivateZoneRecords(zones map[string]*alibabaPrivateZone, endpoints []*endpoint.Endpoint) error {
|
func (p *AlibabaCloudProvider) updatePrivateZoneRecords(zones map[string]*alibabaPrivateZone, endpoints []*endpoint.Endpoint) error {
|
||||||
|
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
rr, domain := p.splitDNSName(endpoint)
|
rr, domain := p.splitDNSName(endpoint)
|
||||||
zone := zones[domain]
|
zone := zones[domain]
|
||||||
if zone == nil {
|
if zone == nil {
|
||||||
err := fmt.Errorf("Failed to find private zone '%s'", domain)
|
err := fmt.Errorf("failed to find private zone '%s'", domain)
|
||||||
log.Errorf("Failed to update %s record named '%s' for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, err)
|
log.Errorf("Failed to update %s record named '%s' for Alibaba Cloud Private Zone: %v", endpoint.RecordType, endpoint.DNSName, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -433,7 +433,7 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes []*route53.Chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
if _, err := p.client.ChangeResourceRecordSetsWithContext(ctx, params); err != nil {
|
if _, err := p.client.ChangeResourceRecordSetsWithContext(ctx, params); err != nil {
|
||||||
log.Errorf("Failure in zone %s [Id: %s]", aws.StringValue(zones[z].Name), z)
|
log.Errorf("failure in zone %s [Id: %s]", aws.StringValue(zones[z].Name), z)
|
||||||
log.Error(err) //TODO(ideahitme): consider changing the interface in cases when this error might be a concern for other components
|
log.Error(err) //TODO(ideahitme): consider changing the interface in cases when this error might be a concern for other components
|
||||||
failedUpdate = true
|
failedUpdate = true
|
||||||
} else {
|
} else {
|
||||||
@ -453,7 +453,7 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes []*route53.Chan
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(failedZones) > 0 {
|
if len(failedZones) > 0 {
|
||||||
return fmt.Errorf("Failed to submit all changes for the following zones: %v", failedZones)
|
return fmt.Errorf("failed to submit all changes for the following zones: %v", failedZones)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -737,7 +737,6 @@ func isAWSAlias(ep *endpoint.Endpoint, addrs []*endpoint.Endpoint) string {
|
|||||||
if hostedZone := canonicalHostedZone(addr.Targets[0]); hostedZone != "" {
|
if hostedZone := canonicalHostedZone(addr.Targets[0]); hostedZone != "" {
|
||||||
return hostedZone
|
return hostedZone
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ type Service struct {
|
|||||||
// answer.
|
// answer.
|
||||||
Group string `json:"group,omitempty"`
|
Group string `json:"group,omitempty"`
|
||||||
|
|
||||||
// Etcd key where we found this service and ignored from json un-/marshalling
|
// Etcd key where we found this service and ignored from json un-/marshaling
|
||||||
Key string `json:"-"`
|
Key string `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,7 +397,6 @@ func (p coreDNSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
index := 0
|
index := 0
|
||||||
for _, ep := range group {
|
for _, ep := range group {
|
||||||
|
@ -62,7 +62,7 @@ type DigitalOceanChange struct {
|
|||||||
func NewDigitalOceanProvider(ctx context.Context, domainFilter endpoint.DomainFilter, dryRun bool) (*DigitalOceanProvider, error) {
|
func NewDigitalOceanProvider(ctx context.Context, domainFilter endpoint.DomainFilter, dryRun bool) (*DigitalOceanProvider, error) {
|
||||||
token, ok := os.LookupEnv("DO_TOKEN")
|
token, ok := os.LookupEnv("DO_TOKEN")
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("No token found")
|
return nil, fmt.Errorf("no token found")
|
||||||
}
|
}
|
||||||
oauthClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{
|
oauthClient := oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{
|
||||||
AccessToken: token,
|
AccessToken: token,
|
||||||
|
@ -101,7 +101,7 @@ const (
|
|||||||
func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) {
|
func NewDnsimpleProvider(domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (provider.Provider, error) {
|
||||||
oauthToken := os.Getenv("DNSIMPLE_OAUTH")
|
oauthToken := os.Getenv("DNSIMPLE_OAUTH")
|
||||||
if len(oauthToken) == 0 {
|
if len(oauthToken) == 0 {
|
||||||
return nil, fmt.Errorf("No dnsimple oauth token provided")
|
return nil, fmt.Errorf("no dnsimple oauth token provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: oauthToken})
|
ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: oauthToken})
|
||||||
@ -319,7 +319,7 @@ func (p *dnsimpleProvider) GetRecordID(ctx context.Context, zone string, recordN
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, fmt.Errorf("No record id found")
|
return 0, fmt.Errorf("no record id found")
|
||||||
}
|
}
|
||||||
|
|
||||||
// dnsimpleSuitableZone returns the most suitable zone for a given hostname and a set of zones.
|
// dnsimpleSuitableZone returns the most suitable zone for a given hostname and a set of zones.
|
||||||
|
@ -158,7 +158,6 @@ func NewDynProvider(config DynConfig) (provider.Provider, error) {
|
|||||||
func filterAndFixLinks(links []string, filter endpoint.DomainFilter) []string {
|
func filterAndFixLinks(links []string, filter endpoint.DomainFilter) []string {
|
||||||
var result []string
|
var result []string
|
||||||
for _, link := range links {
|
for _, link := range links {
|
||||||
|
|
||||||
// link looks like /REST/CNAMERecord/acme.com/exchange.acme.com/349386875
|
// link looks like /REST/CNAMERecord/acme.com/exchange.acme.com/349386875
|
||||||
|
|
||||||
// strip /REST/
|
// strip /REST/
|
||||||
@ -292,7 +291,6 @@ func (d *dynProviderState) allRecordsToEndpoints(records *dynectsoap.GetAllRecor
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func errorOrValue(err error, value interface{}) interface{} {
|
func errorOrValue(err error, value interface{}) interface{} {
|
||||||
@ -394,7 +392,6 @@ func (d *dynProviderState) fetchAllRecordsInZone(zone string) (*dynectsoap.GetAl
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &records, nil
|
return &records, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildLinkToRecord build a resource link. The symmetry of the dyn API is used to save
|
// buildLinkToRecord build a resource link. The symmetry of the dyn API is used to save
|
||||||
@ -570,7 +567,7 @@ func (d *dynProviderState) commit(client *dynect.Client) error {
|
|||||||
case 1:
|
case 1:
|
||||||
return errs[0]
|
return errs[0]
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Multiple errors committing: %+v", errs)
|
return fmt.Errorf("multiple errors committing: %+v", errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,7 +678,7 @@ func (d *dynProviderState) ApplyChanges(ctx context.Context, changes *plan.Chang
|
|||||||
case 1:
|
case 1:
|
||||||
return errs[0]
|
return errs[0]
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Multiple errors committing: %+v", errs)
|
return fmt.Errorf("multiple errors committing: %+v", errs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if needsCommit {
|
if needsCommit {
|
||||||
|
@ -447,7 +447,6 @@ func (p *LinodeProvider) ApplyChanges(ctx context.Context, changes *plan.Changes
|
|||||||
DomainRecord: record,
|
DomainRecord: record,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +152,6 @@ func (p *NS1Provider) Records(ctx context.Context) ([]*endpoint.Endpoint, error)
|
|||||||
var endpoints []*endpoint.Endpoint
|
var endpoints []*endpoint.Endpoint
|
||||||
|
|
||||||
for _, zone := range zones {
|
for _, zone := range zones {
|
||||||
|
|
||||||
// TODO handle Header Codes
|
// TODO handle Header Codes
|
||||||
zoneData, _, err := p.client.GetZone(zone.String())
|
zoneData, _, err := p.client.GetZone(zone.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -84,7 +84,7 @@ func LoadOCIConfig(path string) (*OCIConfig, error) {
|
|||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewOCIProvider initialises a new OCI DNS based Provider.
|
// NewOCIProvider initializes a new OCI DNS based Provider.
|
||||||
func NewOCIProvider(cfg OCIConfig, domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (*OCIProvider, error) {
|
func NewOCIProvider(cfg OCIConfig, domainFilter endpoint.DomainFilter, zoneIDFilter provider.ZoneIDFilter, dryRun bool) (*OCIProvider, error) {
|
||||||
var client ociDNSClient
|
var client ociDNSClient
|
||||||
client, err := dns.NewDnsClientWithConfigurationProvider(common.NewRawConfigurationProvider(
|
client, err := dns.NewDnsClientWithConfigurationProvider(common.NewRawConfigurationProvider(
|
||||||
@ -96,7 +96,7 @@ func NewOCIProvider(cfg OCIConfig, domainFilter endpoint.DomainFilter, zoneIDFil
|
|||||||
&cfg.Auth.Passphrase,
|
&cfg.Auth.Passphrase,
|
||||||
))
|
))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "initialising OCI DNS API client")
|
return nil, errors.Wrap(err, "initializing OCI DNS API client")
|
||||||
}
|
}
|
||||||
|
|
||||||
return &OCIProvider{
|
return &OCIProvider{
|
||||||
|
@ -97,7 +97,6 @@ func NewOVHProvider(ctx context.Context, domainFilter endpoint.DomainFilter, end
|
|||||||
|
|
||||||
// Records returns the list of records in all relevant zones.
|
// Records returns the list of records in all relevant zones.
|
||||||
func (p *OVHProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) {
|
func (p *OVHProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) {
|
||||||
|
|
||||||
_, records, err := p.zonesRecords(ctx)
|
_, records, err := p.zonesRecords(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -117,7 +117,6 @@ func (tlsConfig *TLSConfig) setHTTPClient(pdnsClientConfig *pgo.Configuration) e
|
|||||||
|
|
||||||
// Function for debug printing
|
// Function for debug printing
|
||||||
func stringifyHTTPResponseBody(r *http.Response) (body string) {
|
func stringifyHTTPResponseBody(r *http.Response) (body string) {
|
||||||
|
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@ -126,7 +125,6 @@ func stringifyHTTPResponseBody(r *http.Response) (body string) {
|
|||||||
buf.ReadFrom(r.Body)
|
buf.ReadFrom(r.Body)
|
||||||
body = buf.String()
|
body = buf.String()
|
||||||
return body
|
return body
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PDNSAPIProvider : Interface used and extended by the PDNSAPIClient struct as
|
// PDNSAPIProvider : Interface used and extended by the PDNSAPIClient struct as
|
||||||
@ -162,7 +160,6 @@ func (c *PDNSAPIClient) ListZones() (zones []pgo.Zone, resp *http.Response, err
|
|||||||
|
|
||||||
log.Errorf("Unable to fetch zones. %v", err)
|
log.Errorf("Unable to fetch zones. %v", err)
|
||||||
return zones, resp, err
|
return zones, resp, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PartitionZones : Method returns a slice of zones that adhere to the domain filter and a slice of ones that does not adhere to the filter
|
// PartitionZones : Method returns a slice of zones that adhere to the domain filter and a slice of ones that does not adhere to the filter
|
||||||
@ -191,14 +188,12 @@ func (c *PDNSAPIClient) ListZone(zoneID string) (zone pgo.Zone, resp *http.Respo
|
|||||||
log.Debugf("Retrying ListZone() ... %d", i)
|
log.Debugf("Retrying ListZone() ... %d", i)
|
||||||
time.Sleep(retryAfterTime * (1 << uint(i)))
|
time.Sleep(retryAfterTime * (1 << uint(i)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
}
|
}
|
||||||
return zone, resp, err
|
return zone, resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Errorf("Unable to list zone. %v", err)
|
log.Errorf("Unable to list zone. %v", err)
|
||||||
return zone, resp, err
|
return zone, resp, err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PatchZone : Method used to update the contents of a particular zone from PowerDNS
|
// PatchZone : Method used to update the contents of a particular zone from PowerDNS
|
||||||
@ -211,7 +206,6 @@ func (c *PDNSAPIClient) PatchZone(zoneID string, zoneStruct pgo.Zone) (resp *htt
|
|||||||
log.Debugf("Retrying PatchZone() ... %d", i)
|
log.Debugf("Retrying PatchZone() ... %d", i)
|
||||||
time.Sleep(retryAfterTime * (1 << uint(i)))
|
time.Sleep(retryAfterTime * (1 << uint(i)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
}
|
}
|
||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
@ -228,11 +222,10 @@ type PDNSProvider struct {
|
|||||||
|
|
||||||
// NewPDNSProvider initializes a new PowerDNS based Provider.
|
// NewPDNSProvider initializes a new PowerDNS based Provider.
|
||||||
func NewPDNSProvider(ctx context.Context, config PDNSConfig) (*PDNSProvider, error) {
|
func NewPDNSProvider(ctx context.Context, config PDNSConfig) (*PDNSProvider, error) {
|
||||||
|
|
||||||
// Do some input validation
|
// Do some input validation
|
||||||
|
|
||||||
if config.APIKey == "" {
|
if config.APIKey == "" {
|
||||||
return nil, errors.New("Missing API Key for PDNS. Specify using --pdns-api-key=")
|
return nil, errors.New("missing API Key for PDNS. Specify using --pdns-api-key=")
|
||||||
}
|
}
|
||||||
|
|
||||||
// We do not support dry running, exit safely instead of surprising the user
|
// We do not support dry running, exit safely instead of surprising the user
|
||||||
@ -259,7 +252,6 @@ func NewPDNSProvider(ctx context.Context, config PDNSConfig) (*PDNSProvider, err
|
|||||||
domainFilter: config.DomainFilter,
|
domainFilter: config.DomainFilter,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return provider, nil
|
return provider, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,13 +264,11 @@ func (p *PDNSProvider) convertRRSetToEndpoints(rr pgo.RrSet) (endpoints []*endpo
|
|||||||
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(rr.Name, rr.Type_, endpoint.TTL(rr.Ttl), record.Content))
|
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(rr.Name, rr.Type_, endpoint.TTL(rr.Ttl), record.Content))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return endpoints, nil
|
return endpoints, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertEndpointsToZones marshals endpoints into pdns compatible Zone structs
|
// ConvertEndpointsToZones marshals endpoints into pdns compatible Zone structs
|
||||||
func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changetype pdnsChangeType) (zonelist []pgo.Zone, _ error) {
|
func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changetype pdnsChangeType) (zonelist []pgo.Zone, _ error) {
|
||||||
|
|
||||||
zonelist = []pgo.Zone{}
|
zonelist = []pgo.Zone{}
|
||||||
endpoints := make([]*endpoint.Endpoint, len(eps))
|
endpoints := make([]*endpoint.Endpoint, len(eps))
|
||||||
copy(endpoints, eps)
|
copy(endpoints, eps)
|
||||||
@ -319,7 +309,7 @@ func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changet
|
|||||||
// external-dns v5.0.0-alpha onwards
|
// external-dns v5.0.0-alpha onwards
|
||||||
records := []pgo.Record{}
|
records := []pgo.Record{}
|
||||||
for _, t := range ep.Targets {
|
for _, t := range ep.Targets {
|
||||||
if "CNAME" == ep.RecordType {
|
if ep.RecordType == "CNAME" {
|
||||||
t = provider.EnsureTrailingDot(t)
|
t = provider.EnsureTrailingDot(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +325,7 @@ func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changet
|
|||||||
// DELETEs explicitly forbid a TTL, therefore only PATCHes need the TTL
|
// DELETEs explicitly forbid a TTL, therefore only PATCHes need the TTL
|
||||||
if changetype == PdnsReplace {
|
if changetype == PdnsReplace {
|
||||||
if int64(ep.RecordTTL) > int64(math.MaxInt32) {
|
if int64(ep.RecordTTL) > int64(math.MaxInt32) {
|
||||||
return nil, errors.New("Value of record TTL overflows, limited to int32")
|
return nil, errors.New("value of record TTL overflows, limited to int32")
|
||||||
}
|
}
|
||||||
if ep.RecordTTL == 0 {
|
if ep.RecordTTL == 0 {
|
||||||
// No TTL was specified for the record, we use the default
|
// No TTL was specified for the record, we use the default
|
||||||
@ -353,13 +343,10 @@ func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changet
|
|||||||
// If we didn't pop anything, we move to the next item in the list
|
// If we didn't pop anything, we move to the next item in the list
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(zone.Rrsets) > 0 {
|
if len(zone.Rrsets) > 0 {
|
||||||
zonelist = append(zonelist, zone)
|
zonelist = append(zonelist, zone)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// residualZones is unsorted by name length like its counterpart
|
// residualZones is unsorted by name length like its counterpart
|
||||||
@ -377,7 +364,6 @@ func (p *PDNSProvider) ConvertEndpointsToZones(eps []*endpoint.Endpoint, changet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we still have some endpoints left, it means we couldn't find a matching zone (filtered or residual) for them
|
// If we still have some endpoints left, it means we couldn't find a matching zone (filtered or residual) for them
|
||||||
// We warn instead of hard fail here because we don't want a misconfig to cause everything to go down
|
// We warn instead of hard fail here because we don't want a misconfig to cause everything to go down
|
||||||
if len(endpoints) > 0 {
|
if len(endpoints) > 0 {
|
||||||
@ -402,20 +388,17 @@ func (p *PDNSProvider) mutateRecords(endpoints []*endpoint.Endpoint, changetype
|
|||||||
} else {
|
} else {
|
||||||
log.Debugf("Struct for PatchZone:\n%s", string(jso))
|
log.Debugf("Struct for PatchZone:\n%s", string(jso))
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := p.client.PatchZone(zone.Id, zone)
|
resp, err := p.client.PatchZone(zone.Id, zone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("PDNS API response: %s", stringifyHTTPResponseBody(resp))
|
log.Debugf("PDNS API response: %s", stringifyHTTPResponseBody(resp))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Records returns all DNS records controlled by the configured PDNS server (for all zones)
|
// Records returns all DNS records controlled by the configured PDNS server (for all zones)
|
||||||
func (p *PDNSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpoint, _ error) {
|
func (p *PDNSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpoint, _ error) {
|
||||||
|
|
||||||
zones, _, err := p.client.ListZones()
|
zones, _, err := p.client.ListZones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -445,7 +428,6 @@ func (p *PDNSProvider) Records(ctx context.Context) (endpoints []*endpoint.Endpo
|
|||||||
// ApplyChanges takes a list of changes (endpoints) and updates the PDNS server
|
// ApplyChanges takes a list of changes (endpoints) and updates the PDNS server
|
||||||
// by sending the correct HTTP PATCH requests to a matching zone
|
// by sending the correct HTTP PATCH requests to a matching zone
|
||||||
func (p *PDNSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
func (p *PDNSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
||||||
|
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
@ -493,7 +475,6 @@ func (p *PDNSProvider) ApplyChanges(ctx context.Context, changes *plan.Changes)
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("Changes pushed out to PowerDNS in %s\n", time.Since(startTime))
|
log.Debugf("Changes pushed out to PowerDNS in %s\n", time.Since(startTime))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ type RcodeZeroProvider struct {
|
|||||||
//
|
//
|
||||||
// Returns the provider or an error if a provider could not be created.
|
// Returns the provider or an error if a provider could not be created.
|
||||||
func NewRcodeZeroProvider(domainFilter endpoint.DomainFilter, dryRun bool, txtEnc bool) (*RcodeZeroProvider, error) {
|
func NewRcodeZeroProvider(domainFilter endpoint.DomainFilter, dryRun bool, txtEnc bool) (*RcodeZeroProvider, error) {
|
||||||
|
|
||||||
client, err := rc0.NewClient(os.Getenv("RC0_API_KEY"))
|
client, err := rc0.NewClient(os.Getenv("RC0_API_KEY"))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -78,7 +77,6 @@ func NewRcodeZeroProvider(domainFilter endpoint.DomainFilter, dryRun bool, txtEn
|
|||||||
|
|
||||||
// Zones returns filtered zones if filter is set
|
// Zones returns filtered zones if filter is set
|
||||||
func (p *RcodeZeroProvider) Zones() ([]*rc0.Zone, error) {
|
func (p *RcodeZeroProvider) Zones() ([]*rc0.Zone, error) {
|
||||||
|
|
||||||
var result []*rc0.Zone
|
var result []*rc0.Zone
|
||||||
|
|
||||||
zones, err := p.fetchZones()
|
zones, err := p.fetchZones()
|
||||||
@ -99,7 +97,6 @@ func (p *RcodeZeroProvider) Zones() ([]*rc0.Zone, error) {
|
|||||||
//
|
//
|
||||||
// Decrypts TXT records if TXT-Encrypt flag is set and key is provided
|
// Decrypts TXT records if TXT-Encrypt flag is set and key is provided
|
||||||
func (p *RcodeZeroProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) {
|
func (p *RcodeZeroProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, error) {
|
||||||
|
|
||||||
zones, err := p.Zones()
|
zones, err := p.Zones()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -108,7 +105,6 @@ func (p *RcodeZeroProvider) Records(ctx context.Context) ([]*endpoint.Endpoint,
|
|||||||
var endpoints []*endpoint.Endpoint
|
var endpoints []*endpoint.Endpoint
|
||||||
|
|
||||||
for _, zone := range zones {
|
for _, zone := range zones {
|
||||||
|
|
||||||
rrset, err := p.fetchRecords(zone.Domain)
|
rrset, err := p.fetchRecords(zone.Domain)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -116,25 +112,19 @@ func (p *RcodeZeroProvider) Records(ctx context.Context) ([]*endpoint.Endpoint,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, r := range rrset {
|
for _, r := range rrset {
|
||||||
|
|
||||||
if provider.SupportedRecordType(r.Type) {
|
if provider.SupportedRecordType(r.Type) {
|
||||||
|
|
||||||
if p.TXTEncrypt && (p.Key != nil) && strings.EqualFold(r.Type, "TXT") {
|
if p.TXTEncrypt && (p.Key != nil) && strings.EqualFold(r.Type, "TXT") {
|
||||||
p.Client.RRSet.DecryptTXT(p.Key, r)
|
p.Client.RRSet.DecryptTXT(p.Key, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.Records) > 1 {
|
if len(r.Records) > 1 {
|
||||||
|
|
||||||
for _, _r := range r.Records {
|
for _, _r := range r.Records {
|
||||||
if !_r.Disabled {
|
if !_r.Disabled {
|
||||||
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(r.Name, r.Type, endpoint.TTL(r.TTL), _r.Content))
|
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(r.Name, r.Type, endpoint.TTL(r.TTL), _r.Content))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if !r.Records[0].Disabled {
|
} else if !r.Records[0].Disabled {
|
||||||
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(r.Name, r.Type, endpoint.TTL(r.TTL), r.Records[0].Content))
|
endpoints = append(endpoints, endpoint.NewEndpointWithTTL(r.Name, r.Type, endpoint.TTL(r.TTL), r.Records[0].Content))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +134,6 @@ func (p *RcodeZeroProvider) Records(ctx context.Context) ([]*endpoint.Endpoint,
|
|||||||
|
|
||||||
// ApplyChanges applies a given set of changes in a given zone.
|
// ApplyChanges applies a given set of changes in a given zone.
|
||||||
func (p *RcodeZeroProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
func (p *RcodeZeroProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
||||||
|
|
||||||
combinedChanges := make([]*rc0.RRSetChange, 0, len(changes.Create)+len(changes.UpdateNew)+len(changes.Delete))
|
combinedChanges := make([]*rc0.RRSetChange, 0, len(changes.Create)+len(changes.UpdateNew)+len(changes.Delete))
|
||||||
|
|
||||||
combinedChanges = append(combinedChanges, p.NewRcodezeroChanges(rc0.ChangeTypeADD, changes.Create)...)
|
combinedChanges = append(combinedChanges, p.NewRcodezeroChanges(rc0.ChangeTypeADD, changes.Create)...)
|
||||||
@ -156,7 +145,6 @@ func (p *RcodeZeroProvider) ApplyChanges(ctx context.Context, changes *plan.Chan
|
|||||||
|
|
||||||
// Helper function
|
// Helper function
|
||||||
func rcodezeroChangesByZone(zones []*rc0.Zone, changeSet []*rc0.RRSetChange) map[string][]*rc0.RRSetChange {
|
func rcodezeroChangesByZone(zones []*rc0.Zone, changeSet []*rc0.RRSetChange) map[string][]*rc0.RRSetChange {
|
||||||
|
|
||||||
changes := make(map[string][]*rc0.RRSetChange)
|
changes := make(map[string][]*rc0.RRSetChange)
|
||||||
zoneNameIDMapper := provider.ZoneIDName{}
|
zoneNameIDMapper := provider.ZoneIDName{}
|
||||||
for _, z := range zones {
|
for _, z := range zones {
|
||||||
@ -178,7 +166,6 @@ func rcodezeroChangesByZone(zones []*rc0.Zone, changeSet []*rc0.RRSetChange) map
|
|||||||
|
|
||||||
// Helper function
|
// Helper function
|
||||||
func (p *RcodeZeroProvider) fetchRecords(zoneName string) ([]*rc0.RRType, error) {
|
func (p *RcodeZeroProvider) fetchRecords(zoneName string) ([]*rc0.RRType, error) {
|
||||||
|
|
||||||
var allRecords []*rc0.RRType
|
var allRecords []*rc0.RRType
|
||||||
|
|
||||||
listOptions := rc0.NewListOptions()
|
listOptions := rc0.NewListOptions()
|
||||||
@ -204,7 +191,6 @@ func (p *RcodeZeroProvider) fetchRecords(zoneName string) ([]*rc0.RRType, error)
|
|||||||
|
|
||||||
// Helper function
|
// Helper function
|
||||||
func (p *RcodeZeroProvider) fetchZones() ([]*rc0.Zone, error) {
|
func (p *RcodeZeroProvider) fetchZones() ([]*rc0.Zone, error) {
|
||||||
|
|
||||||
var allZones []*rc0.Zone
|
var allZones []*rc0.Zone
|
||||||
|
|
||||||
listOptions := rc0.NewListOptions()
|
listOptions := rc0.NewListOptions()
|
||||||
@ -230,7 +216,6 @@ func (p *RcodeZeroProvider) fetchZones() ([]*rc0.Zone, error) {
|
|||||||
//
|
//
|
||||||
// Changes are submitted by change type.
|
// Changes are submitted by change type.
|
||||||
func (p *RcodeZeroProvider) submitChanges(changes []*rc0.RRSetChange) error {
|
func (p *RcodeZeroProvider) submitChanges(changes []*rc0.RRSetChange) error {
|
||||||
|
|
||||||
if len(changes) == 0 {
|
if len(changes) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -242,11 +227,8 @@ func (p *RcodeZeroProvider) submitChanges(changes []*rc0.RRSetChange) error {
|
|||||||
|
|
||||||
// separate into per-zone change sets to be passed to the API.
|
// separate into per-zone change sets to be passed to the API.
|
||||||
changesByZone := rcodezeroChangesByZone(zones, changes)
|
changesByZone := rcodezeroChangesByZone(zones, changes)
|
||||||
|
|
||||||
for zoneName, changes := range changesByZone {
|
for zoneName, changes := range changesByZone {
|
||||||
|
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
|
|
||||||
logFields := log.Fields{
|
logFields := log.Fields{
|
||||||
"record": change.Name,
|
"record": change.Name,
|
||||||
"content": change.Records[0].Content,
|
"content": change.Records[0].Content,
|
||||||
@ -308,7 +290,6 @@ func (p *RcodeZeroProvider) submitChanges(changes []*rc0.RRSetChange) error {
|
|||||||
|
|
||||||
// NewRcodezeroChanges returns a RcodeZero specific array with rrset change objects.
|
// NewRcodezeroChanges returns a RcodeZero specific array with rrset change objects.
|
||||||
func (p *RcodeZeroProvider) NewRcodezeroChanges(action string, endpoints []*endpoint.Endpoint) []*rc0.RRSetChange {
|
func (p *RcodeZeroProvider) NewRcodezeroChanges(action string, endpoints []*endpoint.Endpoint) []*rc0.RRSetChange {
|
||||||
|
|
||||||
changes := make([]*rc0.RRSetChange, 0, len(endpoints))
|
changes := make([]*rc0.RRSetChange, 0, len(endpoints))
|
||||||
|
|
||||||
for _, _endpoint := range endpoints {
|
for _, _endpoint := range endpoints {
|
||||||
@ -320,7 +301,6 @@ func (p *RcodeZeroProvider) NewRcodezeroChanges(action string, endpoints []*endp
|
|||||||
|
|
||||||
// NewRcodezeroChange returns a RcodeZero specific rrset change object.
|
// NewRcodezeroChange returns a RcodeZero specific rrset change object.
|
||||||
func (p *RcodeZeroProvider) NewRcodezeroChange(action string, endpoint *endpoint.Endpoint) *rc0.RRSetChange {
|
func (p *RcodeZeroProvider) NewRcodezeroChange(action string, endpoint *endpoint.Endpoint) *rc0.RRSetChange {
|
||||||
|
|
||||||
change := &rc0.RRSetChange{
|
change := &rc0.RRSetChange{
|
||||||
Type: endpoint.RecordType,
|
Type: endpoint.RecordType,
|
||||||
ChangeType: action,
|
ChangeType: action,
|
||||||
|
@ -213,7 +213,6 @@ func (r rfc2136Provider) ApplyChanges(ctx context.Context, changes *plan.Changes
|
|||||||
m.SetUpdate(r.zoneName)
|
m.SetUpdate(r.zoneName)
|
||||||
|
|
||||||
for _, ep := range changes.Create {
|
for _, ep := range changes.Create {
|
||||||
|
|
||||||
if !r.domainFilter.Match(ep.DNSName) {
|
if !r.domainFilter.Match(ep.DNSName) {
|
||||||
log.Debugf("Skipping record %s because it was filtered out by the specified --domain-filter", ep.DNSName)
|
log.Debugf("Skipping record %s because it was filtered out by the specified --domain-filter", ep.DNSName)
|
||||||
continue
|
continue
|
||||||
@ -222,7 +221,6 @@ func (r rfc2136Provider) ApplyChanges(ctx context.Context, changes *plan.Changes
|
|||||||
r.AddRecord(m, ep)
|
r.AddRecord(m, ep)
|
||||||
}
|
}
|
||||||
for _, ep := range changes.UpdateNew {
|
for _, ep := range changes.UpdateNew {
|
||||||
|
|
||||||
if !r.domainFilter.Match(ep.DNSName) {
|
if !r.domainFilter.Match(ep.DNSName) {
|
||||||
log.Debugf("Skipping record %s because it was filtered out by the specified --domain-filter", ep.DNSName)
|
log.Debugf("Skipping record %s because it was filtered out by the specified --domain-filter", ep.DNSName)
|
||||||
continue
|
continue
|
||||||
@ -231,7 +229,6 @@ func (r rfc2136Provider) ApplyChanges(ctx context.Context, changes *plan.Changes
|
|||||||
r.UpdateRecord(m, ep)
|
r.UpdateRecord(m, ep)
|
||||||
}
|
}
|
||||||
for _, ep := range changes.Delete {
|
for _, ep := range changes.Delete {
|
||||||
|
|
||||||
if !r.domainFilter.Match(ep.DNSName) {
|
if !r.domainFilter.Match(ep.DNSName) {
|
||||||
log.Debugf("Skipping record %s because it was filtered out by the specified --domain-filter", ep.DNSName)
|
log.Debugf("Skipping record %s because it was filtered out by the specified --domain-filter", ep.DNSName)
|
||||||
continue
|
continue
|
||||||
|
@ -206,7 +206,7 @@ func (p *vinyldnsProvider) findRecordSetID(zoneID string, recordSetName string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "", fmt.Errorf("Record not found")
|
return "", fmt.Errorf("record not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *vinyldnsProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
func (p *vinyldnsProvider) ApplyChanges(ctx context.Context, changes *plan.Changes) error {
|
||||||
|
@ -156,7 +156,6 @@ func (p *VultrProvider) submitChanges(ctx context.Context, changes []*VultrChang
|
|||||||
|
|
||||||
for zoneName, changes := range zoneChanges {
|
for zoneName, changes := range zoneChanges {
|
||||||
for _, change := range changes {
|
for _, change := range changes {
|
||||||
|
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"record": change.ResourceRecordSet.Name,
|
"record": change.ResourceRecordSet.Name,
|
||||||
"type": change.ResourceRecordSet.Type,
|
"type": change.ResourceRecordSet.Type,
|
||||||
@ -202,7 +201,6 @@ func (p *VultrProvider) submitChanges(ctx context.Context, changes []*VultrChang
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,7 +219,6 @@ func newVultrChanges(action string, endpoints []*endpoint.Endpoint) []*VultrChan
|
|||||||
changes := make([]*VultrChanges, 0, len(endpoints))
|
changes := make([]*VultrChanges, 0, len(endpoints))
|
||||||
ttl := vultrTTL
|
ttl := vultrTTL
|
||||||
for _, e := range endpoints {
|
for _, e := range endpoints {
|
||||||
|
|
||||||
if e.RecordTTL.IsConfigured() {
|
if e.RecordTTL.IsConfigured() {
|
||||||
ttl = int(e.RecordTTL)
|
ttl = int(e.RecordTTL)
|
||||||
}
|
}
|
||||||
@ -256,7 +253,6 @@ func seperateChangesByZone(zones []govultr.DNSDomain, changes []*VultrChanges) m
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
change[zone] = append(change[zone], c)
|
change[zone] = append(change[zone], c)
|
||||||
|
|
||||||
}
|
}
|
||||||
return change
|
return change
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,6 @@ func (sc *gatewaySource) endpointsFromGateway(hostnames []string, gateway networ
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (sc *gatewaySource) hostNamesFromGateway(gateway networkingv1alpha3.Gateway) ([]string, error) {
|
func (sc *gatewaySource) hostNamesFromGateway(gateway networkingv1alpha3.Gateway) ([]string, error) {
|
||||||
|
|
||||||
var hostnames []string
|
var hostnames []string
|
||||||
for _, server := range gateway.Spec.Servers {
|
for _, server := range gateway.Spec.Servers {
|
||||||
for _, host := range server.Hosts {
|
for _, host := range server.Hosts {
|
||||||
|
@ -228,7 +228,7 @@ func matchLabelSelector(selector labels.Selector, srcAnnotations map[string]stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func poll(interval time.Duration, timeout time.Duration, condition wait.ConditionFunc) error {
|
func poll(interval time.Duration, timeout time.Duration, condition wait.ConditionFunc) error {
|
||||||
if config.FAST_POLL {
|
if config.FastPoll {
|
||||||
time.Sleep(5 * time.Millisecond)
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
|
||||||
ok, err := condition()
|
ok, err := condition()
|
||||||
|
Loading…
Reference in New Issue
Block a user