Skip to content

Commit 1c954f1

Browse files
committed
add event probe
Signed-off-by: Sylvain Hellegouarch <[email protected]>
1 parent 93651ce commit 1c954f1

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.31.1...HEAD
66

7+
### Added
8+
9+
* A new probe to list cluster events
10+
711
## [0.31.1][] - 2023-10-02
812

913
[0.31.1]: https://github.com/chaostoolkit/chaostoolkit-kubernetes/compare/0.31.0...0.31.1

chaosk8s/event/__init__.py

Whitespace-only changes.

chaosk8s/event/probes.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import json
2+
from typing import Any, Dict
3+
4+
from chaoslib.types import Configuration, Secrets
5+
from kubernetes import client
6+
7+
from chaosk8s import create_k8s_api_client
8+
9+
__all__ = ["get_events"]
10+
11+
12+
def get_events(
13+
label_selector: str = None,
14+
limit: int = 100,
15+
configuration: Configuration = None,
16+
secrets: Secrets = None,
17+
) -> Dict[str, Any]:
18+
"""
19+
Retrieve Kubernetes events across all namespaces. If a `label_selector`
20+
is set, filter to that selector only.
21+
"""
22+
api = create_k8s_api_client(secrets)
23+
24+
v1 = client.EventsV1Api(api)
25+
ret = v1.list_event_for_all_namespaces(
26+
_preload_content=False, label_selector=label_selector, limit=limit
27+
)
28+
29+
return json.loads(ret.read().decode("utf-8"))

0 commit comments

Comments
 (0)