Ejemplo n.º 1
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)
Ejemplo n.º 2
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()
Ejemplo n.º 3
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()