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:
@@ -22,7 +22,6 @@ func (f *taskDockerTest) Command() string { return "" }
|
||||
func (f *taskDockerTest) EnvVars() map[string]string {
|
||||
return map[string]string{"FN_FORMAT": "default"}
|
||||
}
|
||||
func (f *taskDockerTest) Labels() map[string]string { return nil }
|
||||
func (f *taskDockerTest) Id() string { return f.id }
|
||||
func (f *taskDockerTest) Group() string { return "" }
|
||||
func (f *taskDockerTest) Image() string { return "fnproject/fn-test-utils" }
|
||||
@@ -37,6 +36,7 @@ func (f *taskDockerTest) TmpFsSize() uint64 { return 0 }
|
||||
func (f *taskDockerTest) WorkDir() string { return "" }
|
||||
func (f *taskDockerTest) Close() {}
|
||||
func (f *taskDockerTest) Input() io.Reader { return f.input }
|
||||
func (f *taskDockerTest) Extensions() map[string]string { return nil }
|
||||
|
||||
func TestRunnerDocker(t *testing.T) {
|
||||
dkr := NewDocker(drivers.Config{})
|
||||
@@ -46,11 +46,17 @@ func TestRunnerDocker(t *testing.T) {
|
||||
|
||||
task := &taskDockerTest{"test-docker", bytes.NewBufferString(`{"isDebug": true}`), &output, &errors}
|
||||
|
||||
cookie, err := dkr.Prepare(ctx, task)
|
||||
cookie, err := dkr.CreateCookie(ctx, task)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't create task cookie")
|
||||
}
|
||||
|
||||
defer cookie.Close(ctx)
|
||||
|
||||
err = dkr.PrepareCookie(ctx, cookie)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't prepare task test")
|
||||
}
|
||||
defer cookie.Close(ctx)
|
||||
|
||||
waiter, err := cookie.Run(ctx)
|
||||
if err != nil {
|
||||
@@ -80,13 +86,26 @@ func TestRunnerDockerNetworks(t *testing.T) {
|
||||
task1 := &taskDockerTest{"test-docker1", bytes.NewBufferString(`{"isDebug": true}`), &output, &errors}
|
||||
task2 := &taskDockerTest{"test-docker2", bytes.NewBufferString(`{"isDebug": true}`), &output, &errors}
|
||||
|
||||
cookie1, err := dkr.Prepare(ctx, task1)
|
||||
cookie1, err := dkr.CreateCookie(ctx, task1)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't create task1 cookie")
|
||||
}
|
||||
|
||||
defer cookie1.Close(ctx)
|
||||
|
||||
err = dkr.PrepareCookie(ctx, cookie1)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't prepare task1 test")
|
||||
}
|
||||
defer cookie1.Close(ctx)
|
||||
|
||||
cookie2, err := dkr.Prepare(ctx, task2)
|
||||
cookie2, err := dkr.CreateCookie(ctx, task2)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't create task2 cookie")
|
||||
}
|
||||
|
||||
defer cookie2.Close(ctx)
|
||||
|
||||
err = dkr.PrepareCookie(ctx, cookie2)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't prepare task2 test")
|
||||
}
|
||||
@@ -141,11 +160,17 @@ func TestRunnerDockerStdin(t *testing.T) {
|
||||
|
||||
task := &taskDockerTest{"test-docker-stdin", bytes.NewBufferString(input), &output, &errors}
|
||||
|
||||
cookie, err := dkr.Prepare(ctx, task)
|
||||
cookie, err := dkr.CreateCookie(ctx, task)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't create task cookie")
|
||||
}
|
||||
|
||||
defer cookie.Close(ctx)
|
||||
|
||||
err = dkr.PrepareCookie(ctx, cookie)
|
||||
if err != nil {
|
||||
t.Fatal("Couldn't prepare task test")
|
||||
}
|
||||
defer cookie.Close(ctx)
|
||||
|
||||
waiter, err := cookie.Run(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user