Skip to content
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

Fix for #368 #374

Merged
merged 1 commit into from
Nov 10, 2017
Merged

Fix for #368 #374

merged 1 commit into from
Nov 10, 2017

Conversation

bitvector2
Copy link
Contributor

All relevent changes are in aws.go

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 31, 2017
@mikkeloscar
Copy link
Contributor

Could you please drop all the import changes from the commits?

For go projects it's a good idea to use the original repository in your go path but just add your fork as another remote, that way you don't have to change the imports when testing it locally.

@bitvector2
Copy link
Contributor Author

bitvector2 commented Oct 31, 2017 via email

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 31, 2017
@bitvector2
Copy link
Contributor Author

stashed, reset import changes, stash applied, commit'd, pushed... should be good now..

@njuettner
Copy link
Member

njuettner commented Nov 1, 2017

Thanks for your PR!

Maybe you can try to rewrite your code more like this:


func batchLimitChangeSet(changes []*route53.Change) []*route53.Change {
...
	for i := 0; i < len(changes); i += batchLimit {
		batch := changes[i:min(i+batchLimit, len(changes))]
		//do something
	}
...
}
// a + b should have better names
func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

This would be easier to read it (at least for me).

batchLimit could be somewhere else like moved to const, maybe even more configurable (but here I'm totally open).

Also please add unit tests.

@bitvector2
Copy link
Contributor Author

bitvector2 commented Nov 1, 2017

The reason I wrote the function in the manner I did was to preserve the atomic nature of all related records by hostname. Currently all the A records are added first to the original CS, then all the TXT records are added to the CS and the entire batch is presumed atomic. If one were to just take the head or the tail of the original CS they would be violating the integrity that they were originally expecting. This said I'm happy to rework in any way desired.

@bitvector2
Copy link
Contributor Author

bitvector2 commented Nov 1, 2017

I think I can combine both ideas so it is an immediately complete scheme, as you wish.

provider/aws.go Outdated
@@ -254,6 +257,39 @@ func (p *AWSProvider) submitChanges(changes []*route53.Change) error {
return nil
}

func limitChangeSet(cs []*route53.Change) []*route53.Change {
limit := 4000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be a constant defined on the top of the file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

provider/aws.go Outdated
for name, count := range countsByName {
if (remaining - count) > 0 {
remaining -= count
for _, v := range cs {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a minor optimisation countsByName, could be changesByName, then you don't have to iterate over whole set to find and append the records by name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you lost me here - are you saying there already is a changesByName or are you saying for me to move my iteration out into its own function changesByName and call it instead?

Copy link

@ideahitme ideahitme Nov 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea was to create a map changesByName instead of countsByName:

changesByName := map[string][]*route53.Change

when u need a count, u can do len(changesByName[name]), when u need to append:

limCs = append(limCs, changesByName[name]...)

@ideahitme
Copy link

please address two comments above, otherwise LGTM

@bitvector2
Copy link
Contributor Author

bitvector2 commented Nov 2, 2017

@ideahitme please merge if you approve

@bitvector2
Copy link
Contributor Author

bitvector2 commented Nov 2, 2017 via email

@ideahitme
Copy link

ideahitme commented Nov 3, 2017

thank you, looks good to me, however it would also be nice to see tests for the limitChangeSet function and AWS ApplyChanges

@bitvector2
Copy link
Contributor Author

bitvector2 commented Nov 3, 2017

thanks for the feedback! - tests coming

:jackiechan:

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 6, 2017
@bitvector2
Copy link
Contributor Author

@ideahitme initial tests have been added - please comment

limCs := limitChangeSet(cs)

limitedCount := len(limCs)
assert.True(t, limitedCount == maxChangeCount, "limited changeset count=%d does not equal maxChangeCount=%d", limitedCount, maxChangeCount)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I want to be sure of here, is that we do not accidentally end up with orphaned A or TXT record. I suggest to make the test more elaborate, for example by making limitChangeSet take maxChangeCount as a parameter. Consequently in test u can use a sane value like 4 or 6 and for test itself make sure that this limit is not exceeded and correct records are picked up.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

additionally having submitChanges tested as well would be nice (test case with 4000+ records for one hosted zone)

}

func sortChangesByActionNameType(cs []*route53.Change) []*route53.Change {
sort.SliceStable(cs, func(i, j int) bool {
Copy link

@ideahitme ideahitme Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with this change travis builds will break on go1.7, but I think we can safely drop it from travis. Would u want to do it, or u want me to update it on this PR ?

@ideahitme
Copy link

two minor things:

  1. Please add this to Changelog
  2. Travis build is failing due to g1.8 sortstable. We should drop go1.7 support from travis.

otherwise LGTM

@bitvector2
Copy link
Contributor Author

@ideahitme - rebased, updated the changelog and travis and its all ready for you now...

@szuecs
Copy link
Contributor

szuecs commented Nov 10, 2017

👍

1 similar comment
@Raffo
Copy link
Contributor

Raffo commented Nov 10, 2017

👍

@Raffo Raffo merged commit cc498e1 into kubernetes-sigs:master Nov 10, 2017
ffledgling pushed a commit to ffledgling/external-dns that referenced this pull request Jan 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants