From a58fee3f736edaccb4ffa24b9d0572c6bdad9993 Mon Sep 17 00:00:00 2001 From: Roi Glinik Date: Sun, 17 Nov 2024 16:03:49 +0200 Subject: [PATCH] MAIN-2538 openshift groups fixes (#1633) * skip role binding without subjects * allow none labels and annotations * assert open shift groups only if there are results. --------- Co-authored-by: arik --- src/robusta/core/discovery/discovery.py | 4 ++++ src/robusta/core/model/openshift_group.py | 6 +++--- src/robusta/core/sinks/robusta/robusta_sink.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/robusta/core/discovery/discovery.py b/src/robusta/core/discovery/discovery.py index efbf8de30..7c2cc0a75 100644 --- a/src/robusta/core/discovery/discovery.py +++ b/src/robusta/core/discovery/discovery.py @@ -246,6 +246,10 @@ def discovery_process() -> DiscoveryResults: for role_binding in role_bindings.items: ns = role_binding.metadata.namespace + if not role_binding.subjects: + logging.info(f"Skipping role binding: {role_binding.metadata.name} in ns: {role_binding.metadata.namespace}") + continue + for subject in role_binding.subjects: if subject.kind == "Group": groupname_to_namespaces[subject.name].append(ns) diff --git a/src/robusta/core/model/openshift_group.py b/src/robusta/core/model/openshift_group.py index 907ab106e..de17a9bd4 100644 --- a/src/robusta/core/model/openshift_group.py +++ b/src/robusta/core/model/openshift_group.py @@ -1,4 +1,4 @@ -from typing import Dict +from typing import Dict, Optional from pydantic import BaseModel @@ -9,8 +9,8 @@ class OpenshiftGroup(BaseModel): namespace: str = "" users: list[str] = [] namespaces: list[str] = [] - labels: Dict[str, str] - annotations: Dict[str, str] + labels: Optional[Dict[str, str]] = None + annotations: Optional[Dict[str, str]] = None deleted: bool = False def get_service_key(self) -> str: diff --git a/src/robusta/core/sinks/robusta/robusta_sink.py b/src/robusta/core/sinks/robusta/robusta_sink.py index 54494a2c0..1cd04cc61 100644 --- a/src/robusta/core/sinks/robusta/robusta_sink.py +++ b/src/robusta/core/sinks/robusta/robusta_sink.py @@ -331,8 +331,8 @@ def __discover_resources(self) -> DiscoveryResults: self.__pods_running_count = results.pods_running_count - self.__assert_openshift_groups_cache_initialized() if results.openshift_groups: + self.__assert_openshift_groups_cache_initialized() self.__publish_new_openshift_groups(results.openshift_groups) # save the cached services for the resolver.