Coverage for ocp_resources/cluster_service_version.py: 0%
17 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-30 10:48 +0200
1import json
2from typing import List, Any, Dict
4from ocp_resources.resource import NamespacedResource
7class ClusterServiceVersion(NamespacedResource):
8 api_group = NamespacedResource.ApiGroup.OPERATORS_COREOS_COM
10 class Status(NamespacedResource.Status):
11 INSTALLING = "Installing"
13 def get_alm_examples(self) -> List[Dict[str, Any]]:
14 """
15 Parse the alm-examples annotation from the CSV instance and return a list of dictionaries.
16 Returns an empty list if no annotation is found or if the JSON is invalid.
18 Returns:
19 Union[List[Dict[str, Any]], List[]]: A list of dictionaries from alm-examples, or an empty list if parsing fails.
20 """
21 alm_examples = self.instance.metadata.annotations.get("alm-examples")
23 if not alm_examples:
24 self.logger.debug(f"No alm-examples annotation found in CSV {self.name}")
25 return []
27 try:
28 return json.loads(alm_examples)
29 except json.JSONDecodeError:
30 self.logger.error(f"Failed to parse alm-examples annotation from CSV {self.name}: Invalid JSON format")
31 return []