mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
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.
This commit is contained in:
@@ -17,6 +17,7 @@ import (
|
||||
sdkmodels "github.com/fnproject/fn_go/models"
|
||||
)
|
||||
|
||||
// See fn-test-utils for json response
|
||||
func getEchoContent(respBytes []byte) (string, error) {
|
||||
|
||||
var respJs map[string]interface{}
|
||||
@@ -39,6 +40,29 @@ func getEchoContent(respBytes []byte) (string, error) {
|
||||
return echo, nil
|
||||
}
|
||||
|
||||
// See fn-test-utils for json response
|
||||
func getConfigContent(key string, respBytes []byte) (string, error) {
|
||||
|
||||
var respJs map[string]interface{}
|
||||
|
||||
err := json.Unmarshal(respBytes, &respJs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
cfg, ok := respJs["config"].(map[string]interface{})
|
||||
if !ok {
|
||||
return "", errors.New("unexpected json: config map")
|
||||
}
|
||||
|
||||
val, ok := cfg[key].(string)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("unexpected json: %s string", key)
|
||||
}
|
||||
|
||||
return val, nil
|
||||
}
|
||||
|
||||
func TestCanExecuteFunction(t *testing.T) {
|
||||
s := apiutils.SetupHarness()
|
||||
s.GivenAppExists(t, &sdkmodels.App{Name: s.AppName})
|
||||
@@ -79,6 +103,13 @@ func TestCanExecuteFunction(t *testing.T) {
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("StatusCode check failed on %v", resp.StatusCode)
|
||||
}
|
||||
|
||||
// Now let's check FN_CHEESE, since LB and runners have override/extension mechanism
|
||||
// to insert FN_CHEESE into config
|
||||
cheese, err := getConfigContent("FN_CHEESE", output.Bytes())
|
||||
if err != nil || cheese != "Tete de Moine" {
|
||||
t.Fatalf("getConfigContent/FN_CHEESE check failed (%v) on %v", err, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCanExecuteBigOutput(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user