Exemplo n.º 1
0
def setup_autoscaler(expander='random',
                     min_nodes=1,
                     max_nodes=10,
                     zone='',
                     node_pool='default-pool'):
    from ckan_cloud_operator.drivers.helm import driver as helm_driver
    from ckan_cloud_operator.providers import manager as providers_manager

    cloud_provider = get_provider_id()
    cluster_name = kubectl.check_output(
        'config current-context').decode().replace('\n', '')

    if cloud_provider == 'gcloud':
        """GKE has built-in autoscaler"""
        from ckan_cloud_operator import gcloud

        gcloud.check_call(
            f'container clusters update {cluster_name} --enable-autoscaling --min-nodes {min_nodes} --max-nodes {max_nodes} --zone {zone} --node_pool {node_pool}'
        )
        return

    values = {
        'image.tag': 'v1.13.1',
        'autoDiscovery.clusterName': cluster_name,
        'extraArgs.balance-similar-node-groups': 'false',
        'extraArgs.expander': expander,
        'cloudProvider': cloud_provider,
        'rbac.create': 'true'
    }
    if values['cloudProvider'] == 'aws':
        zone = providers_manager.get_provider('cluster').get_info().get('zone')
        while not zone:
            zone = input('Enter the AWS cluster region: ')
        values['awsRegion'] = zone.strip()

    helm_driver.deploy(
        tiller_namespace='kube-system',
        chart_repo='https://kubernetes-charts.storage.googleapis.com',
        chart_name='stable/cluster-autoscaler',
        chart_version='',
        release_name='cluster-autoscaler',
        namespace='kube-system',
        chart_repo_name='stable',
        values=values)
Exemplo n.º 2
0
def deploy_storage_permissions_function():
    """Deploys a serverless function that sets all keys to private"""
    ckan_infra = CkanInfra()
    bucket_name = ckan_infra.GCLOUD_STORAGE_BUCKET
    project_id = ckan_infra.GCLOUD_AUTH_PROJECT
    function_name = bucket_name.replace('-', '') + 'permissions'
    function_js = PERMISSIONS_FUNCTION_JS(function_name, project_id,
                                          bucket_name)
    package_json = PERMISSIONS_FUNCTION_PACKAGE_JSON
    with tempfile.TemporaryDirectory() as tmpdir:
        with open(f'{tmpdir}/package.json', 'w') as f:
            f.write(package_json)
        with open(f'{tmpdir}/index.js', 'w') as f:
            f.write(function_js)
        gcloud.check_call(
            f'functions deploy {function_name} '
            f'--runtime nodejs6 '
            f'--trigger-resource {bucket_name} '
            f'--trigger-event google.storage.object.finalize '
            f'--source {tmpdir} '
            f'--retry '
            f'--timeout 30s ',
            ckan_infra=ckan_infra)