def _get_instance(instance_id_or_name=None, instance_id=None, required=True): if instance_id: logs.debug(f'Getting instance using instance_id', instance_id=instance_id) instance = crds_manager.get(APP_CRD_SINGULAR, name=instance_id, required=False) instance_name = None else: logs.debug(f'Attempting to get instance using id', instance_id_or_name=instance_id_or_name) instance = crds_manager.get(APP_CRD_SINGULAR, name=instance_id_or_name, required=False) if instance: instance_id = instance_id_or_name instance_name = None else: logs.debug(f'Attempting to get instance from instance name', instance_id_or_name=instance_id_or_name) instance_name = crds_manager.get(APP_NAME_CRD_SINGULAR, name=instance_id_or_name, required=False) if instance_name: instance_id = instance_name['spec'].get('latest-instance-id') logs.debug(instance_id=instance_id) instance = crds_manager.get(APP_CRD_SINGULAR, name=instance_id, required=False) instance_name = instance_id_or_name else: instance_name = None logs.debug_yaml_dump(instance_name=instance_name, instance_id=instance_id, instance=bool(instance)) if required: assert instance_id and len(instance) > 2, \ f'Failed to find instance (instance_id_or_name={instance_id_or_name}, instance_id={instance_id})' return instance_id, instance
def _get_instance_id_and_type(instance_id_or_name=None, instance_id=None, required=True): if instance_id: logs.debug(f'Getting instance type using instance_id', instance_id=instance_id) instance = crds_manager.get(INSTANCE_CRD_SINGULAR, name=instance_id, required=False) instance_name = None else: logs.debug(f'Attempting to get instance type using id', instance_id_or_name=instance_id_or_name) instance = crds_manager.get(INSTANCE_CRD_SINGULAR, name=instance_id_or_name, required=False) if instance: instance_id = instance_id_or_name instance_name = None else: logs.debug(f'Attempting to get instance type from instance name', instance_id_or_name=instance_id_or_name) instance_name = crds_manager.get(INSTANCE_NAME_CRD_SINGULAR, name=instance_id_or_name, required=False) if instance_name: instance_id = instance_name['spec'].get('latest-instance-id') logs.debug(instance_id=instance_id) instance = crds_manager.get(INSTANCE_CRD_SINGULAR, name=instance_id, required=False) instance_name = instance_id_or_name else: instance_name = None if instance: instance_type = instance['metadata']['labels'].get('{}/instance-type'.format(labels_manager.get_label_prefix())) else: instance_type = None logs.debug_yaml_dump(instance_name=instance_name, instance_id=instance_id, instance_type=instance_type, instance=bool(instance)) if required: assert instance_id and instance_type and len(instance) > 2, f'Failed to find instance (instance_id_or_name={instance_id_or_name}, instance_id={instance_id})' return instance_id, instance_type, instance
def spec(self): """Initialize the spec object, fetch values from kubernetes if not provided :return: DeisCkanInstanceSpec """ if not getattr(self, '_spec', None): self._spec = DeisCkanInstanceSpec(self.values['spec'], self._override_spec) if self._persist_overrides and self._spec.num_applied_overrides > 0: logs.info('persisting overrides') logs.debug(f'saving spec for instance id {self.id}: {self._spec.spec}') instance = kubectl.get(f'{self.kind} {self.id}') instance['spec'] = self._spec.spec logs.debug_yaml_dump(instance) kubectl.apply(instance) return self._spec
def _init_solr(instance_id, dry_run=False): logs.debug('Initializing solr', instance_id=instance_id) solr_status = solr_manager.get_collection_status(instance_id) logs.debug_yaml_dump(solr_status) if not solr_status['ready']: logs.info('Creating solr collection', collection_name=instance_id, solr_config='ckan_28_default') if not dry_run: solr_manager.create_collection(instance_id, 'ckan_28_default') else: logs.info(f'collection already exists ({instance_id})') solr_url = solr_status['solr_http_endpoint'] logs.debug(solr_url=solr_url) assert solr_url.startswith('http') and solr_url.endswith('/solr'), f'invalid solr_url ({solr_url})' host, port = solr_url.replace('https://', '').replace('http://', '').replace('/solr', '').split(':') logs.debug('Solr initialization completed successfully', host=host, port=port) return host, port