mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* 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.
77 lines
1.7 KiB
Go
77 lines
1.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
|
|
pool "github.com/fnproject/fn/api/runnerpool"
|
|
)
|
|
|
|
func setupStaticPool(runners []string) pool.RunnerPool {
|
|
return NewStaticRunnerPool(runners, nil, "", mockRunnerFactory)
|
|
}
|
|
|
|
var (
|
|
ErrorGarbanzoBeans = errors.New("yes, that's right. Garbanzo beans...")
|
|
)
|
|
|
|
type mockStaticRunner struct {
|
|
address string
|
|
}
|
|
|
|
func (r *mockStaticRunner) TryExec(ctx context.Context, call pool.RunnerCall) (bool, error) {
|
|
return true, nil
|
|
}
|
|
|
|
func (r *mockStaticRunner) Status(ctx context.Context) (*pool.RunnerStatus, error) {
|
|
return nil, nil
|
|
}
|
|
|
|
func (r *mockStaticRunner) Close(context.Context) error {
|
|
return ErrorGarbanzoBeans
|
|
}
|
|
|
|
func (r *mockStaticRunner) Address() string {
|
|
return r.address
|
|
}
|
|
|
|
func mockRunnerFactory(addr, cn string, pki *pool.PKIData) (pool.Runner, error) {
|
|
return &mockStaticRunner{address: addr}, nil
|
|
}
|
|
|
|
func TestNewStaticPool(t *testing.T) {
|
|
addrs := []string{"127.0.0.1:8080", "127.0.0.1:8081"}
|
|
np := setupStaticPool(addrs)
|
|
|
|
runners, err := np.Runners(nil)
|
|
if err != nil {
|
|
t.Fatalf("Failed to list runners %v", err)
|
|
}
|
|
if len(runners) != len(addrs) {
|
|
t.Fatalf("Invalid number of runners %v", len(runners))
|
|
}
|
|
|
|
err = np.Shutdown(context.Background())
|
|
if err != ErrorGarbanzoBeans {
|
|
t.Fatalf("Expected garbanzo beans error from shutdown %v", err)
|
|
}
|
|
}
|
|
|
|
func TestEmptyPool(t *testing.T) {
|
|
np := setupStaticPool(nil).(*staticRunnerPool)
|
|
|
|
runners, err := np.Runners(nil)
|
|
if err != nil {
|
|
t.Fatalf("Failed to list runners %v", err)
|
|
}
|
|
if len(runners) != 0 {
|
|
t.Fatalf("Invalid number of runners %v", len(runners))
|
|
}
|
|
|
|
err = np.Shutdown(context.Background())
|
|
if err != nil {
|
|
t.Fatalf("Unexpected error from shutdown %v", err)
|
|
}
|
|
}
|