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

GCE: Updating instance groups interface to accept all named ports at once #1463

Merged
merged 1 commit into from
Oct 6, 2017

Conversation

nikhiljindal
Copy link
Contributor

Follow up from #1033.

Updating the BackendPool (for backend services) and NodePool (for instance groups) interfaces so that all named ports can be added to an instance group at once. This removes unnecessary API calls where for each named port, we were first fetching the instance group and then setting the named port on it. With this change, we should fetch the instance group once and then set all named ports in a single API call.

Have also removed BackendPool.Sync method since Add does the same now.
Sync was also misleading since it only added backend services and didnt delete them. Add is more explicit.

cc @nicksardo @csbell @G-Harmon

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Oct 3, 2017
@k8s-reviewable
Copy link

This change is Reviewable

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Oct 3, 2017
@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 43.618% when pulling 9a8789d on nikhiljindal:refactorBackendSync into abc8b9d on kubernetes:master.

@G-Harmon
Copy link

G-Harmon commented Oct 4, 2017

Reviewed 10 of 10 files at r1.
Review status: all files reviewed at latest revision, 3 unresolved discussions.


controllers/gce/backends/backends_test.go, line 264 at r1 (raw file):

	pool, _ := newTestJig(f, fakeIGs, true)
	pool.Add([]ServicePort{ServicePort{Port: 81}}, nil)
	pool.Add([]ServicePort{ServicePort{Port: 90}}, nil)

Can you please update the unit test to exercise your new code using multiple ports? Could you combine these two pool.Add() calls?


controllers/gce/controller/utils_test.go, line 81 at r1 (raw file):

	gotZonesToNode := cm.fakeIGs.GetInstancesByZone()

	if cm.fakeIGs.Ports[0] != testPort[0] {

Is it useful or valuable to verify the length of cm.fakeIGs.Ports?


controllers/gce/instances/instances_test.go, line 72 at r1 (raw file):

	f = NewFakeInstanceGroups(sets.NewString([]string{"n1", "n2"}...))
	pool = newNodePool(f, defaultZone)
	pool.AddInstanceGroup("test", []int64{80})

same here, perhaps add a test that exercises multiple ports.


Comments from Reviewable

@nikhiljindal
Copy link
Contributor Author

Review status: 8 of 11 files reviewed at latest revision, 3 unresolved discussions.


controllers/gce/backends/backends_test.go, line 264 at r1 (raw file):

Previously, G-Harmon wrote…

Can you please update the unit test to exercise your new code using multiple ports? Could you combine these two pool.Add() calls?

The line below this is calling Add with multiple ports.
There were already tests here for Add (which took a single port) and Sync (which took multiple ports) before this change.
I have updated both to call Add now, with single port or multiple ports - so we have tests for both.


controllers/gce/controller/utils_test.go, line 81 at r1 (raw file):

Previously, G-Harmon wrote…

Is it useful or valuable to verify the length of cm.fakeIGs.Ports?

Good point, done.


controllers/gce/instances/instances_test.go, line 72 at r1 (raw file):

Previously, G-Harmon wrote…

same here, perhaps add a test that exercises multiple ports.

Done. Figured there were no port specific tests.
Have added a separate TestSetNamedPorts with multiple test cases.


Comments from Reviewable

@nikhiljindal
Copy link
Contributor Author

Thanks @G-Harmon for the review. Have updated code as per comments. PTAL

defer func() { b.snapshotter.Add(portKey(p.Port), be) }()

var err error
func (b *Backends) Add(svcPorts []ServicePort, igs []*compute.InstanceGroup) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about renaming this func to 'Sync'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sync will imply that we will add missing ones and delete extras. But this one adds and not deletes. Thats the reason I prefer add over sync

Copy link
Contributor

Choose a reason for hiding this comment

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

But we also update backend services.

// addWithIGs will get or create a Backend for the given port.
// It assumes that the instance groups have been created and required named port has been added.
// If not, then Add should be called instead.
func (b *Backends) addWithIGs(p ServicePort, igs []*compute.InstanceGroup) error {
Copy link
Contributor

@nicksardo nicksardo Oct 5, 2017

Choose a reason for hiding this comment

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

How about naming "syncBackendService"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed to addBackendService. Same argument as above about sync vs add.

@@ -151,20 +150,19 @@ func (f *FakeInstanceGroups) RemoveInstancesFromInstanceGroup(name, zone string,

func (f *FakeInstanceGroups) SetNamedPortsOfInstanceGroup(igName, zone string, namedPorts []*compute.NamedPort) error {
found := false
for _, ig := range f.instanceGroups {
if ig.Name == igName && ig.Zone == zone {
var ig *compute.InstanceGroup
Copy link
Contributor

Choose a reason for hiding this comment

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

Can remove the above found variable and use ig == nil for the "failed to find..." error.

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

glog.V(3).Infof("Instance group %v already has named port %+v", ig.Name, np)
found = true
break
continue
Copy link
Contributor

Choose a reason for hiding this comment

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

glog.V(3).Infof("Instance group %v already has named port %+v", ig.Name, np) occurs very frequently. Recommend we bump the level to 5. Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. You look at logs a lot more than me, so happy to do whatever you say :)
Updated to 5.

if np.Port == port {
existingPorts[np.Port] = true
}
newPorts := []*compute.NamedPort{}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: var newPorts []*compute.NamedPort

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

@nicksardo
Copy link
Contributor

Done reviewing. PTAL at my comments but looks great otherwise.

@nicksardo
Copy link
Contributor

Looks like CI failed building the tests: https://travis-ci.org/kubernetes/ingress/jobs/283895016


// node pool syncs kube-nodes, this will add them to both igs.
lbc.CloudClusterManager.instancePool.Sync([]string{"n1", "n2", "n3"})
gotZonesToNode := cm.fakeIGs.GetInstancesByZone()

if cm.fakeIGs.Ports[0] != testPort {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this since we already have a dedicated test for testing ports on instance groups. No need to duplicate the check here.

@nikhiljindal
Copy link
Contributor Author

nikhiljindal commented Oct 5, 2017

Thanks @nicksardo !
Updated code as per comments. PTAL

@nikhiljindal
Copy link
Contributor Author

Renamed Add to Ensure as discussed

@nicksardo nicksardo added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 6, 2017
@nicksardo nicksardo merged commit d662620 into kubernetes:master Oct 6, 2017
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. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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.

6 participants