-
Notifications
You must be signed in to change notification settings - Fork 820
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 findOpenPorts portAllocator function #1725
Conversation
Build Succeeded 👏 Build Id: d5bc282d-f118-475a-9e97-c872153beb12 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
Note that in that case of |
Build Failed 😱 Build Id: 1c8aa1ec-e06a-4a63-ad29-2f241ee39617 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
// single port empty | ||
fd := fixture.DeepCopy() | ||
fd.Spec.Ports[0].PortPolicy = "" | ||
pa.Allocate(fd) |
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.
Allocate returns GameServer pointer, so it is worth checking it for nil.
fd := fixture.DeepCopy() | ||
fd.Spec.Ports[0].PortPolicy = "" | ||
pa.Allocate(fd) | ||
assert.Nil(t, err) |
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.
Which error do you check here? Seems this assert is redundant.
assert.True(t, cache.WaitForCacheSync(stop, pa.nodeSynced)) | ||
|
||
err := pa.syncAll() | ||
assert.Nil(t, err) |
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.
Use require here, please. If an error happens here there is no point to continue.
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.
Also use NoError
over Nil
- that way if it fails, we get a better error message.
@@ -39,6 +39,37 @@ var ( | |||
n3 = corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "node3", UID: "node3"}} | |||
) | |||
|
|||
func TestEmptyPortPolicy(t *testing.T) { |
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.
I think this test name is not accurate. It should describe which function do you test.
There is a test function TestPortAllocatorAllocate, so you can put this scenario there as a separate t.Run("empty port policy")
statement.
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.
"TestPortAllocatorAllocateWithEmptyPolicy" ?
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.
several changes have been requested
@akremsa: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
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.
Doh! I never submitted this review!
fd := fixture.DeepCopy() | ||
fd.Spec.Ports[0].PortPolicy = "" | ||
pa.Allocate(fd) | ||
assert.Nil(t, err) |
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.
assert.Nil(t, err) | |
assert.NoError(t, err) |
(gives a better message on failure)
assert.True(t, cache.WaitForCacheSync(stop, pa.nodeSynced)) | ||
|
||
err := pa.syncAll() | ||
assert.Nil(t, err) |
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.
Also use NoError
over Nil
- that way if it fails, we get a better error message.
@@ -39,6 +39,37 @@ var ( | |||
n3 = corev1.Node{ObjectMeta: metav1.ObjectMeta{Name: "node3", UID: "node3"}} | |||
) | |||
|
|||
func TestEmptyPortPolicy(t *testing.T) { |
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.
"TestPortAllocatorAllocateWithEmptyPolicy" ?
@@ -121,6 +121,9 @@ func (pa *PortAllocator) Allocate(gs *agonesv1.GameServer) *agonesv1.GameServer | |||
// Also the return gives an escape from the double loop | |||
findOpenPorts := func(amount int) []pn { | |||
var ports []pn | |||
if amount <= 0 { |
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.
Excellent short circuit! 👍
58ffbae
to
5296de6
Compare
Thanks for the review, I have applied both series of comments. |
Build Succeeded 👏 Build Id: 5bcf26fb-3fc7-409e-9441-37a1e70e72c8 The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
@akremsa: changing LGTM is restricted to collaborators In response to this: Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
There could be the possible case when we set PortPolicy as an empty string on update of GameServer.
5296de6
to
fc49377
Compare
Build Succeeded 👏 Build Id: 2eb288d6-4d54-42d9-9b69-fd37ba14576f The following development artifacts have been built, and will exist for the next 30 days:
A preview of the website (the last 30 builds are retained): To install this version:
|
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.
Love it!
This also ties nicely into #749
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: akremsa, aLekSer, markmandel The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
* Fix findOpenPorts portAllocator function There could be the possible case when we set PortPolicy as an empty string on update of GameServer.
There could be the possible case when we set PortPolicy as an empty
string on update of GameServer.
What type of PR is this?
/kind bug
What this PR does / Why we need it:
There is a way to cause infinite loop (recursion) in
Allocate()
function usingkubectl edit gameservers
, if you update thePortPolicy
to an empty string "" and one more field. Then you would receive the state when Agones controller could not allocate any ports and got stuck in this state:Which issue(s) this PR fixes:
none
Special notes for your reviewer:
This is not expected scenario of editing
GameServer
but I assume that restarting agones controller with deleting bad GameServer would recover from this situation.