示例#1
0
def get_operator_version(verify=False):
    installed_image_tag = _get_installed_operator_image_tag()
    if verify:
        expected_image_tag = _get_expected_operator_image_tag()
        if not expected_image_tag:
            logs.info('No configmap created yet')
            return 'not-configured'
        if installed_image_tag and len(installed_image_tag) >= 2:
            if installed_image_tag != expected_image_tag:
                logs.error(
                    f'installed tag mismatch (expected={expected_image_tag}, actual={installed_image_tag})'
                )
                logs.info(
                    'delete the operator image tag file to skip this check: /etc/CKAN_CLOUD_OPERATOR_IMAGE_TAG'
                )
                logs.exit_catastrophic_failure()
        else:
            logs.error(
                "No version tag could be found. for local development, "
                "make sure you use correct version and run the following "
                "to create the file with correct version:\n\n"
                f"echo {expected_image_tag} | sudo tee /etc/CKAN_CLOUD_OPERATOR_IMAGE_TAG\n"
            )
            logs.exit_catastrophic_failure()
    return installed_image_tag
示例#2
0
def port_forward(db_prefix, all_daemon):
    if all_daemon:
        assert not db_prefix and all_daemon == 'I know the risks'
        subprocess.Popen(
            ['ckan-cloud-operator', 'db', 'proxy', 'port-forward'],
            stderr=subprocess.DEVNULL,
            stdout=subprocess.DEVNULL)
        for db_prefix in manager.get_provider().get_all_db_prefixes():
            subprocess.Popen([
                'ckan-cloud-operator', 'db', 'proxy', 'port-forward',
                '--db-prefix', db_prefix
            ],
                             stderr=subprocess.DEVNULL,
                             stdout=subprocess.DEVNULL)
    else:
        while True:
            start_time = datetime.datetime.now()
            try:
                manager.start_port_forward(db_prefix=db_prefix)
            except Exception:
                traceback.print_exc()
            end_time = datetime.datetime.now()
            if (end_time - start_time).total_seconds() < 10:
                logs.critical('DB Proxy failure')
                logs.exit_catastrophic_failure()
            else:
                logs.warning('Restarting the DB proxy')
示例#3
0
def port_forward():
    while True:
        start_time = datetime.datetime.now()
        try:
            manager.start_port_forward()
        except Exception:
            traceback.print_exc()
        end_time = datetime.datetime.now()
        if (end_time - start_time).total_seconds() < 10:
            logs.critical('DB Proxy failure')
            logs.exit_catastrophic_failure()
        else:
            logs.warning('Restarting the DB proxy')
def get_operator_version(verify=False):
    installed_image_tag = _get_installed_operator_image_tag()
    if verify:
        expected_image_tag = _get_expected_operator_image_tag()
        if installed_image_tag and len(installed_image_tag) >= 2:
            assert installed_image_tag == expected_image_tag, \
                f'installed tag mismatch (expected={expected_image_tag}, actual={installed_image_tag})'
        else:
            logs.error("No version tag could be found. for local development, "
                       "make sure you use correct version and run the following "
                       "to create the file with correct version:\n\n"
                       f"echo {expected_image_tag} | sudo tee /etc/CKAN_CLOUD_OPERATOR_IMAGE_TAG\n")
            logs.exit_catastrophic_failure()
    return installed_image_tag
示例#5
0
 def deis_instance_delete(instance_id, force):
     """Permanently delete the instances and all related infrastructure"""
     failed_instance_ids = []
     for id in instance_id:
         try:
             cls(id).delete(force)
         except Exception:
             traceback.print_exc()
             failed_instance_ids.append(id)
     if len(failed_instance_ids) > 0:
         logs.critical(f'Instance deletion failed for the following instance ids: {failed_instance_ids}')
         if not force:
             logs.exit_catastrophic_failure()
     great_success()
示例#6
0
def create_storage_class():
    if kubectl.get("storageclass/cca-ckan", required=False) is None:
        if _config_get("deploy-nfs-client-provisioner") == "yes":
            deploy_nfs_client_provisioner()
        else:
            logs.error("Missing cca-ckan storage class")
            logs.exit_catastrophic_failure()
    kubectl.apply({
        'apiVersion': 'storage.k8s.io/v1', 'kind': 'StorageClass',
        'metadata': {
            'name': 'cca-storage',
        },
        'provisioner': 'kubernetes.io/gce-pd',
        'reclaimPolicy': 'Delete',
        'volumeBindingMode': 'Immediate',
        'parameters': {
            'type': 'pd-standard',
        }
    })
示例#7
0
def get(what,
        *args,
        required=True,
        namespace='ckan-cloud',
        get_cmd='get',
        **kwargs):
    extra_args = ' '.join(args)
    extra_kwargs = ' '.join([f'{k} {v}' for k, v in kwargs.items()])
    try:
        return yaml.load(
            logs.subprocess_check_output(
                f'kubectl -n {namespace} {get_cmd} {what} {extra_args} -o yaml {extra_kwargs}',
                shell=True,
            ))
    except subprocess.CalledProcessError:
        if required:
            logs.exit_catastrophic_failure()
        else:
            return None
def print_event_exit_on_complete(event, details_msg, soft_exit=False):
    if not details_msg: details_msg = ''
    msg = event.pop('msg')
    step = event.pop('step')
    logs.info(f'{step}: {msg}')
    if len(event) > 0:
        logs.info(f'event metadata: {event}')
    event_completed_successfully = get_event_migration_complete_status(event)
    if event_completed_successfully:
        logs.info(f'Migration completed successfully ({details_msg})')
        if soft_exit:
            return True
        else:
            logs.exit_great_success()
    elif event_completed_successfully is False:
        logs.error(f'Migration failed ({details_msg})')
        if soft_exit:
            return False
        else:
            logs.exit_catastrophic_failure()
    else:
        return None