Esempio n. 1
0
def _helm_deploy(values,
                 tiller_namespace_name,
                 chart_repo,
                 chart_name,
                 chart_version,
                 release_name,
                 instance_id,
                 dry_run=False,
                 chart_repo_name=None):
    assert chart_repo_name, 'chart-repo-name is required'
    helm_driver.init(tiller_namespace_name)
    logs.info(
        f'Deploying helm chart {chart_repo_name} {chart_repo} {chart_version} {chart_name} to release {release_name} '
        f'(instance_id={instance_id})')
    with tempfile.NamedTemporaryFile('w') as f:
        yaml.dump(values, f, default_flow_style=False)
        f.flush()
        helm_driver.deploy(tiller_namespace=tiller_namespace_name,
                           chart_repo=chart_repo,
                           chart_name=chart_name,
                           chart_version=chart_version,
                           release_name=release_name,
                           values_filename=f.name,
                           namespace=instance_id,
                           dry_run=dry_run,
                           chart_repo_name=chart_repo_name)
Esempio n. 2
0
def _helm_deploy(values, tiller_namespace_name, ckan_helm_chart_repo, ckan_helm_chart_version, ckan_helm_release_name,
                 instance_id, dry_run=False):
    logs.debug(f'Deploying helm chart {ckan_helm_chart_repo} {ckan_helm_chart_version} to release {ckan_helm_release_name} (instance_id={instance_id})')
    with tempfile.NamedTemporaryFile('w') as f:
        yaml.dump(values, f, default_flow_style=False)
        f.flush()
        helm_driver.deploy(tiller_namespace_name, ckan_helm_chart_repo, 'ckan-cloud/ckan', ckan_helm_chart_version,
                           ckan_helm_release_name, f.name, instance_id, dry_run=dry_run)
def _helm_deploy(values, tiller_namespace_name, ckan_helm_chart_repo,
                 ckan_helm_chart_version, ckan_helm_release_name, instance_id):
    with tempfile.NamedTemporaryFile('w') as f:
        yaml.dump(values, f, default_flow_style=False)
        f.flush()
        helm_driver.deploy(tiller_namespace_name, ckan_helm_chart_repo,
                           'ckan-cloud/ckan', ckan_helm_chart_version,
                           ckan_helm_release_name, f.name, instance_id)
def update(instance_id, instance):
    tiller_namespace_name = _get_resource_name()
    _init_namespace(instance_id)
    _init_ckan_infra_secret(instance_id)
    ckan_helm_chart_repo = instance['spec'].get(
        "ckanHelmChartRepo",
        "https://raw.githubusercontent.com/ViderumGlobal/ckan-cloud-helm/master/charts_repository"
    )
    ckan_helm_chart_version = instance['spec'].get("ckanHelmChartVersion", "")
    ckan_helm_release_name = f'ckan-cloud-{instance_id}'
    instance['spec']['centralizedSolrHost'], instance['spec'][
        'centralizedSolrPort'] = _init_solr(instance_id)
    with tempfile.NamedTemporaryFile('w') as f:
        yaml.dump(instance['spec'], f, default_flow_style=False)
        f.flush()
        helm_driver.deploy(tiller_namespace_name, ckan_helm_chart_repo,
                           'ckan-cloud/ckan', ckan_helm_chart_version,
                           ckan_helm_release_name, f.name, instance_id)
Esempio n. 5
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)