== Function Controller
The *function controller* runs inside kubernetes, watching for changes to *function* and *topic* resources. It reacts by requesting the deployment of functions, and scales them according to events being detected on their input topics.
The following function config will limit the number of instance to 3 even if the number of topic partitions exceeds 3, and keep the last instance running for at least 60s.
```yaml
spec:
maxReplicas: 3
idleTimeoutMs: 60000
```
== 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-controller
----
=== Building
* To build locally (this will produce a binary named `function-controller` 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:
+
[source, bash]
----
make test
----
* To attach a https://github.com/derekparker/delve/blob/master/Documentation/EditorIntegration.md[delve capable] debugger (such as Goland)
to a `function-controller` running _inside_ k8s:
+
[source, bash]
----
make debug-dockerize
----
Then expose the `2345` port as a service, using `riff/config/delve/function-controller-debug.yaml`:
+
[source, bash]
----
kubectl apply -f config/debug-service.yaml
----
After restarting the `function-controller-...` pod, you can connect the debugger through `localhost:30102` (or `$(minikube ip):30102`).
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0
Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0 Code generated by mockery v1.0.0