Skip to content

Commit

Permalink
fix: show pickups on map (#1477)
Browse files Browse the repository at this point in the history
* fix: set game settings in annotations

* fix game manager test
  • Loading branch information
razvan-pro committed Mar 5, 2021
1 parent a785ade commit 57bdb08
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
13 changes: 4 additions & 9 deletions aimmo-game-creator/game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ def _delete_game_secret(self, game_id):
self.api.delete_namespaced_secret(resource.metadata.name, K8S_NAMESPACE)

def _create_game_server_allocation(
self, game_id: int, worksheet_id: int, retry_count: int = 0
self, game_id: int, game_data: dict, retry_count: int = 0
) -> str:
result = self.custom_objects_api.create_namespaced_custom_object(
group="allocation.agones.dev",
Expand All @@ -295,11 +295,8 @@ def _create_game_server_allocation(
"metadata": {
"labels": {
"game-id": game_id,
"worksheet_id": worksheet_id,
},
"annotations": {
"game-api-url": f"{self.games_url}{game_id}/",
},
"annotations": game_data,
},
},
},
Expand All @@ -310,7 +307,7 @@ def _create_game_server_allocation(
)
time.sleep(5)
return self._create_game_server_allocation(
game_id, worksheet_id, retry_count=retry_count + 1
game_id, game_data, retry_count=retry_count + 1
)
else:
return result["status"]["gameServerName"]
Expand All @@ -336,9 +333,7 @@ def _delete_game_server(self, game_id):

def create_game(self, game_id, game_data):
self._create_game_secret(game_id)
game_server_name = self._create_game_server_allocation(
game_id, game_data["worksheet_id"]
)
game_server_name = self._create_game_server_allocation(game_id, game_data)
self._create_game_service(game_id, game_server_name)
self._add_path_to_ingress(game_id)
LOGGER.info("Game started - {}".format(game_id))
Expand Down
6 changes: 4 additions & 2 deletions aimmo-game-creator/tests/test_game_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ def test_adding_a_game_creates_game_allocation(self):
"required": {"matchLabels": {"agones.dev/fleet": "aimmo-game"}},
"scheduling": "Packed",
"metadata": {
"labels": {"game-id": 1, "worksheet_id": 1},
"annotations": {"game-api-url": "http://test/*1/"},
"labels": {"game-id": 1},
"annotations": {
"worksheet_id": 1,
},
},
},
},
Expand Down
11 changes: 7 additions & 4 deletions aimmo-game/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import asyncio
import json
import logging
import os
from dataclasses import dataclass
Expand Down Expand Up @@ -173,7 +174,8 @@ async def _send_game_state(self, sid):


def create_runner(port, socketio_server, communicator: DjangoCommunicator):
generator = map_generator.Main({})
settings = json.loads(os.environ["settings"])
generator = getattr(map_generator, settings["GENERATOR"])(settings)
turn_collector = TurnCollector(socketio_server)
return GameRunner(
game_state_generator=generator.get_game_state,
Expand Down Expand Up @@ -230,9 +232,10 @@ async def wait_for_allocation(
labels: Dict[str, Any] = game_server_update.object_meta.labels
annotations: Dict[str, Any] = game_server_update.object_meta.annotations
game_id = labels["game-id"]
os.environ["worksheet_id"] = labels["worksheet_id"]
os.environ["GAME_API_URL"] = annotations["game-api-url"]
django_api_url = annotations["game-api-url"]
os.environ["worksheet_id"] = annotations["worksheet_id"]
os.environ["GAME_API_URL"] = annotations["GAME_API_URL"]
os.environ["settings"] = annotations["settings"]
django_api_url = annotations["GAME_API_URL"]
return GameAllocationInfo(game_id, django_api_url)


Expand Down

0 comments on commit 57bdb08

Please sign in to comment.