def retrieve_train_names(self, location, all_trains=True, trains_filter=None): train_names = [] trains_filter = trains_filter or [] for train in os.listdir(location): if (not (all_trains or train in trains_filter) or not os.path.isdir(os.path.join(location, train)) or train.startswith('.') or train in ('library', 'docs') or not VALID_TRAIN_REGEX.match(train)): continue train_names.append(train) return train_names
def get_trains(self, location, options=None): # We make sure we do not dive into library and docs folders and not consider those a train # This allows us to use these folders for placing helm library charts and docs respectively trains = {'charts': {}, 'test': {}} options = options or {} unhealthy_apps = set() for train in os.listdir(location): if (not os.path.isdir(os.path.join(location, train)) or train.startswith('.') or train in ('library', 'docs') or not VALID_TRAIN_REGEX.match(train)): continue trains[train] = {} for train in filter( lambda c: os.path.exists(os.path.join(location, c)), trains): category_path = os.path.join(location, train) for item in filter( lambda p: os.path.isdir(os.path.join(category_path, p)), os.listdir(category_path)): item_location = os.path.join(category_path, item) trains[train][item] = item_data = { 'name': item, 'location': item_location, 'healthy': False, # healthy means that each version the item hosts is valid and healthy 'healthy_error': None, # An error string explaining why the item is not healthy 'versions': {}, } schema = f'{train}.{item}' try: self.middleware.call_sync('catalog.validate_catalog_item', item_location, schema, False) except ValidationErrors as verrors: item_data[ 'healthy_error'] = f'Following error(s) were found with {item!r}:\n' for verror in verrors: item_data[ 'healthy_error'] += f'{verror[0]}: {verror[1]}' unhealthy_apps.add(f'{item} ({train} train)') # If the item format is not valid - there is no point descending any further into versions continue item_data.update(self.item_details(item_location, schema)) unhealthy_versions = [ k for k, v in item_data['versions'].items() if not v['healthy'] ] if unhealthy_versions: unhealthy_apps.add(f'{item} ({train} train)') item_data[ 'healthy_error'] = f'Errors were found with {", ".join(unhealthy_versions)} version(s)' else: item_data['healthy'] = True if options.get('alert') and options.get('label') and unhealthy_apps: self.middleware.call_sync('alert.oneshot_create', 'CatalogNotHealthy', { 'catalog': options['label'], 'apps': ', '.join(unhealthy_apps) }) return trains