mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
http-stream format (#1202)
* POC code for inotify UDS-io-socket * http-stream format introducing the `http-stream` format support in fn. there are many details for this, none of which can be linked from github :( -- docs are coming (I could even try to add some here?). this is kinda MVP-ish level, but does not implement the remaining spec, ie 'headers' fixing up / invoke fixing up. the thinking being we can land this to test fdks / cli with and start splitting work up on top of this. all other formats work the same as previous (no breakage, only new stuff) with the cli you can set `format: http-stream` and deploy, and then invoke a function via the `http-stream` format. this uses unix domain socket (uds) on the container instead of previous stdin/stdout, and fdks will have to support this in a new fashion (will see about getting docs on here). fdk-go works, which is here: https://github.com/fnproject/fdk-go/pull/30 . the output looks the same as an http format function when invoking a function. wahoo. there's some amount of stuff we can clean up here, enumerated: * the cleanup of the sock files is iffy, high pri here * permissions are a pain in the ass and i punted on dealing with them. you can run `sudo ./fnserver` if running locally, it may/may not work in dind(?) ootb * no pipe usage at all (yay), still could reduce buffer usage around the pipe behavior, we could clean this up potentially before removal (and tests) * my brain can’t figure out if dispatchOldFormats changes pipe behavior, but tests work * i marked XXX to do some clean up which will follow soon… need this to test fdk tho so meh, any thoughts on those marked would be appreciated however (1 less decision for me). mostly happy w/ general shape/plumbing tho * there are no tests atm, this is a tricky dance indeed. attempts were made. need to futz with the permission stuff before committing to adding any tests here, which I don't like either. also, need to get the fdk-go based test image updated according to the fdk-go, and there's a dance there too. rumba time.. * delaying the big big cleanup until we have good enough fdk support to kill all the other formats. open to ideas on how to maneuver landing stuff... * fix unmount * see if the tests work on ci... * add call id header * fix up makefile * add configurable iofs opts * add format file describing http-stream contract * rm some cruft * default iofs to /tmp, remove mounting out of the box fn we can't mount. /tmp will provide a memory backed fs for us on most systems, this will be fine for local developing and this can be configured to be wherever for anyone that wants to make things more difficult for themselves. also removes the mounting, this has to be done as root. we can't do this in the oss fn (short of requesting root, but no). in the future, we may want to have a knob here to have a function that can be configured in fn that allows further configuration here. since we don't know what we need in this dept really, not doing that yet (it may be the case that it could be done operationally outside of fn, eg, but not if each directory needs to be configured itself, which seems likely, anyway...) * add WIP note just in case...
This commit is contained in:
@@ -17,6 +17,7 @@ type cookie struct {
|
||||
poolId string
|
||||
// network name from docker networks if applicable
|
||||
netId string
|
||||
|
||||
// docker container create options created by Driver.CreateCookie, required for Driver.Prepare()
|
||||
opts docker.CreateContainerOptions
|
||||
// task associated with this cookie
|
||||
@@ -104,6 +105,17 @@ func (c *cookie) configureTmpFs(log logrus.FieldLogger) {
|
||||
c.opts.HostConfig.Tmpfs["/tmp"] = tmpFsOption
|
||||
}
|
||||
|
||||
func (c *cookie) configureIOFs(log logrus.FieldLogger) {
|
||||
path := c.task.UDSPath()
|
||||
if path == "" {
|
||||
// TODO this should be required soon-ish
|
||||
return
|
||||
}
|
||||
|
||||
bind := fmt.Sprintf("%s:/iofs", path)
|
||||
c.opts.HostConfig.Binds = append(c.opts.HostConfig.Binds, bind)
|
||||
}
|
||||
|
||||
func (c *cookie) configureVolumes(log logrus.FieldLogger) {
|
||||
if len(c.task.Volumes()) == 0 {
|
||||
return
|
||||
@@ -176,12 +188,13 @@ func (c *cookie) configureEnv(log logrus.FieldLogger) {
|
||||
return
|
||||
}
|
||||
|
||||
envvars := make([]string, 0, len(c.task.EnvVars()))
|
||||
for name, val := range c.task.EnvVars() {
|
||||
envvars = append(envvars, name+"="+val)
|
||||
if c.opts.Config.Env == nil {
|
||||
c.opts.Config.Env = make([]string, 0, len(c.task.EnvVars()))
|
||||
}
|
||||
|
||||
c.opts.Config.Env = envvars
|
||||
for name, val := range c.task.EnvVars() {
|
||||
c.opts.Config.Env = append(c.opts.Config.Env, name+"="+val)
|
||||
}
|
||||
}
|
||||
|
||||
// implements Cookie
|
||||
|
||||
@@ -242,6 +242,7 @@ func (drv *DockerDriver) CreateCookie(ctx context.Context, task drivers.Containe
|
||||
cookie.configureTmpFs(log)
|
||||
cookie.configureVolumes(log)
|
||||
cookie.configureWorkDir(log)
|
||||
cookie.configureIOFs(log)
|
||||
|
||||
// Order is important, if pool is enabled, it overrides pick network
|
||||
drv.pickPool(ctx, cookie)
|
||||
|
||||
@@ -73,6 +73,7 @@ func (c *poolTask) TmpFsSize() uint64 { return 0
|
||||
func (c *poolTask) Extensions() map[string]string { return nil }
|
||||
func (c *poolTask) LoggerConfig() drivers.LoggerConfig { return drivers.LoggerConfig{} }
|
||||
func (c *poolTask) WriteStat(ctx context.Context, stat drivers.Stat) {}
|
||||
func (c *poolTask) UDSPath() string { return "" }
|
||||
|
||||
type dockerPoolItem struct {
|
||||
id string
|
||||
|
||||
@@ -38,6 +38,7 @@ func (f *taskDockerTest) Close() {}
|
||||
func (f *taskDockerTest) Input() io.Reader { return f.input }
|
||||
func (f *taskDockerTest) Extensions() map[string]string { return nil }
|
||||
func (f *taskDockerTest) LoggerConfig() drivers.LoggerConfig { return drivers.LoggerConfig{} }
|
||||
func (f *taskDockerTest) UDSPath() string { return "" }
|
||||
|
||||
func TestRunnerDocker(t *testing.T) {
|
||||
dkr := NewDocker(drivers.Config{})
|
||||
|
||||
Reference in New Issue
Block a user