This repository has been archived by the owner on Nov 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
84 lines (70 loc) · 2.48 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"fmt"
"os"
"strings"
"github.com/openfaas-incubator/faas-federation/handlers"
"github.com/openfaas-incubator/faas-federation/routing"
"github.com/openfaas-incubator/faas-federation/types"
"github.com/openfaas-incubator/faas-federation/version"
bootstrap "github.com/openfaas/faas-provider"
"github.com/openfaas/faas-provider/proxy"
bootTypes "github.com/openfaas/faas-provider/types"
log "github.com/sirupsen/logrus"
)
func init() {
logFormat := os.Getenv("LOG_FORMAT")
logLevel := os.Getenv("LOG_LEVEL")
if strings.EqualFold(logFormat, "json") {
log.SetFormatter(&log.JSONFormatter{
FieldMap: log.FieldMap{
log.FieldKeyMsg: "message",
log.FieldKeyTime: "@timestamp",
},
TimestampFormat: "2006-01-02T15:04:05.999Z07:00",
})
} else {
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
}
if level, err := log.ParseLevel(logLevel); err == nil {
log.SetLevel(level)
}
}
func main() {
log.Infof("faas-federation version: %s. Last commit message: %s, commit SHA: %s", version.BuildVersion(), version.GitCommitMessage, version.GitCommitSHA)
readConfig := types.ReadConfig{}
osEnv := types.OsEnv{}
cfg := readConfig.Read(osEnv)
providerLookup, err := routing.NewDefaultProviderRouting(cfg.Providers, cfg.DefaultProvider)
if err != nil {
panic(fmt.Errorf("could not create provider lookup, error: %v", err))
}
err = providerLookup.ReloadCache()
if err != nil {
panic(fmt.Errorf("could not reload provider cache, error: %v", err))
}
proxyFunc := proxy.NewHandlerFunc(cfg.ReadTimeout,
handlers.NewFunctionLookup(providerLookup))
bootstrapHandlers := bootTypes.FaaSHandlers{
FunctionProxy: handlers.MakeProxyHandler(proxyFunc),
DeleteHandler: handlers.MakeDeleteHandler(proxyFunc),
DeployHandler: handlers.MakeDeployHandler(proxyFunc, providerLookup),
FunctionReader: handlers.MakeFunctionReader(cfg.Providers),
ReplicaReader: handlers.MakeReplicaReader(),
ReplicaUpdater: handlers.MakeReplicaUpdater(),
UpdateHandler: handlers.MakeUpdateHandler(proxyFunc, providerLookup),
HealthHandler: handlers.MakeHealthHandler(),
InfoHandler: handlers.MakeInfoHandler(version.BuildVersion(), version.GitCommitSHA),
}
bootstrapConfig := bootTypes.FaaSConfig{
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
TCPPort: &cfg.Port,
EnableHealth: true,
EnableBasicAuth: false,
}
log.Infof("listening on port %d", cfg.Port)
bootstrap.Serve(&bootstrapHandlers, &bootstrapConfig)
}