Skip to content

Commit 69f6c82

Browse files
committed
1 parent ea9d3b9 commit 69f6c82

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Extend the feature of streaming k8s events to AWS CloudWatch logs.
99

1010
Streams k8s events from k8s namespace to Slack channel as a Slack bot using incoming web hooks. No tokens needed.
1111

12+
# Known issue
13+
14+
* Model objects should tolerate None in place of empty lists https://github.com/kubernetes-client/python/issues/376.<br/>
15+
For now we have to patch the class in our code to workaround this issue.
16+
1217
# Configuration
1318

1419
Configuration is done via env variables that you set in deployment or configmap.

k8s-events-streamer.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
import kubernetes
1111
from dateutil.tz import tzlocal
1212

13+
# Workaround for https://github.com/kubernetes-client/python/issues/376
14+
from kubernetes.client.models.v1_event import V1Event
15+
16+
17+
def set_involved_object(self, involved_object):
18+
if involved_object is None:
19+
involved_object = {}
20+
self._involved_object = involved_object
21+
22+
23+
setattr(V1Event, 'involved_object', property(
24+
fget=V1Event.involved_object.fget, fset=set_involved_object))
25+
# End of workaround
26+
1327
logger = logging.getLogger()
1428
logger.setLevel(logging.INFO)
1529

@@ -121,6 +135,11 @@ def main():
121135
logger.info("Processing events...")
122136
for event in k8s_watch.stream(v1.list_namespaced_event, k8s_namespace_name):
123137
logger.debug(str(event))
138+
if not event['object'].involved_object:
139+
logger.debug(
140+
'Found empty involved_object in the event. Skip this one.'
141+
)
142+
continue
124143
if is_message_type_delete(event) and skip_delete_events != False:
125144
logger.debug(
126145
'Event type DELETED and skip deleted events is enabled. Skip this one.')

0 commit comments

Comments
 (0)