Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes direct invoke call model #1192

Merged
merged 1 commit into from
Aug 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions api/agent/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type CallOpt func(c *call) error

const (
ceMimeType = "application/cloudevents+json"
// static path for all fn invocations
invokePath = "/invoke"
)

// FromRequest initialises a call to a route from an HTTP request
Expand Down Expand Up @@ -184,7 +186,7 @@ func FromHTTPTriggerRequest(app *models.App, fn *models.Fn, trigger *models.Trig
TmpFsSize: 0, // TODO clean up this
Memory: fn.Memory,
CPUs: 0, // TODO clean up this
Config: buildTriggerConfig(app, fn, trigger),
Config: buildConfigWithPath(app, fn, trigger.Source),
// TODO - this wasn't really the intention here (that annotations would naturally cascade
// but seems to be necessary for some runner behaviour
Annotations: app.Annotations.MergeChange(fn.Annotations).MergeChange(trigger.Annotations),
Expand Down Expand Up @@ -244,6 +246,7 @@ func FromHTTPFnRequest(app *models.App, fn *models.Fn, req *http.Request) CallOp

c.Call = &models.Call{
ID: id,
Path: invokePath,
Image: fn.Image,
// Delay: 0,
Type: "sync",
Expand All @@ -255,7 +258,7 @@ func FromHTTPFnRequest(app *models.App, fn *models.Fn, req *http.Request) CallOp
TmpFsSize: 0, // TODO clean up this
Memory: fn.Memory,
CPUs: 0, // TODO clean up this
Config: buildTriggerConfig(app, fn, nil),
Config: buildConfigWithPath(app, fn, invokePath),
// TODO - this wasn't really the intention here (that annotations would naturally cascade
// but seems to be necessary for some runner behaviour
Annotations: app.Annotations.MergeChange(fn.Annotations),
Expand All @@ -264,6 +267,7 @@ func FromHTTPFnRequest(app *models.App, fn *models.Fn, req *http.Request) CallOp
URL: reqURL(req),
Method: req.Method,
AppID: app.ID,
AppName: app.Name,
FnID: fn.ID,
SyslogURL: syslogURL,
}
Expand Down Expand Up @@ -297,7 +301,7 @@ func buildConfig(app *models.App, route *models.Route) models.Config {
return conf
}

func buildTriggerConfig(app *models.App, fn *models.Fn, trigger *models.Trigger) models.Config {
func buildConfigWithPath(app *models.App, fn *models.Fn, path string) models.Config {
conf := make(models.Config, 8+len(app.Config)+len(fn.Config))
for k, v := range app.Config {
conf[k] = v
Expand All @@ -308,9 +312,7 @@ func buildTriggerConfig(app *models.App, fn *models.Fn, trigger *models.Trigger)

conf["FN_FORMAT"] = fn.Format
conf["FN_APP_NAME"] = app.Name
if trigger != nil {
conf["FN_PATH"] = trigger.Source
}
conf["FN_PATH"] = path
// TODO: might be a good idea to pass in: "FN_BASE_PATH" = fmt.Sprintf("/r/%s", appName) || "/" if using DNS entries per app
conf["FN_MEMORY"] = fmt.Sprintf("%d", fn.Memory)
conf["FN_TYPE"] = "sync"
Expand Down