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)
    if annotations_manager.get_status(instance, 'helm', 'created'):
        values = instance['spec']
    else:
        values = {
            **instance['spec'], "replicas": 1,
            "nginxReplicas": 1,
            "disableJobs": True,
            "noProbes": True
        }
    _helm_deploy(values, tiller_namespace_name, ckan_helm_chart_repo,
                 ckan_helm_chart_version, ckan_helm_release_name, instance_id)
    _wait_instance_events(instance_id)
    instance = crds_manager.get(INSTANCE_CRD_SINGULAR, name=instance_id)
    if not annotations_manager.get_status(instance, 'helm', 'created'):
        annotations_manager.set_status(instance, 'helm', 'created')
        _helm_deploy(instance['spec'], tiller_namespace_name,
                     ckan_helm_chart_repo, ckan_helm_chart_version,
                     ckan_helm_release_name, instance_id)
def update(instance_id, instance, force=False, dry_run=False):
    tiller_namespace_name = _get_resource_name()
    logs.debug('Updating helm-based instance deployment',
               instance_id=instance_id,
               tiller_namespace_name=tiller_namespace_name)
    _create_private_container_registry_secret(instance_id)
    _init_ckan_infra_secret(instance_id, dry_run=dry_run)
    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}'
    solr_schema = instance['spec'].get("ckanSolrSchema", "ckan_default")
    solr_host, solr_port = _init_solr(
        instance_id,
        solr_schema,
        dry_run=dry_run,
    )
    logs.debug(ckan_helm_chart_repo=ckan_helm_chart_repo,
               ckan_helm_chart_version=ckan_helm_chart_version,
               ckan_helm_release_name=ckan_helm_release_name,
               solr_host=solr_host,
               solr_port=solr_port)
    instance['spec']['centralizedSolrHost'], instance['spec'][
        'centralizedSolrPort'] = solr_host, solr_port
    if annotations_manager.get_status(instance, 'helm', 'created'):
        logs.info('Updating existing instance')
        values = instance['spec']
    else:
        logs.info(
            'New instance, deploying first with 1 replica and disabled probes and jobs'
        )
        values = {
            **instance['spec'], "replicas": 1,
            "nginxReplicas": 1,
            "disableJobs": True,
            "noProbes": True,
            "enableHarvesterNG": False
        }
    _helm_deploy(values,
                 tiller_namespace_name,
                 ckan_helm_chart_repo,
                 ckan_helm_chart_version,
                 ckan_helm_release_name,
                 instance_id,
                 dry_run=dry_run)
    if not dry_run:
        _wait_instance_events(instance_id)
        instance = crds_manager.get(INSTANCE_CRD_SINGULAR, name=instance_id)
        if not annotations_manager.get_status(instance, 'helm', 'created'):
            annotations_manager.set_status(instance, 'helm', 'created')
            _helm_deploy(instance['spec'], tiller_namespace_name,
                         ckan_helm_chart_repo, ckan_helm_chart_version,
                         ckan_helm_release_name, instance_id)
            _scale_down_scale_up(namespace=instance_id,
                                 replicas=values.get('replicas', 1))