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.
This commit is contained in:
Tolga Ceylan
2018-07-12 13:58:38 -07:00
committed by GitHub
parent 62461d93a7
commit 5dc5740a54
26 changed files with 745 additions and 57 deletions

1
images/fn-status-checker/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
vendor

View File

@@ -0,0 +1,15 @@
# build stage
FROM golang:1.10-alpine AS build-env
RUN apk --no-cache add git
ENV D=/go/src/github.com/fnproject/fn/images/fn-status-checker
RUN go get -u github.com/golang/dep/cmd/dep
ADD Gopkg.* $D/
RUN cd $D && dep ensure --vendor-only
ADD . $D
RUN cd $D && go build -ldflags="-s -w" -o fn-status-checker && cp fn-status-checker /tmp/
# final stage
FROM alpine
WORKDIR /function
COPY --from=build-env /tmp/fn-status-checker /function
ENTRYPOINT ["./fn-status-checker"]

18
images/fn-status-checker/Gopkg.lock generated Normal file
View File

@@ -0,0 +1,18 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[[projects]]
branch = "master"
name = "github.com/fnproject/fdk-go"
packages = [
".",
"utils"
]
revision = "5d768b2006f11737b6a69a758ddd6d2fac04923e"
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "c55f0d3da5ec2e9e5c9a7c563702e4cf28513fa1aaea1c18664ca2cb7d726f89"
solver-name = "gps-cdcl"
solver-version = 1

View File

@@ -0,0 +1,3 @@
[[constraint]]
branch = "master"
name = "github.com/fnproject/fdk-go"

View File

@@ -0,0 +1,2 @@
set -e
docker build --build-arg HTTPS_PROXY --build-arg HTTP_PROXY -t fnproject/fn-status-checker:latest .

View File

@@ -0,0 +1,2 @@
set -e
docker push fnproject/fn-status-checker:latest

View File

@@ -0,0 +1,54 @@
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
}
}