-
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
Allow ports to be added to any container in a GS pod #1396
Allow ports to be added to any container in a GS pod #1396
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
Thanks for this PR, it seems that this feature would be really useful. |
Build Failed 😱 Build Id: fdf4096e-9153-44c6-bdfa-69a14fe1dbeb To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
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.
Looks good overall would be really helpful for us ... only questions are around if any other tests are needed.
pkg/apis/agones/v1/gameserver.go
Outdated
|
||
for _, p := range gs.Spec.Ports { | ||
cp := corev1.ContainerPort{ | ||
ContainerPort: p.ContainerPort, | ||
HostPort: p.HostPort, | ||
Protocol: p.Protocol, | ||
} | ||
gsContainer.Ports = append(gsContainer.Ports, cp) | ||
portApplied := false | ||
for j, container := range pod.Spec.Containers { |
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.
nit - j
is this just index?
pkg/apis/agones/v1/gameserver.go
Outdated
@@ -417,6 +423,22 @@ func (gss *GameServerSpec) Validate(devAddress string) ([]metav1.StatusCause, bo | |||
Message: ErrHostPortDynamic, | |||
}) | |||
} | |||
|
|||
if p.ContainerName != "" && gss.Container != "" { |
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.
is there tests around one or both of these being an empty string?
HostPort: 5002, | ||
PortPolicy: Static, | ||
ContainerPort: 5002, | ||
ContainerName: "anothertest", |
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.
is this the only place it needs to be tested?
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.
Other than the comment below on splitting things up, I don't see any other unit tests that need updating at this point.
But like i mentioned in the main comment - would definitely want a e2e test.
@domgreen: 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. |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Build Failed 😱 Build Id: 3a42fde6-c3cb-4779-b717-312b709fd616 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
|
Hi! Thanks so much for doing this work! I had a TODO from a previous Slack conversation to write a ticket for this for ages, and never got around to it! This is going to be really useful. A few high level things, and then I'll drop some comments on more specific stuff: Which means it will also need a feature gate - you can add one here. We should also add an e2e test for this - I wonder if we can run 2 simple-udp containers side by side and open them both up to UDP traffic separately? Or run a nginx image as a sidecar, and connect to the TCP port as a http request even? Right now the e2e test installation doesn't enable any feature flags, but I'll enable that today so it's ready for you as well. Please let us know if you have any questions on the above. |
pkg/apis/agones/v1/gameserver.go
Outdated
@@ -192,7 +192,9 @@ type GameServerPort struct { | |||
// When `Static` portPolicy is specified, `HostPort` is required, to specify the port that game clients will | |||
// connect to | |||
PortPolicy PortPolicy `json:"portPolicy,omitempty"` | |||
// ContainerPort is the port that is being opened on the game server process | |||
// ContainerName is the container on which to open the port. Defaults to the game server container. | |||
ContainerName string `json:"containerName,omitempty"` |
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 be Container string
to match what we have at the top level for specifying the "game server container"? Seems like it should be more consistent.
Also, when you do the Alpha feature flagging - this should be made into a pointer, so it's easily omitted.
pkg/apis/agones/v1/gameserver.go
Outdated
|
||
if p.ContainerName != "" && gss.Container != "" { | ||
containerFound := false | ||
for _, container := range gss.Template.Spec.Containers { |
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.
Would it make more sense to update FindGameServerContainer
to something that can FindContainer
which takes a container name passed in?
Might make this code a little nicer, and likely easier to test.
pkg/apis/agones/v1/gameserver.go
Outdated
gsContainer.Ports = append(gsContainer.Ports, cp) | ||
portApplied := false | ||
for j, container := range pod.Spec.Containers { | ||
if container.Name == p.ContainerName { |
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.
Probably also makes sense to update and rename ApplyToPodGameServerContainer
to use with this logic, since it's almost the same, except you would want to pass in a name, rather than use the gs.Spec.Container by default.
assert.Equal(t, corev1.Protocol("UDP"), pod.Spec.Containers[0].Ports[0].Protocol) | ||
assert.True(t, metav1.IsControlledBy(pod, fixture)) | ||
|
||
sidecar := corev1.Container{Name: "sidecar", Image: "container/sidecar"} | ||
fixture.Spec.Template.Spec.ServiceAccountName = "other-agones-sdk" | ||
fixture.Spec.Ports = append(fixture.Spec.Ports, GameServerPort{ |
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.
Do we want to split this into two tests? Once with the default port setup, and one with this new functionality - just to get coverage on both scenarios?
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.
Added a bunch of comments, but this is definitely headed in a great direction. Some other things that also in mind:
We'll need some docs here: https://agones.dev/site/docs/reference/gameserver/
(Check out the documentation guide on how to hide new features until they are complete), and updates here:
https://github.com/googleforgames/agones/blob/master/examples/gameserver.yaml
I think that's about it though 👍
I've iterated on all your suggestions: thanks for the feedback! There are a couple of instances where errors are newly returned but I opted to ignore them due to the game server name definitely being set at that point. I've also run into a problem with the docs after
|
Build Failed 😱 Build Id: 8e827621-4aa4-4ac3-83d7-b1d4581b0689 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
@benclive thanks for noticing this. As a workaround you can put the whole "```yaml" block into the shortcode:
And old one into |
Build Failed 😱 Build Id: 0282760d-9dec-4d6c-a35c-705091e560b2 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
Build Failed 😱 Build Id: 699ea887-91d4-468d-97b9-8b5893d28e88 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
Build Failed 😱 Build Id: 48cbac67-c4e8-4c97-bfd9-52c2db6ae162 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
@markmandel The E2E tests are now failing on my change; I'm waiting for #1397 to be merged to make any more progress as I need to enable the feature flag in the E2E tests. |
Build Failed 😱 Build Id: 45217172-d1a7-4684-b960-0edfa6d882cc To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
Build Failed 😱 Build Id: f35b3a3c-22ae-4cd1-8103-dd17c5e3ce15 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
I can't tell if the current failure is related to my changes or not: Running |
Ah, TestGameServerReserve is flaky - #1276 - I'll restart it. |
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.
This looks awesome 🔥
I just realised one thing that will need to be added, and then this is good to go (assuming all tests pass).
https://agones.dev/site/docs/guides/feature-stages/#feature-gates < we should add a section here for your feature flag and link it to the gameserver reference page.
Outside of that, this is ready to merge!
Build Succeeded 👏 Build Id: 26235e87-2ff5-4702-af99-b794ff267625 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:
|
Build Succeeded 👏 Build Id: 6f186ecf-078b-4ded-a2b2-34780244ee85 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:
|
@@ -28,6 +28,7 @@ The current set of `alpha` and `beta` feature gates are: | |||
|--------------|---------|---------|-------|-------| | |||
| Multicluster Allocation<sup>*</sup> | N/A | Enabled | `Alpha` | 0.11.0 | | |||
| Example Gate (not in use) | `Example` | Disabled | None | 0.13.0 | | |||
| [Port Allocations to Multiple Containers]({{< ref "/docs/Reference/gameserver.md" >}}) | `ContainerPortAllocation` | Disabled | `Alpha` | 1.5.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.
You'll hate me, but this need to be wrapped in a feature
shortcode like you did previously, so it doesn't show up with this release. 🤦♂️ I should have mentioned that in my comments previously.
(Might need to make a copy of the table, not sure, depends how formatting works out)
I swear this is the last thing 👍
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.
Good point! I had to wrap the table as you mentioned but all done now :)
Build Failed 😱 Build Id: 7160b526-0161-4014-83f2-0eb04c2e52b6 To get permission to view the Cloud Build view, join the agones-discuss Google Group. |
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.
👯♂️ 👯♀️
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: benclive, domgreen, 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 |
Build Succeeded 👏 Build Id: a7c4e336-2a75-4a6f-9ae9-669a180b1f0d 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:
|
New changes are detected. LGTM label has been removed. |
Build Succeeded 👏 Build Id: ca227e84-eedd-4376-be3e-cfc7f635cf89 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:
|
…1396) * Allow ports to be added to any container in a gs * Adding E2E tests + feature flag * Update docs * Add feature info to feature stage page Co-authored-by: Mark Mandel <[email protected]>
We have a use case for mapping ports to sidecars for auth purposes. Our pod contains a sidecar container for auth as well as a main game server container.
We require clients to be able to access the auth sidecar as well as the main game container, but Agones only maps ports to the main game container right now. This PR adds support for specifying a "ContainerName" in the GameServerPort object. It will default to the main game container if omitted so should be backwards compatible with existing configs.
Example
Using a modified simple-udp
fleet.yaml
gives a gameserver with ports allocated to both containers. (I rannc
inside alpine to avoid docker networking issues with KinD)Game Server Description:
fleet.yaml