mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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:
1
images/fn-status-checker/.gitignore
vendored
Normal file
1
images/fn-status-checker/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
vendor
|
||||
15
images/fn-status-checker/Dockerfile
Normal file
15
images/fn-status-checker/Dockerfile
Normal 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
18
images/fn-status-checker/Gopkg.lock
generated
Normal 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
|
||||
3
images/fn-status-checker/Gopkg.toml
Normal file
3
images/fn-status-checker/Gopkg.toml
Normal file
@@ -0,0 +1,3 @@
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/fnproject/fdk-go"
|
||||
2
images/fn-status-checker/build.sh
Executable file
2
images/fn-status-checker/build.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
set -e
|
||||
docker build --build-arg HTTPS_PROXY --build-arg HTTP_PROXY -t fnproject/fn-status-checker:latest .
|
||||
2
images/fn-status-checker/release.sh
Executable file
2
images/fn-status-checker/release.sh
Executable file
@@ -0,0 +1,2 @@
|
||||
set -e
|
||||
docker push fnproject/fn-status-checker:latest
|
||||
54
images/fn-status-checker/status.go
Normal file
54
images/fn-status-checker/status.go
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user