-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add subdomain filter to AWS provider #1375
Closed
Closed
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3c81959
added subdomain filter for aws provider
spohner 656730d
Added tests for subdomainfilter
spohner 2c9210b
Added subdomain section
spohner 773817d
Revert "Added subdomain section"
spohner d26c7ef
Fix wrong indentations
spohner e0b67d0
Change name to Subdomain filter
spohner ee134b2
Added SubdomainFilter wrapper
spohner d6fe14f
added subdomain filter for aws provider
spohner e100a79
Added tests for subdomainfilter
spohner 7d13591
Added subdomain section
spohner 41a86c0
Revert "Added subdomain section"
spohner 6dbd36b
Fix wrong indentations
spohner ea9f612
Change name to Subdomain filter
spohner 618f585
Added SubdomainFilter wrapper
spohner b1ce5f5
Merge branch 'subdomainfilter' of https://github.com/spohner/external…
spohner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -124,7 +124,9 @@ type AWSProvider struct { | |
zoneTypeFilter ZoneTypeFilter | ||
// filter hosted zones by tags | ||
zoneTagFilter ZoneTagFilter | ||
preferCNAME bool | ||
// only allow changes to specified subdomain and its subdomains | ||
subdomainFilter DomainFilter | ||
preferCNAME bool | ||
} | ||
|
||
// AWSConfig contains configuration to create a new AWS provider. | ||
|
@@ -133,6 +135,7 @@ type AWSConfig struct { | |
ZoneIDFilter ZoneIDFilter | ||
ZoneTypeFilter ZoneTypeFilter | ||
ZoneTagFilter ZoneTagFilter | ||
SubdomainFilter DomainFilter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also here DomainFilter -> SubDomainFilter? |
||
BatchChangeSize int | ||
BatchChangeInterval time.Duration | ||
EvaluateTargetHealth bool | ||
|
@@ -174,6 +177,7 @@ func NewAWSProvider(awsConfig AWSConfig) (*AWSProvider, error) { | |
zoneIDFilter: awsConfig.ZoneIDFilter, | ||
zoneTypeFilter: awsConfig.ZoneTypeFilter, | ||
zoneTagFilter: awsConfig.ZoneTagFilter, | ||
subdomainFilter: awsConfig.SubdomainFilter, | ||
batchChangeSize: awsConfig.BatchChangeSize, | ||
batchChangeInterval: awsConfig.BatchChangeInterval, | ||
evaluateTargetHealth: awsConfig.EvaluateTargetHealth, | ||
|
@@ -401,8 +405,10 @@ func (p *AWSProvider) submitChanges(ctx context.Context, changes []*route53.Chan | |
return nil | ||
} | ||
|
||
filteredChangesBySubdomains := filteredChangesBySubdomains(changes, p) | ||
|
||
// separate into per-zone change sets to be passed to the API. | ||
changesByZone := changesByZone(zones, changes) | ||
changesByZone := changesByZone(zones, filteredChangesBySubdomains) | ||
if len(changesByZone) == 0 { | ||
log.Info("All records are already up to date, there are no changes for the matching hosted zones") | ||
} | ||
|
@@ -651,6 +657,18 @@ func sortChangesByActionNameType(cs []*route53.Change) []*route53.Change { | |
return cs | ||
} | ||
|
||
func filteredChangesBySubdomains(changeSet []*route53.Change, p *AWSProvider) []*route53.Change { | ||
changes := []*route53.Change{} | ||
|
||
for _, c := range changeSet { | ||
hostname := aws.StringValue(c.ResourceRecordSet.Name) | ||
if p.subdomainFilter.Match(hostname) { | ||
changes = append(changes, c) | ||
} | ||
} | ||
return changes | ||
} | ||
|
||
// changesByZone separates a multi-zone change into a single change per zone. | ||
func changesByZone(zones map[string]*route53.HostedZone, changeSet []*route53.Change) map[string][]*route53.Change { | ||
changes := make(map[string][]*route53.Change) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this not be changed to SubdomainFilter instead of DomainFilter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The subdomain filter is still a domain filter and the domain filtering provided by DomainFilter will be sufficient. However, I can add a SubdomainFilter type for readability and future changes. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes please, just thought it would be better to divide it because of readability and future changes as well.