Beispiel #1
0
def create_game(api, name, environment_variables):
    rc = ReplicationController(
        api,
        {
            'kind': 'ReplicationController',
            'apiVersion': 'v1',
            'metadata': {
                'name': name,
                'namespace': 'default',
                'labels': {
                    'app': 'aimmo-game',
                    'game': name,
                },
            },
            'spec': {
                'replicas': 1,
                'selector': {
                    'app': 'aimmo-game',
                    'game': name,
                },
                'template': {
                    'metadata': {
                        'labels': {
                            'app': 'aimmo-game',
                            'game': name,
                        },
                    },
                    'spec': {
                        'containers': [
                            {
                                'env': [
                                    {
                                        'name': env_name,
                                        'value': env_value,
                                    } for env_name, env_value in environment_variables.items()
                                ],
                                'image': 'ocadotechnology/aimmo-game:latest',
                                'ports': [
                                    {
                                        'containerPort': 80,
                                    },
                                ],
                                'name': 'aimmo-game',
                            },
                        ],
                    },
                },
            },
        },
    )

    rc.create()
Beispiel #2
0
def select_set(name_set, api, namespace, type_balance, cookie, type_set):
    if type_set == "statefulset":
        pre_set = StatefulSet.objects(api).filter(namespace=namespace)
    elif type_set == "rc":
        pre_set = ReplicationController.objects(api).filter(
            namespace=namespace)
    list_set = []
    for s in pre_set.response['items']:
        try:
            dic_set = {}
            dic_set["name"] = s["metadata"]["name"]
            dic_set["replicas"] = s["status"]["replicas"]
            dic_set["cookie"] = cookie
            dic_set["type_balance"] = type_balance
            dic_set["ports"] = s["spec"]["template"]["spec"]["containers"][0][
                "ports"]
            if True:
                if name_set != "allsets":
                    if name_set == dic_set["name"]:
                        list_set.append(dic_set)
                elif name_set == "allsets":
                    pass
        except:
            system("echo [ERROR] Error to add %s" % (s["metadata"]["name"]))
    return list_set
Beispiel #3
0
    def start(self, object_type, object_file_path, force=False):

        if not self.api:
            logging.info('API Client does not exist')
            return

        with open(object_file_path) as json_data:
            json_file = json.load(json_data)

        if object_type is KubernetesObjects.POD:

            pod = Pod(self.api, json_file)
            self._recreate_object(pod, force)
            self._add_object_to_kube_objects_dict('pods', pod)

        elif object_type is KubernetesObjects.SERVICE:

            service = Service(self.api, json_file)
            self._recreate_object(service, force)
            self._add_object_to_kube_objects_dict('services', service)

        elif object_type is KubernetesObjects.REPLICATION_CONTROLLER:

            rc = ReplicationController(self.api, json_file)
            self._recreate_object(rc, force)
            self._add_object_to_kube_objects_dict('rcs', rc)
Beispiel #4
0
def maintain_games(api, games):
    current_game_names = set()
    for game in ReplicationController.objects(api).filter(selector={'app': 'aimmo-game'}):
        current_game_names.add(game.name)
        if game.name not in games:
            LOGGER.info("Deleting game %s", game.name)
            game.delete()
    for game_id, game_config in games.items():
        if game_id not in current_game_names:
            LOGGER.info("Creating game %s", game_id)
            create_game(api, game_id, game_config)
Beispiel #5
0
def create_game_rc(api, name, environment_variables):
    environment_variables['SOCKETIO_RESOURCE'] = "game/%s/socket.io" % name
    environment_variables['GAME_API_URL'] = os.environ.get('GAME_API_URL', 'https://staging-dot-decent-digit-629.appspot.com/aimmo/api/games/')
    environment_variables['GAME_NAME'] = name
    environment_variables['GAME_URL'] = "http://game-%s" % name
    environment_variables['PYKUBE_KUBERNETES_SERVICE_HOST'] = 'kubernetes'
    environment_variables['IMAGE_SUFFIX'] = os.environ.get('IMAGE_SUFFIX', 'latest')
    rc = ReplicationController(
        api,
        {
            'kind': 'ReplicationController',
            'apiVersion': 'v1',
            'metadata': {
                'name': "game-%s" % name,
                'namespace': 'default',
                'labels': {
                    'app': 'aimmo-game',
                    'game': name,
                },
            },
            'spec': {
                'replicas': 1,
                'selector': {
                    'app': 'aimmo-game',
                    'game': name,
                },
                'template': {
                    'metadata': {
                        'labels': {
                            'app': 'aimmo-game',
                            'game': name,
                        },
                    },
                    'spec': {
                        'containers': [
                            {
                                'env': [
                                    {
                                        'name': env_name,
                                        'value': env_value,
                                    } for env_name, env_value in environment_variables.items()
                                ],
                                'image': 'ocadotechnology/aimmo-game:%s' % os.environ.get('IMAGE_SUFFIX', 'latest'),
                                'ports': [
                                    {
                                        'containerPort': 5000,
                                    },
                                ],
                                'name': 'aimmo-game',
                                'resources': {
                                    'limits': {
                                        'cpu': '1000m',
                                        'memory': '128Mi',
                                    },
                                    'requests': {
                                        'cpu': '100m',
                                        'memory': '64Mi',
                                    },
                                },
                            },
                        ],
                    },
                },
            },
        },
    )
    rc.create()
Beispiel #6
0
def create_game_rc(api, name, environment_variables):
    environment_variables['SOCKETIO_RESOURCE'] = "game/%s/socket.io" % name
    environment_variables['GAME_API_URL'] = os.environ.get(
        'GAME_API_URL',
        'https://staging-dot-decent-digit-629.appspot.com/aimmo/api/games/')
    environment_variables['GAME_NAME'] = name
    environment_variables['GAME_URL'] = "http://game-%s" % name
    environment_variables['PYKUBE_KUBERNETES_SERVICE_HOST'] = 'kubernetes'
    environment_variables['IMAGE_SUFFIX'] = os.environ.get(
        'IMAGE_SUFFIX', 'latest')
    rc = ReplicationController(
        api,
        {
            'kind': 'ReplicationController',
            'apiVersion': 'v1',
            'metadata': {
                'name': "game-%s" % name,
                'namespace': 'default',
                'labels': {
                    'app': 'aimmo-game',
                    'game': name,
                },
            },
            'spec': {
                'replicas': 1,
                'selector': {
                    'app': 'aimmo-game',
                    'game': name,
                },
                'template': {
                    'metadata': {
                        'labels': {
                            'app': 'aimmo-game',
                            'game': name,
                        },
                    },
                    'spec': {
                        'containers': [
                            {
                                'env': [{
                                    'name': env_name,
                                    'value': env_value,
                                } for env_name, env_value in
                                        environment_variables.items()],
                                'image':
                                'ocadotechnology/aimmo-game:%s' %
                                os.environ.get('IMAGE_SUFFIX', 'latest'),
                                'ports': [
                                    {
                                        'containerPort': 5000,
                                    },
                                ],
                                'name':
                                'aimmo-game',
                                'resources': {
                                    'limits': {
                                        'cpu': '1000m',
                                        'memory': '128Mi',
                                    },
                                    'requests': {
                                        'cpu': '100m',
                                        'memory': '64Mi',
                                    },
                                },
                            },
                        ],
                    },
                },
            },
        },
    )
    rc.create()