Files
fn-serverless/images/fn-status-checker/status.go
Tolga Ceylan 5dc5740a54 fn: runner status and docker load images (#1116)
* fn: runner status and docker load images

Introducing a function run for pure runner Status
calls. Previously, Status gRPC calls returned active
inflight request counts with the purpose of a simple
health checker. However this is not sufficient since
it does not show if agent or docker is healthy. With
this change, if pure runner is configured with a status
image, that image is executed through docker. The
call uses zero memory/cpu/tmpsize settings to ensure
resource tracker does not block it.

However, operators might not always have a docker
repository accessible/available for status image. Or
operators might not want the status to go over the
network. To allow such cases, and in general possibly
caching docker images, added a new environment variable
FN_DOCKER_LOAD_FILE. If this is set, fn-agent during
startup will load these images that were previously
saved with 'docker save' into docker.
2018-07-12 13:58:38 -07:00

55 lines
959 B
Go

package main
import (
"bytes"
"context"
"encoding/json"
"io"
"io/ioutil"
"log"
fdk "github.com/fnproject/fdk-go"
)
func main() {
fdk.Handle(fdk.HandlerFunc(myHandler))
}
func myHandler(ctx context.Context, in io.Reader, out io.Writer) {
var input map[string]interface{}
body, err := ioutil.ReadAll(in)
if err != nil {
log.Print("could not read input")
fdk.WriteStatus(out, 530)
return
}
err = json.Unmarshal(body, &input)
if err != nil {
log.Print("could not unmarshal json input")
fdk.WriteStatus(out, 531)
return
}
output, err := json.Marshal(&input)
if err != nil {
log.Print("could not marshal json output")
fdk.WriteStatus(out, 532)
return
}
written, err := io.Copy(out, bytes.NewReader(output))
if err != nil {
log.Print("could not write output")
fdk.WriteStatus(out, 533)
return
}
if written != int64(len(output)) {
log.Print("partial write of output")
fdk.WriteStatus(out, 534)
return
}
}