== Function Sidecar
The *function sidecar* runs alongside the function container in every function pod, and takes care of consuming input
events from the broker. It forwards those events to the function (via the *invoker*) using gRPC (recommended)
or other "dispatcher" mechanisms such as `http` (legacy). Likewise, the sidecar marshalls function output back to the
broker.
== Development
=== Prerequisites
The following tools are required to build this project:
- `make`
- Docker
- https://github.com/Masterminds/glide#install[Glide] for dependency management
If you intend to re-generate mocks for testing, install:
- https://github.com/vektra/mockery#installation[Mockery]
If you would like to run tests using the `ginkgo` command, install:
- http://onsi.github.io/ginkgo/[Ginkgo]
=== Get the source
[source, bash]
----
go get github.com/projectriff/riff
cd $(go env GOPATH)/github.com/projectriff/riff/function-sidecar
----
=== Building
* To build locally (this will produce a binary named `function-sidecar` on _your_ machine):
+
[source, bash]
----
make build
----
* To build for docker (and deploy as part of the whole https://github.com/projectriff/riff#-manual-install-of-riff[riff]
installation):
+
[source, bash]
----
make dockerize
----
This assumes that your docker client is correctly configured to target the daemon where you want the image built.
* To run tests, assuming kafka is running locally on port 9092:
+
[source, bash]
----
KAFKA_BROKER=localhost:9092 make test
----
* To attach a https://github.com/derekparker/delve/blob/master/Documentation/EditorIntegration.md[delve capable] debugger (such as Goland)
to a `function-sidecar` running _inside_ k8s:
+
[source, bash]
----
make debug-dockerize
----
Then expose the `2345` port as a service, assuming your function is named "`foo`":
+
[source, bash]
----
kubectl expose deployment foo --type=NodePort --name=foo-debug --port=2345
----
After restarting the pod of the `function-sidecar`, you can connect the debugger through `localhost:<port>` (or `$(minikube ip):<port>`) where `<port>` is discovered via
+
[source, bash]
----
kubectl get svc/foo-debug -o jsonpath='{.spec.ports[0].nodePort}'
----