forked from openfaas/faas-netes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
82 lines (69 loc) · 2.63 KB
/
server.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
// Copyright (c) Alex Ellis 2017. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
package main
import (
"log"
"os"
"github.com/openfaas/faas-netes/handlers"
"github.com/openfaas/faas-netes/types"
"github.com/openfaas/faas-netes/version"
"github.com/openfaas/faas-provider"
bootTypes "github.com/openfaas/faas-provider/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
)
func main() {
// creates the in-cluster config
config, err := rest.InClusterConfig()
if err != nil {
panic(err.Error())
}
functionNamespace := "default"
if namespace, exists := os.LookupEnv("function_namespace"); exists {
functionNamespace = namespace
}
// creates the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
readConfig := types.ReadConfig{}
osEnv := types.OsEnv{}
cfg := readConfig.Read(osEnv)
log.Printf("HTTP Read Timeout: %s\n", cfg.ReadTimeout)
log.Printf("HTTP Write Timeout: %s\n", cfg.WriteTimeout)
deployConfig := &handlers.DeployHandlerConfig{
HTTPProbe: cfg.HTTPProbe,
FunctionReadinessProbeConfig: &handlers.FunctionProbeConfig{
InitialDelaySeconds: int32(cfg.ReadinessProbeInitialDelaySeconds),
TimeoutSeconds: int32(cfg.ReadinessProbeTimeoutSeconds),
PeriodSeconds: int32(cfg.ReadinessProbePeriodSeconds),
},
FunctionLivenessProbeConfig: &handlers.FunctionProbeConfig{
InitialDelaySeconds: int32(cfg.LivenessProbeInitialDelaySeconds),
TimeoutSeconds: int32(cfg.LivenessProbeTimeoutSeconds),
PeriodSeconds: int32(cfg.LivenessProbePeriodSeconds),
},
ImagePullPolicy: cfg.ImagePullPolicy,
}
bootstrapHandlers := bootTypes.FaaSHandlers{
FunctionProxy: handlers.MakeProxy(functionNamespace, cfg.ReadTimeout),
DeleteHandler: handlers.MakeDeleteHandler(functionNamespace, clientset),
DeployHandler: handlers.MakeDeployHandler(functionNamespace, clientset, deployConfig),
FunctionReader: handlers.MakeFunctionReader(functionNamespace, clientset),
ReplicaReader: handlers.MakeReplicaReader(functionNamespace, clientset),
ReplicaUpdater: handlers.MakeReplicaUpdater(functionNamespace, clientset),
UpdateHandler: handlers.MakeUpdateHandler(functionNamespace, clientset),
Health: handlers.MakeHealthHandler(),
InfoHandler: handlers.MakeInfoHandler(version.BuildVersion(), version.GitCommit),
}
var port int
port = cfg.Port
bootstrapConfig := bootTypes.FaaSConfig{
ReadTimeout: cfg.ReadTimeout,
WriteTimeout: cfg.WriteTimeout,
TCPPort: &port,
EnableHealth: true,
}
bootstrap.Serve(&bootstrapHandlers, &bootstrapConfig)
}