openfaas / of-watchdog

Reverse proxy for STDIO and HTTP microservices
MIT License
259 stars 115 forks source link

Add one-shot mode #66

Open alexellis opened 5 years ago

alexellis commented 5 years ago

Expected Behaviour

To enable the "batch job" use-case, users should be able to specify a "one shot" mode or parameter. This would allow unlimited requests to /healthz and /metrics, but only a single request to /, after which it would shutdown the binary process.

This is partially to work around limitations in Kubernetes jobs with daemons, web-servers and side-cars which keep the job in a "running" status.

https://github.com/kubernetes/kubernetes/issues/25908 https://github.com/kubernetes/enhancements/issues/753

Argo workflows does appear to work in "sidecar" mode without any additional changes to the watchdog, but I suspect building on Kubernetes Jobs would be cleaner from a dependencies point of view.

Example with figlet container:

https://twitter.com/alexellisuk/status/1148239010034311169

Example in Argo docs on sidecars:

https://github.com/argoproj/argo/blob/master/examples/README.md#sidecars

alexellis commented 5 years ago

@LucasRoesler @stefanprodan WDYT?

alexellis commented 5 years ago

Related to: https://github.com/openfaas/faas/issues/657

LucasRoesler commented 4 years ago

@alexellis without a sidecar, how would the request to / be sent?

alexellis commented 4 years ago

Sorry I don't understand the question.

alexellis commented 4 years ago

The batch job use-case would be like I shared in my tweet in the original post above.

Container 1 - curl or similar process - calls 127.0.0.1:8080 with payload Container 2 - OF container built with of-watchdog or classic watchdog in "one shot" mode

Result of invocation is available via STDIO, or with Container 3 which would save away the result.

alexellis commented 4 years ago

The overall workflow would be out of scope for this flag / feature addition. The suggested feature is simply a graceful shutdown after processing a single HTTP invoke request.