From 57bdb083c023d80c9cab3efcfe9039881a4c3ecf Mon Sep 17 00:00:00 2001 From: Razvan Mahu <67904187+razvan-pro@users.noreply.github.com> Date: Fri, 5 Mar 2021 11:00:20 +0000 Subject: [PATCH] fix: show pickups on map (#1477) * fix: set game settings in annotations * fix game manager test --- aimmo-game-creator/game_manager.py | 13 ++++--------- aimmo-game-creator/tests/test_game_manager.py | 6 ++++-- aimmo-game/service.py | 11 +++++++---- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/aimmo-game-creator/game_manager.py b/aimmo-game-creator/game_manager.py index e0ff2eab6..5296df6eb 100644 --- a/aimmo-game-creator/game_manager.py +++ b/aimmo-game-creator/game_manager.py @@ -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", @@ -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, }, }, }, @@ -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"] @@ -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)) diff --git a/aimmo-game-creator/tests/test_game_manager.py b/aimmo-game-creator/tests/test_game_manager.py index 9cce4cd1b..a416c1ae3 100644 --- a/aimmo-game-creator/tests/test_game_manager.py +++ b/aimmo-game-creator/tests/test_game_manager.py @@ -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, + }, }, }, }, diff --git a/aimmo-game/service.py b/aimmo-game/service.py index aa1276240..e04c8ba7a 100644 --- a/aimmo-game/service.py +++ b/aimmo-game/service.py @@ -1,6 +1,7 @@ #!/usr/bin/env python import asyncio +import json import logging import os from dataclasses import dataclass @@ -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, @@ -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)