space-agon icon indicating copy to clipboard operation
space-agon copied to clipboard

Migrate Space Agon Demo from using Open Match 1 to Open Match 2

Open peterzhongyi opened this issue 5 months ago • 0 comments

This pull request changes the Space Agon's match making logic from using Open Match 1 to Open Match 2(https://github.com/googleforgames/open-match2/blob/main)

Key files to review:

  1. director/director.go
  2. frontend/frontend.go
  3. mmf/mmf.go
  4. install/helm/space-agon/templates && install/helm/space-agon/values.yaml
  5. omclient/omclient.go - mostly copied from https://github.com/googleforgames/open-match-ecosystem/blob/v2.0/v2/internal/omclient/omclient.go, but added an initializer and assignment related APIs.
  6. logging/logging.go - completely copied from https://github.com/googleforgames/open-match-ecosystem/blob/v2.0/v2/internal/logging/logging.go.

Key differences between OM1 and OM2:

  1. Frontend and Director communicates with OM1 via gRPC, but use HTTP to communicate with OM2. Thus the omclient.go and logging.go was created.
  2. OM1 was previously deployed in Kubernetes via helm, but OM2 is now deployed on Cloud Run (https://github.com/googleforgames/open-match2/blob/main/docs/DEVELOPMENT.md).
  3. Redis was previously deployed in Kubernetes via helm, but is now deployed on Memorystore on Pantheon UI.
  4. MMF is now an internal load balancer service because OM2 is not on Kubernetes.

Two tests are intentionally left out in the pull request:

  1. Frontend/frontend_test.go was deleted because the OM2 repo doesn't provide a omtest tool anymore, and the test itself isn't originally covering a lot of the code logic either.
  2. The integration test was skipped in the PR checks because the process of deploying the Space Agon demo has changed a lot, and since OM2 and Redis are no longer deployed on Kubernetes, it is more complicated to set up for the integration test to run. Also, once it's all set up, it's more reasonable to test the demo just by running it, rather than running the integration test.

To run the demo with this PR, first follow the README to until you installed Agones. Then instead of installing Open Match with make openmatch-install, follow the steps below to install OM2:

  1. Find the region of your Kubernetes Cluster, and use this region for the steps below.
  2. Create a Redis instance in Memorystore on Pantheon UI.
  3. Deploy OM2 by cloning the https://github.com/googleforgames/open-match2/blob/main repo and following the docs/DEVELOPMENT.md file to install OM2. You need to replace the IP address of the OM_REDIS_WRITE_HOST and OM_REDIS_READ_HOST in the service.yaml file to be the IP address of the Redis instance you created.

Now to allow your frontend to talk to the OM2 you installed:

  1. Create a Google Service Account in your project and give it the Cloud Run Invoker role
  2. Replace the value of iam.gke.io/gcp-service-account field in frontend.yaml to be the Google Service Account you created.
  3. Bind the Kubernetes Service Account in frontend.yaml to the Google Service Account(in the form of SERVICE_ACCOUNT_NAME@PROJECT_ID.iam.gserviceaccount.com) with
gcloud iam service-accounts add-iam-policy-binding   --role roles/iam.workloadIdentityUser   --member "serviceAccount:PROJECT_ID.svc.id.goog[default/frontend-sa]"   YOUR_GOOGLE_SERVICE_ACCOUNT
  1. In install/helm/space-agon/values.yaml, change the omCoreAddress field of frontend to be the address of you OM2 service on Cloud Run.

Because the MMF server are now called from Cloud Run instead of Kubernetes Cluster, the MMF needs to have an IP that the director needs to know when the director is starting up. To do this,

  1. Reserve an internal IP address for you project in Pantheon UI.
  2. In install/helm/space-agon/values.yaml, replace the ipAddress field for mmf and the mmfAddress field for director to be the IP address that you just reserved.
  3. In install/helm/space-agon/values.yaml, change the omCoreAddress field of director to be the address of you OM2 service on Cloud Run.

Now in the root directory of the demo and use make build && make install to start the Space Agon demo. NOTE: after you have the external IP address of the frontend service, open two chrome windows so you can see them AT THE SAME TIME, and click Find Game. If you can't see both tabs at the same time, the demo's client has a bug that will connect to a match several times.

Towards #50

peterzhongyi avatar Sep 17 '24 18:09 peterzhongyi