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

refactor simple game server #3817

Merged
merged 8 commits into from
Jun 25, 2024

Conversation

ashutosji
Copy link
Contributor

What type of PR is this? This is a refactor of existing code of simple game server present in examples folder.

Uncomment only one /kind <> line, press enter to put that in a new line, and remove leading whitespace from that line:

/kind breaking
/kind bug
/kind cleanup
/kind documentation
/kind feature
/kind hotfix
/kind release

What this PR does / Why we need it:

Which issue(s) this PR fixes: #3813

Closes #3813

Special notes for your reviewer:

@github-actions github-actions bot added kind/cleanup Refactoring code, fixing up documentation, etc size/XL labels May 10, 2024
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 72700498-8b76-4a75-8bea-5879ed4cd3a9

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3817/head:pr_3817 && git checkout pr_3817
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.41.0-dev-8b83ca3-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Approach looks good! Some nits, and some other ideas to try.

@@ -0,0 +1,331 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

Apache licence header please.

examples/simple-game-server/response-handler.go Outdated Show resolved Hide resolved
examples/simple-game-server/response-handler.go Outdated Show resolved Hide resolved
Comment on lines 16 to 21
func ready(s *sdk.SDK) {
err := s.Ready()
if err != nil {
log.Fatalf("Could not send ready message")
}
}
Copy link
Member

Choose a reason for hiding this comment

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

So I am noting that we have a pattern that looks like the above quite a bit - execute a function on the SDK, if it fails, log.Fatalf(...)

Not 100% sure how useful this would be - as it may only apply in a few places, but something like:

func runSDK(f func() err, failMsg string) {
   if err := f(); err != nil {
      log.Fatalf(failMsg + ": %v", err)
   }
}

Then this function could pretty much go away and you could do inline in handleReady

func handleReady(s *sdk.SDK, parts []string, _ ...context.CancelFunc) (response string, addACK bool, responseError error) {
   runSDK(func() err { return s.Ready() }, "Could not send ready message")
}

Since it's a closure, it could also handle anything taking in a series of arguments.

Where it goes fall over is if a SDK function returns several return values -- so it may not be worth it. But figured I'd show you my general idea, and see if it made sense -- save writing two functions for each command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I am noting that we have a pattern that looks like the above quite a bit - execute a function on the SDK, if it fails, log.Fatalf(...)

Not 100% sure how useful this would be - as it may only apply in a few places, but something like:

func runSDK(f func() err, failMsg string) {
   if err := f(); err != nil {
      log.Fatalf(failMsg + ": %v", err)
   }
}

Then this function could pretty much go away and you could do inline in handleReady

func handleReady(s *sdk.SDK, parts []string, _ ...context.CancelFunc) (response string, addACK bool, responseError error) {
   runSDK(func() err { return s.Ready() }, "Could not send ready message")
}

Since it's a closure, it could also handle anything taking in a series of arguments.

Where it goes fall over is if a SDK function returns several return values -- so it may not be worth it. But figured I'd show you my general idea, and see if it made sense -- save writing two functions for each command.

Ahan! I got it. I have added all the sdk functions inside the handlers.

@@ -0,0 +1,371 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

rename suggestion: handlers.go

@@ -0,0 +1,331 @@
package main
Copy link
Member

Choose a reason for hiding this comment

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

Rename suggestions : sdk.go (don't love it) - but helpers.go is a bit ambiguous. sdk.go gives some idea that this is where the sdk gets called.

Either that or pull it all into handers.go and put the SDK command under each handler? (or if need be, make it inline?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rename suggestions : sdk.go (don't love it) - but helpers.go is a bit ambiguous. sdk.go gives some idea that this is where the sdk gets called.

Either that or pull it all into handers.go and put the SDK command under each handler? (or if need be, make it inline?)

I have pulled everything inside handlers.go. sdk.go isn't required.
Thank you so much for your guidance.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 8b83ca3 to 7a03c71 Compare May 14, 2024 11:00
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: c54e02bb-849e-45cd-83ba-9885bf4fa113

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3817/head:pr_3817 && git checkout pr_3817
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.41.0-dev-7a03c71-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Looks good!

Will need an increment on the version number:

Will also need to update all the references to simple-game-server - but may want to test locally with some e2e tests before updating everything as we'll need to push a new version to prod.

@@ -0,0 +1,581 @@
// Copyright 2020 Google LLC All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2020 Google LLC All Rights Reserved.
// Copyright 2024 Google LLC All Rights Reserved.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 7a03c71 to 253638e Compare May 21, 2024 09:18
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@ashutosji
Copy link
Contributor Author

Looks good!

Will need an increment on the version number:

Will also need to update all the references to simple-game-server - but may want to test locally with some e2e tests before updating everything as we'll need to push a new version to prod.

I had tested few functionalities mentioned in this file: https://github.com/googleforgames/agones/blob/main/test/e2e/gameserver_test.go#L717.
Also, I had ran the command mentioned here: https://github.com/googleforgames/agones/blob/main/build/README.md#make-test-e2e and https://github.com/googleforgames/agones/blob/main/build/README.md#make-test-go.

Everything works perfectly to me. I was communicated with gameserver (https://agones.dev/site/docs/getting-started/create-gameserver/#3-connect-to-the-gameserver) the response was as expected.

Please, let me know what else i am missing for e2e test.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 2eb3c057-1ad5-4c69-9e20-40a830f1b884

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 253638e to 7c8810f Compare May 21, 2024 10:52
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: bdcd983b-76c0-4aba-be39-cbf32599be5f

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@ashutosji
Copy link
Contributor Author

Hi @markmandel,

Step #1 - "e2e-feature-gates":     framework.go:346: 
Step #1 - "e2e-feature-gates":         	Error Trace:	/go/src/agones.dev/agones/test/e2e/framework/framework.go:346
Step #1 - "e2e-feature-gates":         	            				/go/src/agones.dev/agones/test/e2e/allocator_test.go:77
Step #1 - "e2e-feature-gates":         	Error:      	Received unexpected error:
Step #1 - "e2e-feature-gates":         	            	context deadline exceeded
Step #1 - "e2e-feature-gates":         	Test:       	TestAllocatorWithDeprecatedRequired
Step #1 - "e2e-feature-gates":         	Messages:   	error waiting for fleet condition on fleet: simple-fleet-1.052xsd
Step #1 - "e2e-feature-gates": --- FAIL: TestAllocatorWithDeprecatedRequired (302.54s)
Step #1 - "e2e-feature-gates": FAIL test/e2e.TestAllocatorWithDeprecatedRequired (302.54s)

Could you please guide why this is failing. There are other functions also failing in allocator_test.go file.
I am not getting why it is failing.

@igooch
Copy link
Collaborator

igooch commented May 21, 2024

Could you please guide why this is failing. There are other functions also failing in allocator_test.go file. I am not getting why it is failing.

It's possible it's failing because the simple game server image 0.33 is not in the Agones artifact registry yet. You can test if that's the issue locally by pushing the simple game server image to your dev project's artifact registry https://github.com/googleforgames/agones/blob/main/examples/simple-game-server/Makefile and temporarily changing the image to your repo image

viper.SetDefault(gsimageFlag, "us-docker.pkg.dev/agones-images/examples/simple-game-server:0.32")
and running the tests on your cluster.

@markmandel
Copy link
Member

As part of this PR, try out the approach(es) in #3836 and see if they work for you 👍🏻

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 7c8810f to 636f807 Compare May 31, 2024 10:27
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: ded8d76c-7d0f-4290-bf8e-6b840b5f906b

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 636f807 to 3ee108f Compare May 31, 2024 10:45
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 93ea63f6-853d-4104-a5af-6fa11f8b1d70

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

build/Makefile Outdated
@@ -64,7 +64,7 @@ KIND_PROFILE ?= agones
KIND_CONTAINER_NAME=$(KIND_PROFILE)-control-plane

# Game Server image to use while doing end-to-end tests
GS_TEST_IMAGE ?= us-docker.pkg.dev/agones-images/examples/simple-game-server:0.32
GS_TEST_IMAGE ?= us-central1-docker.pkg.dev/agones-ashutoshnsingh/example/simple-game-server:0.33-dev-linux-amd64
Copy link
Member

Choose a reason for hiding this comment

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

I expect this won't work, since the agones-images project doesn't have access to your artifact registry.

You could make it public if yo u desired though 😄 at least temporarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot @markmandel. It worked perfectly.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 3ee108f to e2f17f4 Compare June 3, 2024 10:51
Copy link

github-actions bot commented Jun 3, 2024

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: cbe7023a-7c96-4571-870d-a23ed4285820

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from e2f17f4 to 42c7843 Compare June 11, 2024 05:53
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Failed 😱

Build Id: 30608748-02a4-49c9-8040-fc7115fbe729

To get permission to view the Cloud Build view, join the agones-discuss Google Group.

Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 254786fa-3d32-4495-8ee8-ae24ac80f490

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3817/head:pr_3817 && git checkout pr_3817
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.42.0-dev-5a1d70b-amd64

Copy link
Member

@markmandel markmandel left a comment

Choose a reason for hiding this comment

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

Looks great! Let's get the new image up to prod and switch over to using it 👍🏻

@@ -799,7 +799,7 @@ func (f *Framework) DefaultGameServer(namespace string) *agonesv1.GameServer {
Containers: []corev1.Container{{
Name: "game-server",
Image: f.GameServerImage,
ImagePullPolicy: corev1.PullIfNotPresent,
ImagePullPolicy: corev1.PullAlways,
Copy link
Member

Choose a reason for hiding this comment

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

Before we close off this PR, let's move this back to PullIfNotPresent

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! Added the new image to prod. Also updated the new image in all the files. Could you please review it and merge it?

@ashutosji ashutosji force-pushed the refactor-simple-game-server branch from 5a1d70b to 1614bf0 Compare June 17, 2024 10:59
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: a494d89a-3aca-44ed-a13d-453fef3833a1

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3817/head:pr_3817 && git checkout pr_3817
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.42.0-dev-1614bf0-amd64

@ashutosji ashutosji marked this pull request as ready for review June 18, 2024 12:27
Copy link
Collaborator

@igooch igooch left a comment

Choose a reason for hiding this comment

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

LGTM

@markmandel markmandel enabled auto-merge (squash) June 25, 2024 00:33
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@agones-bot
Copy link
Collaborator

Build Succeeded 👏

Build Id: 5f5f5998-b3b5-4c2f-9152-491a909ffe58

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:

  • git fetch https://github.com/googleforgames/agones.git pull/3817/head:pr_3817 && git checkout pr_3817
  • helm install agones ./install/helm/agones --namespace agones-system --set agones.image.registry=us-docker.pkg.dev/agones-images/ci --set agones.image.tag=1.42.0-dev-8bec16b-amd64

@markmandel markmandel merged commit d8689db into googleforgames:main Jun 25, 2024
3 of 4 checks passed
spiceratops added a commit to spiceratops/k8s-gitops that referenced this pull request Jul 23, 2024
This PR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [agones](https://agones.dev)
([source](https://github.com/googleforgames/agones)) | minor |
`1.41.0` -> `1.42.0` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>googleforgames/agones (agones)</summary>

###
[`v1.42.0`](https://github.com/googleforgames/agones/blob/HEAD/CHANGELOG.md#v1420-2024-07-16)

[Compare
Source](https://github.com/googleforgames/agones/compare/v1.41.0...v1.42.0)

[Full
Changelog](https://github.com/googleforgames/agones/compare/v1.41.0...v1.42.0)

**Breaking changes:**

- Update csharp.md to indicate ConnectAsync is deprecated by
[@&#8203;aallbrig](https://github.com/aallbrig) in
[googleforgames/agones#3866

**Implemented enhancements:**

- Add security context to Agones containers by
[@&#8203;peterzhongyi](https://github.com/peterzhongyi) in
[googleforgames/agones#3856
- Add Security Context to game server sidecar by
[@&#8203;peterzhongyi](https://github.com/peterzhongyi) in
[googleforgames/agones#3869
- Drop CountsAndLists Data from the Fleet and Game Server Set When the
Flag is False by [@&#8203;igooch](https://github.com/igooch) in
[googleforgames/agones#3881
- Adds tests to confirm that Fleet, Fleet Autoscaler, and Fleet
Allocation apply defaults code is idempotent by
[@&#8203;igooch](https://github.com/igooch) in
[googleforgames/agones#3888
- feat: Add CRD Changes and Feature Flag for chain policy by
[@&#8203;indexjoseph](https://github.com/indexjoseph) in
[googleforgames/agones#3880

**Fixed bugs:**

- sdk-server expects SDK_LOG_LEVEL by
[@&#8203;KAllan357](https://github.com/KAllan357) in
[googleforgames/agones#3858
- this will resolve From/layer extraction issue on ltsc2019 in examples
by [@&#8203;ashutosji](https://github.com/ashutosji) in
[googleforgames/agones#3873
- featuregate: adds validation if PortPolicyNone is not enabled by
[@&#8203;daniellee](https://github.com/daniellee) in
[googleforgames/agones#3871
- added local as default for registry when registry is not specified by
[@&#8203;kamaljeeti](https://github.com/kamaljeeti) in
[googleforgames/agones#3876
- Buffer Unity SDK ReceiveData when watching for configuration changes
by [@&#8203;ZeroParticle](https://github.com/ZeroParticle) in
[googleforgames/agones#3872
- agones-{extensions,allocator}: Make servers context aware by
[@&#8203;zmerlynn](https://github.com/zmerlynn) in
[googleforgames/agones#3845
- added condition for distributed logic by
[@&#8203;ashutosji](https://github.com/ashutosji) in
[googleforgames/agones#3877

**Security fixes:**

- Bump [@&#8203;grpc/grpc-js](https://github.com/grpc/grpc-js) from
1.10.7 to 1.10.9 in /sdks/nodejs by
[@&#8203;dependabot](https://github.com/dependabot) in
[googleforgames/agones#3863

**Other:**

- Preparation for Release v1.42.0 by
[@&#8203;ashutosji](https://github.com/ashutosji) in
[googleforgames/agones#3854
- Add helpful note to edit-first-gameserver-go by
[@&#8203;peterzhongyi](https://github.com/peterzhongyi) in
[googleforgames/agones#3846
- Moved Passthrough feature description to the correct section in
Feature Stages by [@&#8203;vicentefb](https://github.com/vicentefb) in
[googleforgames/agones#3861
- Updated Node.js Page to Reflect that Counters and Lists is Implemented
by [@&#8203;ashutosji](https://github.com/ashutosji) in
[googleforgames/agones#3865
- Change Slack channel description from #developers to #development by
[@&#8203;branhoff](https://github.com/branhoff) in
[googleforgames/agones#3868
- updated UpdateList documentation for local sdk server and sdk server
by [@&#8203;ashutosji](https://github.com/ashutosji) in
[googleforgames/agones#3878
- Add zio-agones to the list of third party client SDKs by
[@&#8203;ghostdogpr](https://github.com/ghostdogpr) in
[googleforgames/agones#3875
- refactor simple game server by
[@&#8203;ashutosji](https://github.com/ashutosji) in
[googleforgames/agones#3817
- Update Slack invite link by
[@&#8203;markmandel](https://github.com/markmandel) in
[googleforgames/agones#3896
- Added cleanup for app-engine services in cloudbuild script by
[@&#8203;kamaljeeti](https://github.com/kamaljeeti) in
[googleforgames/agones#3890
- Adds a command to generate the zz_generated.deepcopy.go files for the
apis by [@&#8203;igooch](https://github.com/igooch) in
[googleforgames/agones#3900
- update go version to 1.21.12 by
[@&#8203;ashutosji](https://github.com/ashutosji) in
[googleforgames/agones#3894

**New Contributors:**

- [@&#8203;KAllan357](https://github.com/KAllan357) made their first
contribution in
[googleforgames/agones#3858
- [@&#8203;branhoff](https://github.com/branhoff) made their first
contribution in
[googleforgames/agones#3868
- [@&#8203;aallbrig](https://github.com/aallbrig) made their first
contribution in
[googleforgames/agones#3866
- [@&#8203;ZeroParticle](https://github.com/ZeroParticle) made their
first contribution in
[googleforgames/agones#3872
- [@&#8203;ghostdogpr](https://github.com/ghostdogpr) made their first
contribution in
[googleforgames/agones#3875

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://github.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy40MzIuMCIsInVwZGF0ZWRJblZlciI6IjM3LjQzMi4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJyZW5vdmF0ZS9oZWxtIiwidHlwZS9taW5vciJdfQ==-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/cleanup Refactoring code, fixing up documentation, etc size/XL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor simple-game-server
4 participants