Skip to content

Commit

Permalink
Add CatalogItem spec features (#1366)
Browse files Browse the repository at this point in the history
* Add support for catalog items with external urls

* Add CatalogItem properties to spec rather than annotations
  • Loading branch information
jkupferer authored Aug 14, 2023
1 parent 4e765f0 commit 4aee74f
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions agnosticv-operator/operator/agnosticvcomponent.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ def catalog_disable(self):
def catalog_display_name(self):
return self.catalog_meta.get('display_name', self.name)

@property
def catalog_external_url(self):
return self.catalog_meta.get('externalUrl')

@property
def catalog_icon(self):
# FIXME - default icon dict?
Expand Down Expand Up @@ -482,10 +486,10 @@ def __catalog_item_definition(self):
},
},
"spec": {
#"category": self.catalog_category,
#"description": self.catalog_description,
#"icon": self.catalog_icon,
#"keywords": self.catalog_keywords,
"category": self.catalog_category,
"description": self.catalog_description,
"displayName": self.catalog_display_name,
"keywords": self.catalog_keywords,
"lastUpdate": self.last_update,
"lifespan": {
"default": self.lifespan_default,
Expand All @@ -503,6 +507,7 @@ def __catalog_item_definition(self):
# FIXME - weird default behavior from agnosticv-operator
if self.catalog_icon:
definition['metadata']['annotations'][f"{Babylon.catalog_api_group}/icon"] = json.dumps(self.catalog_icon)
definition['spec']['icon'] = self.catalog_icon
else:
definition['metadata']['annotations'][f"{Babylon.catalog_api_group}/icon"] = ''

Expand All @@ -512,20 +517,24 @@ def __catalog_item_definition(self):
if self.bookbag:
definition['spec']['bookbag'] = self.bookbag

if self.catalog_external_url:
definition['spec']['externalUrl'] = self.catalog_external_url

for key, value in self.catalog_labels.items():
definition['metadata']['labels'][f"{Babylon.catalog_api_group}/{key}"] = value

if self.stage in ('dev', 'test', 'prod', 'event'):
definition['metadata']['labels'][f"{Babylon.catalog_api_group}/stage"] = self.stage

for idx, linked_component in enumerate(self.linked_components):
#if not 'linkedComponents' in definition['spec']:
# definition['spec']['linkedComponents'] = []
if not 'linkedComponents' in definition['spec']:
definition['spec']['linkedComponents'] = []

#definition['spec']['linkedComponents'].append({
# "displayName": linked_component.display_name,
# "name": linked_component.name,
#})
definition['spec']['linkedComponents'].append({
"name": linked_component.name,
})
if linked_component.display_name:
definition['spec']['linkedComponents'][-1]['displayName'] = linked_component.display_name

definition['spec']['resources'].append({
"name": linked_component.name or linked_component.short_name,
Expand Down Expand Up @@ -1207,9 +1216,10 @@ async def handle_update(self, logger):
await self.manage_config(logger=logger)

async def manage_config(self, logger):
await self.__manage_anarchy_governor(logger=logger)
await self.__manage_catalog_item(logger=logger)
await self.__manage_resource_provider(logger=logger)
if not self.catalog_external_url:
await self.__manage_anarchy_governor(logger=logger)
await self.__manage_resource_provider(logger=logger)


class LinkedComponent:
Expand Down

0 comments on commit 4aee74f

Please sign in to comment.