From 1fbd07fcd59bb4c0f4fd6310aa920f642fca6edb Mon Sep 17 00:00:00 2001 From: Cristian Steib Date: Thu, 5 Oct 2023 02:31:05 +0200 Subject: [PATCH] allow to configure custom values for events --- kopf/_cogs/clients/events.py | 8 ++++---- kopf/_cogs/configs/configuration.py | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/kopf/_cogs/clients/events.py b/kopf/_cogs/clients/events.py index 25c54dfd..3bca4bb6 100644 --- a/kopf/_cogs/clients/events.py +++ b/kopf/_cogs/clients/events.py @@ -53,7 +53,7 @@ async def post_event( body = { 'metadata': { 'namespace': namespace, - 'generateName': 'kopf-event-', + 'generateName': settings.posting.event_name_prefix, }, 'action': 'Action?', @@ -61,9 +61,9 @@ async def post_event( 'reason': reason, 'message': message, - 'reportingComponent': 'kopf', - 'reportingInstance': 'dev', - 'source' : {'component': 'kopf'}, # used in the "From" column in `kubectl describe`. + 'reportingComponent': settings.posting.reporting_component, + 'reportingInstance': settings.posting.reporting_instance, + 'source': {'component': settings.posting.reporting_component}, # used in the "From" column in `kubectl describe`. 'involvedObject': full_ref, diff --git a/kopf/_cogs/configs/configuration.py b/kopf/_cogs/configs/configuration.py index bee55f90..1ecc5085 100644 --- a/kopf/_cogs/configs/configuration.py +++ b/kopf/_cogs/configs/configuration.py @@ -80,6 +80,10 @@ class PostingSettings: (``kopf.info()``, ``kopf.warn()``, ``kopf.exception()``). """ + reporting_component: str = 'kopf' + reporting_instance: str = 'dev' + event_name_prefix: str = 'kopf-event-' + @dataclasses.dataclass class PeeringSettings: