Exemple #1
0
def load_config(config_data):
    if 'k8s' not in config_data:
        config_data['k8s'] = {}

    if 'runtime_cpu' not in config_data['k8s']:
        config_data['k8s']['runtime_cpu'] = RUNTIME_CPU
    if 'runtime_memory' not in config_data['k8s']:
        config_data['k8s']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['k8s']:
        config_data['k8s']['runtime_timeout'] = RUNTIME_TIMEOUT
    if 'runtime' not in config_data['k8s']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['k8s']:
            config_data['k8s']['docker_user'] = get_docker_username()
        if not config_data['k8s']['docker_user']:
            raise Exception(
                'You must execute "docker login" or provide "docker_user" '
                'param in config under "k8s" section')
        docker_user = config_data['k8s']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['k8s']['runtime'] = runtime_name

    if 'workers' not in config_data['lithops'] or \
       config_data['lithops']['workers'] > MAX_CONCURRENT_WORKERS:
        config_data['lithops']['workers'] = MAX_CONCURRENT_WORKERS
Exemple #2
0
def load_config(config_data):
    for key in DEFAULT_CONFIG_KEYS:
        if key not in config_data['knative']:
            config_data['knative'][key] = DEFAULT_CONFIG_KEYS[key]

    config_data['knative']['invoke_pool_threads'] = config_data['knative'][
        'max_workers']

    if 'git_url' not in config_data['knative']:
        config_data['knative']['git_url'] = BUILD_GIT_URL
    if 'git_rev' not in config_data['knative']:
        revision = 'master' if 'dev' in __version__ else __version__
        config_data['knative']['git_rev'] = revision

    if 'runtime' not in config_data['knative']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['knative']:
            config_data['knative']['docker_user'] = get_docker_username()
        if not config_data['knative']['docker_user']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')
        docker_user = config_data['knative']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['knative']['runtime'] = runtime_name
Exemple #3
0
def load_config(config_data):
    if 'code_engine' not in config_data:
        config_data['code_engine'] = {}

    if 'kubectl_config' in config_data['code_engine']:
        print(
            '"kubectl_config" variable in config is deprecated, use "kubecfg_path" instead'
        )
        config_data['code_engine']['kubecfg_path'] = config_data[
            'code_engine']['kubectl_config']

    if 'cpu' not in config_data['code_engine']:
        config_data['code_engine']['cpu'] = RUNTIME_CPU

    if 'container_registry' not in config_data['code_engine']:
        config_data['code_engine']['container_registry'] = CONTAINER_REGISTRY

    if 'runtime_memory' not in config_data['serverless']:
        config_data['serverless']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['serverless']:
        config_data['serverless']['runtime_timeout'] = RUNTIME_TIMEOUT

    if 'runtime' in config_data['code_engine']:
        config_data['serverless']['runtime'] = config_data['code_engine'][
            'runtime']
    if 'runtime' not in config_data['serverless']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            config_data['code_engine']['docker_user'] = get_docker_username()
        if not config_data['code_engine']['docker_user']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')
        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace(
            '.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME,
                                             python_version, revision)
        config_data['serverless']['runtime'] = runtime_name

    else:
        if config_data['serverless']['runtime'].count('/') > 1:
            # container registry is in the provided runtime name
            cr, rn = config_data['serverless']['runtime'].split('/', 1)
            config_data['code_engine']['container_registry'] = cr
            config_data['serverless']['runtime'] = rn

    config_data['serverless']['remote_invoker'] = True

    if 'workers' not in config_data['lithops'] or \
       config_data['lithops']['workers'] > MAX_CONCURRENT_WORKERS:
        config_data['lithops']['workers'] = MAX_CONCURRENT_WORKERS

    if 'invoke_pool_threads' not in config_data['code_engine']:
        config_data['code_engine'][
            'invoke_pool_threads'] = INVOKE_POOL_THREADS_DEFAULT
    config_data['serverless']['invoke_pool_threads'] = config_data[
        'code_engine']['invoke_pool_threads']
Exemple #4
0
def load_config(config_data):
    if 'knative' not in config_data or not config_data['knative']:
        config_data['knative'] = {}

    if 'git_url' not in config_data['knative']:
        config_data['knative']['git_url'] = BUILD_GIT_URL
    if 'git_rev' not in config_data['knative']:
        revision = 'master' if 'dev' in __version__ else __version__
        config_data['knative']['git_rev'] = revision
    if 'container_registry' not in config_data['knative']:
        config_data['knative']['container_registry'] = CONTAINER_REGISTRY

    if 'cpu' not in config_data['knative']:
        config_data['knative']['cpu'] = RUNTIME_CPU
    if 'concurrency' not in config_data['knative']:
        config_data['knative']['concurrency'] = RUNTIME_CONCURRENCY
    if 'min_instances' not in config_data['knative']:
        config_data['knative']['min_instances'] = RUNTIME_MIN_INSTANCES
    if 'max_instances' not in config_data['knative']:
        config_data['knative']['max_instances'] = RUNTIME_MAX_INSTANCES

    if 'runtime_memory' not in config_data['serverless']:
        config_data['serverless']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['serverless']:
        config_data['serverless']['runtime_timeout'] = RUNTIME_TIMEOUT

    if 'runtime' in config_data['knative']:
        config_data['serverless']['runtime'] = config_data['knative']['runtime']

    if 'runtime' not in config_data['serverless']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['knative']:
            config_data['knative']['docker_user'] = get_docker_username()
        if not config_data['knative']['docker_user']:
            raise Exception('You must provide "docker_user" param in config '
                            'or execute "docker login"')
        docker_user = config_data['knative']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME, python_version, revision)
        config_data['serverless']['runtime'] = runtime_name
    else:
        if config_data['serverless']['runtime'].count('/') > 1:
            # container registry is in the provided runtime name
            cr, rn = config_data['serverless']['runtime'].split('/', 1)
            config_data['knative']['container_registry'] = cr
            config_data['serverless']['runtime'] = rn

    if 'workers' not in config_data['lithops']:
        max_instances = config_data['knative']['max_instances']
        concurrency = config_data['knative']['concurrency']
        config_data['lithops']['workers'] = int(max_instances * concurrency)

    if 'invoke_pool_threads' not in config_data['knative']:
        config_data['knative']['invoke_pool_threads'] = config_data['lithops']['workers']
    config_data['serverless']['invoke_pool_threads'] = config_data['knative']['invoke_pool_threads']
Exemple #5
0
def load_config(config_data):
    if 'code_engine' not in config_data:
        config_data['code_engine'] = {}

    if 'kubectl_config' in config_data['code_engine']:
        print('"kubectl_config" variable in code_engine config is deprecated, use "kubecfg_path" instead')
        config_data['code_engine']['kubecfg_path'] = config_data['code_engine']['kubectl_config']

    if 'cpu' in config_data['code_engine']:
        print('"cpu" variable in code_engine config is deprecated, use "runtime_cpu" instead')
        config_data['code_engine']['runtime_cpu'] = config_data['code_engine']['cpu']

    if 'ibm' in config_data and config_data['ibm'] is not None:
        config_data['code_engine'].update(config_data['ibm'])

    if 'runtime_cpu' not in config_data['code_engine']:
        config_data['code_engine']['runtime_cpu'] = RUNTIME_CPU
    if 'runtime_memory' not in config_data['code_engine']:
        config_data['code_engine']['runtime_memory'] = RUNTIME_MEMORY
    if 'runtime_timeout' not in config_data['code_engine']:
        config_data['code_engine']['runtime_timeout'] = RUNTIME_TIMEOUT
    if 'runtime' not in config_data['code_engine']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            config_data['code_engine']['docker_user'] = get_docker_username()
        if not config_data['code_engine']['docker_user']:
            raise Exception('You must execute "docker login" or provide "docker_user" '
                            'param in config under "code_engine" section')
        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME, python_version, revision)
        config_data['code_engine']['runtime'] = runtime_name

    runtime_cpu = config_data['code_engine']['runtime_cpu']
    if runtime_cpu not in VALID_CPU_VALUES:
        raise Exception('{} is an invalid runtime cpu value. Set one of: '
                        '{}'.format(runtime_cpu, VALID_CPU_VALUES))

    runtime_memory = config_data['code_engine']['runtime_memory']
    if runtime_memory not in VALID_MEMORY_VALUES:
        raise Exception('{} is an invalid runtime memory value in MB. Set one of: '
                        '{}'.format(runtime_memory, VALID_MEMORY_VALUES))

    region = config_data['code_engine'].get('region')
    if region and region not in VALID_REGIONS:
        raise Exception('{} is an invalid region name. Set one of: '
                        '{}'.format(region, VALID_REGIONS))

    if 'workers' not in config_data['lithops'] or \
       config_data['lithops']['workers'] > MAX_CONCURRENT_WORKERS:
        config_data['lithops']['workers'] = MAX_CONCURRENT_WORKERS
Exemple #6
0
def load_config(config_data):
    for key in DEFAULT_CONFIG_KEYS:
        if key not in config_data['k8s']:
            config_data['k8s'][key] = DEFAULT_CONFIG_KEYS[key]

    if 'runtime' not in config_data['k8s']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['k8s']:
            config_data['k8s']['docker_user'] = get_docker_username()
        if not config_data['k8s']['docker_user']:
            raise Exception('You must execute "docker login" or provide "docker_user" '
                            'param in config under "k8s" section')
        docker_user = config_data['k8s']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME, python_version, revision)
        config_data['k8s']['runtime'] = runtime_name
Exemple #7
0
def load_config(config_data):

    if 'ibm' in config_data and config_data['ibm'] is not None:
        config_data['code_engine'].update(config_data['ibm'])

    for key in DEFAULT_CONFIG_KEYS:
        if key not in config_data['code_engine']:
            config_data['code_engine'][key] = DEFAULT_CONFIG_KEYS[key]

    if 'runtime' not in config_data['code_engine']:
        if not DOCKER_PATH:
            raise Exception('docker command not found. Install docker or use '
                            'an already built runtime')
        if 'docker_user' not in config_data['code_engine']:
            config_data['code_engine']['docker_user'] = get_docker_username()
        if not config_data['code_engine']['docker_user']:
            raise Exception('You must execute "docker login" or provide "docker_user" '
                            'param in config under "code_engine" section')
        docker_user = config_data['code_engine']['docker_user']
        python_version = version_str(sys.version_info).replace('.', '')
        revision = 'latest' if 'dev' in __version__ else __version__.replace('.', '')
        runtime_name = '{}/{}-v{}:{}'.format(docker_user, RUNTIME_NAME, python_version, revision)
        config_data['code_engine']['runtime'] = runtime_name

    runtime_cpu = config_data['code_engine']['runtime_cpu']
    if runtime_cpu not in VALID_CPU_VALUES:
        raise Exception('{} is an invalid runtime cpu value. Set one of: '
                        '{}'.format(runtime_cpu, VALID_CPU_VALUES))

    runtime_memory = config_data['code_engine']['runtime_memory']
    if runtime_memory not in VALID_MEMORY_VALUES:
        raise Exception('{} is an invalid runtime memory value in MB. Set one of: '
                        '{}'.format(runtime_memory, VALID_MEMORY_VALUES))

    region = config_data['code_engine'].get('region')
    if region and region not in VALID_REGIONS:
        raise Exception('{} is an invalid region name. Set one of: '
                        '{}'.format(region, VALID_REGIONS))