-
Notifications
You must be signed in to change notification settings - Fork 40k
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: Allow node count to exceed GCE TargetPool maximums #25178
Merged
k8s-github-robot
merged 1 commit into
kubernetes:master
from
zmerlynn:random_max_target_pools
May 10, 2016
+208
−23
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ package gce | |
import ( | ||
"reflect" | ||
"testing" | ||
|
||
compute "google.golang.org/api/compute/v1" | ||
"k8s.io/kubernetes/pkg/util/rand" | ||
) | ||
|
||
func TestGetRegion(t *testing.T) { | ||
|
@@ -148,3 +151,112 @@ func TestScrubDNS(t *testing.T) { | |
} | ||
} | ||
} | ||
|
||
func TestRestrictTargetPool(t *testing.T) { | ||
const maxInstances = 5 | ||
tests := []struct { | ||
instances []string | ||
want []string | ||
}{ | ||
{ | ||
instances: []string{"1", "2", "3", "4", "5"}, | ||
want: []string{"1", "2", "3", "4", "5"}, | ||
}, | ||
{ | ||
instances: []string{"1", "2", "3", "4", "5", "6"}, | ||
want: []string{"4", "3", "5", "2", "6"}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
rand.Seed(5) | ||
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. comment on this seed value and the "want" values above? 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. Done. I used prose to comment the test blocks, hopefully that was good. |
||
got := restrictTargetPool(append([]string{}, tc.instances...), maxInstances) | ||
if !reflect.DeepEqual(got, tc.want) { | ||
t.Errorf("restrictTargetPool(%v) => %v, want %v", tc.instances, got, tc.want) | ||
} | ||
} | ||
} | ||
|
||
func TestComputeUpdate(t *testing.T) { | ||
const maxInstances = 5 | ||
const fakeZone = "us-moon1-f" | ||
tests := []struct { | ||
tp []string | ||
instances []string | ||
wantToAdd []string | ||
wantToRemove []string | ||
}{ | ||
{ | ||
// Test adding all instances. | ||
tp: []string{}, | ||
instances: []string{"0", "1", "2"}, | ||
wantToAdd: []string{"0", "1", "2"}, | ||
wantToRemove: []string{}, | ||
}, | ||
{ | ||
// Test node 1 coming back healthy. | ||
tp: []string{"0", "2"}, | ||
instances: []string{"0", "1", "2"}, | ||
wantToAdd: []string{"1"}, | ||
wantToRemove: []string{}, | ||
}, | ||
{ | ||
// Test node 1 going healthy while node 4 needs to be removed. | ||
tp: []string{"0", "2", "4"}, | ||
instances: []string{"0", "1", "2"}, | ||
wantToAdd: []string{"1"}, | ||
wantToRemove: []string{"4"}, | ||
}, | ||
{ | ||
// Test exceeding the TargetPool max of 5 (for the test), | ||
// which shuffles in 7, 5, 8 based on the deterministic | ||
// seed below. | ||
tp: []string{"0", "2", "4", "6"}, | ||
instances: []string{"0", "1", "2", "3", "5", "7", "8"}, | ||
wantToAdd: []string{"7", "5", "8"}, | ||
wantToRemove: []string{"4", "6"}, | ||
}, | ||
{ | ||
// Test all nodes getting removed. | ||
tp: []string{"0", "1", "2", "3"}, | ||
instances: []string{}, | ||
wantToAdd: []string{}, | ||
wantToRemove: []string{"0", "1", "2", "3"}, | ||
}, | ||
} | ||
for _, tc := range tests { | ||
rand.Seed(5) // Arbitrary RNG seed for deterministic testing. | ||
|
||
// Dummy up the gceInstance slice. | ||
var instances []*gceInstance | ||
for _, inst := range tc.instances { | ||
instances = append(instances, &gceInstance{Name: inst, Zone: fakeZone}) | ||
} | ||
// Dummy up the TargetPool URL list. | ||
var urls []string | ||
for _, inst := range tc.tp { | ||
inst := &gceInstance{Name: inst, Zone: fakeZone} | ||
urls = append(urls, inst.makeComparableHostPath()) | ||
} | ||
gotAddInsts, gotRem := computeUpdate(&compute.TargetPool{Instances: urls}, instances, maxInstances) | ||
var wantAdd []string | ||
for _, inst := range tc.wantToAdd { | ||
inst := &gceInstance{Name: inst, Zone: fakeZone} | ||
wantAdd = append(wantAdd, inst.makeComparableHostPath()) | ||
} | ||
var gotAdd []string | ||
for _, inst := range gotAddInsts { | ||
gotAdd = append(gotAdd, inst.Instance) | ||
} | ||
if !reflect.DeepEqual(wantAdd, gotAdd) { | ||
t.Errorf("computeTargetPool(%v, %v) => added %v, wanted %v", tc.tp, tc.instances, gotAdd, wantAdd) | ||
} | ||
_ = gotRem | ||
// var gotRem []string | ||
// for _, inst := range gotRemInsts { | ||
// gotRem = append(gotRem, inst.Instance) | ||
// } | ||
// if !reflect.DeepEqual(tc.wantToRemove, gotRem) { | ||
// t.Errorf("computeTargetPool(%v, %v) => removed %v, wanted %v", tc.tp, tc.instances, gotRem, tc.wantToRemove) | ||
// } | ||
} | ||
} |
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
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.
@kubernetes/goog-cluster fyi
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.
Internal b/28566577, FYI