vmware-archive / kafka-trigger

Kubernetes CRD controller for Kafka topic as event source for Kubeless functions
Apache License 2.0
28 stars 34 forks source link

Get topic from inside handler_function #21

Closed lunarray closed 4 years ago

lunarray commented 4 years ago

FEATURE REQUEST:

What happened: Currently inside the kubeless handler function triggered by kafka trigger, we got two argument passed which is event and context. Inside both event and context there is no way to know what topic fired this event.

What you expected to happen: There is a way to get the subscribed topic name passed to either context or event. Like maybe:

def forward(event, context):
  topic_name = context['kafka']['topic']

Environment:



- Kubeless version (use `kubeless version`)
Kubeless version: v1.0.4-dirty

- Cloud provider or physical cluster:
Self-managed kubernetes AWS
jon-whit commented 4 years ago

@andresmgot I put up a merge request to add this support. I'm happy to talk through alternatives, but for now I've extended the request headers to include the event-topic which triggered a given function. This will address this requested functionality, and my team also has an immediate need for this in our platform.

andresmgot commented 4 years ago

I've released https://github.com/kubeless/kafka-trigger/releases/tag/v1.0.4 with this, thanks!

jon-whit commented 4 years ago

@andresmgot awesome! Thank you.

jon-whit commented 4 years ago

@lunarray so you should now be able to access the event-topic like so:

def forward(event, context):
  topic = event['extensions']['request'].get_header('event-topic')