Skip to content

Commit 1821bfe

Browse files
committed
Backend support for CRDs visualization
1 parent effae32 commit 1821bfe

2 files changed

Lines changed: 16 additions & 64 deletions

File tree

docs/setup-robusta/crds.rst

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,7 @@ Configuration
2424
Basic Configuration
2525
^^^^^^^^^^^^^^^^^^^
2626

27-
To enable CRD monitoring, add the ``customClusterRoleRules`` section to your Robusta Helm values:
28-
29-
.. code-block:: yaml
30-
31-
runner:
32-
customClusterRoleRules:
33-
- apiGroups:
34-
- "*"
35-
resources:
36-
- "*"
37-
verbs:
38-
- "list"
39-
- "get"
40-
- "watch"
41-
42-
.. warning::
43-
The above configuration grants read access to all resources. For production environments, it's recommended to limit access to specific CRDs only.
44-
45-
Specific CRD Configuration
46-
^^^^^^^^^^^^^^^^^^^^^^^^^^
47-
48-
For better security, specify only the CRDs you need to monitor:
49-
50-
**Example 1: Monitoring Cert-Manager Resources**
27+
Specify read permissions for the CRDs you need to monitor:
5128

5229
.. code-block:: yaml
5330

src/robusta/core/playbooks/internal/crds.py

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import subprocess
55
from typing import Optional, List
66

7+
from core.reporting.consts import SlackAnnotations
8+
from robusta.core.playbooks.common import get_resource_events_table
79
from robusta.core.model.env_vars import KUBECTL_CMD_TIMEOUT_SEC
810
from robusta.core.model.base_params import ActionParams
911
from robusta.core.playbooks.actions_registry import action
1012
from robusta.core.model.events import ExecutionBaseEvent
1113
from robusta.core.reporting.blocks import FileBlock, JsonBlock, TableBlock, MarkdownBlock
12-
from robusta.core.reporting.base import Finding
14+
from robusta.core.reporting.base import Finding, EnrichmentType
1315
from robusta.utils.error_codes import ActionException, ErrorCodes
1416

1517

@@ -126,47 +128,20 @@ def fetch_resource_events(event: ExecutionBaseEvent, params: ResourceParams):
126128
)
127129

128130
try:
129-
cmd = ["kubectl", "get", "events",
130-
f"--field-selector=involvedObject.name={params.name},involvedObject.kind={params.kind}",
131-
"-o", "json"]
132-
if params.namespace:
133-
cmd.extend(["-n", params.namespace])
134-
135-
output = run_kubectl_command(cmd)
136-
137-
events_data = json.loads(output)
138-
items = events_data.get("items", [])
139-
140-
if not items:
141-
finding.add_enrichment([MarkdownBlock(f"No events found for {params.kind}/{params.name}")])
142-
else:
143-
headers = ["Type", "Reason", "Age", "From", "Message"]
144-
rows = []
145-
146-
for item in items:
147-
event_type = item.get("type", "Unknown")
148-
reason = item.get("reason", "Unknown")
149-
150-
last_timestamp = item.get("lastTimestamp") or item.get("eventTime", "")
151-
age = last_timestamp.split("T")[0] if last_timestamp else "Unknown"
152-
153-
source = item.get("source", {})
154-
from_str = source.get("component", "Unknown")
155-
if source.get("host"):
156-
from_str += f" ({source.get('host')})"
157-
158-
message = item.get("message", "No message")
159-
160-
rows.append([event_type, reason, age, from_str, message])
161-
162-
rows.reverse()
163-
164-
table_block = TableBlock(
165-
rows=rows,
166-
headers=headers
131+
events_table = get_resource_events_table(
132+
"Resource Events",
133+
params.kind,
134+
params.name,
135+
params.namespace,
136+
)
137+
if events_table:
138+
finding.add_enrichment(
139+
[events_table],
140+
{SlackAnnotations.ATTACHMENT: True},
141+
enrichment_type=EnrichmentType.k8s_events,
142+
title="Resource Events",
167143
)
168144

169-
finding.add_enrichment([table_block])
170145

171146
event.add_finding(finding)
172147

0 commit comments

Comments
 (0)