Files
fn-serverless/api/runnerpool/runner_pool.go
Tolga Ceylan e67d0e5f3f fn: Call extensions/overriding and more customization friendly docker driver (#1065)
In pure-runner and LB agent, service providers might want to set specific driver options.

For example, to add cpu-shares to functions, LB can add the information as extensions
to the Call and pass this via gRPC to runners. Runners then pick these extensions from
gRPC call and pass it to driver. Using a custom driver implementation, pure-runners can
process these extensions to modify docker.CreateContainerOptions.

To achieve this, LB agents can now be configured using a call overrider.

Pure-runners can be configured using a custom docker driver.

RunnerCall and Call interfaces both expose call extensions.

An example to demonstrate this is implemented in test/fn-system-tests/system_test.go
which registers a call overrider for LB agent as well as a simple custom docker driver.
In this example, LB agent adds a key-value to extensions and runners add this key-value
as an environment variable to the container.
2018-06-18 14:42:28 -07:00

51 lines
1.4 KiB
Go

package runnerpool
import (
"context"
"io"
"net/http"
"github.com/fnproject/fn/api/models"
)
// Placer implements a placement strategy for calls that are load-balanced
// across runners in a pool
type Placer interface {
PlaceCall(rp RunnerPool, ctx context.Context, call RunnerCall) error
}
// RunnerPool is the abstraction for getting an ordered list of runners to try for a call
type RunnerPool interface {
// returns an error for unrecoverable errors that should not be retried
Runners(call RunnerCall) ([]Runner, error)
Shutdown(ctx context.Context) error
}
// PKIData encapsulates TLS certificate data
type PKIData struct {
Ca string
Key string
Cert string
}
// MTLSRunnerFactory represents a factory method for constructing runners using mTLS
type MTLSRunnerFactory func(addr, certCommonName string, pki *PKIData) (Runner, error)
// Runner is the interface to invoke the execution of a function call on a specific runner
type Runner interface {
TryExec(ctx context.Context, call RunnerCall) (bool, error)
Close(ctx context.Context) error
Address() string
}
// RunnerCall provides access to the necessary details of request in order for it to be
// processed by a RunnerPool
type RunnerCall interface {
SlotHashId() string
Extensions() map[string]string
RequestBody() io.ReadCloser
ResponseWriter() http.ResponseWriter
StdErr() io.ReadWriteCloser
Model() *models.Call
}