Skip to content

Commit

Permalink
feat: expose labels and annotations in the model (#369)
Browse files Browse the repository at this point in the history
We would like to use labels and annotations to configure the strategy to
behave differently for some workloads. This will expose labels and
annotations in `object_data.annotations`/ `object_data.labels` to be
used in strategies.
  • Loading branch information
chicocvenancio authored Dec 10, 2024
1 parent 1515b3d commit 1da6221
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions robusta_krr/core/integrations/kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ def __build_scannable_object(
namespace = item.metadata.namespace
kind = kind or item.__class__.__name__[2:]

labels = {}
annotations = {}
if item.metadata.labels:
labels = item.metadata.labels

if item.metadata.annotations:
annotations = item.metadata.annotations

obj = K8sObjectData(
cluster=self.cluster,
namespace=namespace,
Expand All @@ -209,6 +217,8 @@ def __build_scannable_object(
container=container.name,
allocations=ResourceAllocations.from_container(container),
hpa=self.__hpa_list.get((namespace, kind, name)),
labels=labels,
annotations= annotations
)
obj._api_resource = item
return obj
Expand Down
4 changes: 4 additions & 0 deletions robusta_krr/core/models/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class K8sObjectData(pd.BaseModel):
kind: KindLiteral
allocations: ResourceAllocations
warnings: set[PodWarning] = set()
labels: Optional[dict[str, str]]
annotations: Optional[dict[str, str]]

_api_resource = pd.PrivateAttr(None)

Expand Down Expand Up @@ -98,6 +100,8 @@ def split_into_batches(self, n: int) -> list[K8sObjectData]:
namespace=self.namespace,
kind=self.kind,
allocations=self.allocations,
labels=self.labels,
annotations=self.annotations,
)
for batch in batched(self.pods, n)
]

0 comments on commit 1da6221

Please # to comment.