-
Notifications
You must be signed in to change notification settings - Fork 566
/
server.go
98 lines (91 loc) · 2.85 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package server
import (
"fmt"
"github.com/pachyderm/pachyderm/src/client"
ppsclient "github.com/pachyderm/pachyderm/src/client/pps"
"github.com/pachyderm/pachyderm/src/server/pkg/log"
"github.com/pachyderm/pachyderm/src/server/pkg/metrics"
"github.com/pachyderm/pachyderm/src/server/pkg/ppsdb"
etcd "github.com/coreos/etcd/clientv3"
kube "k8s.io/client-go/kubernetes"
)
// NewAPIServer creates an APIServer.
func NewAPIServer(
etcdAddress string,
etcdPrefix string,
address string,
kubeClient *kube.Clientset,
namespace string,
workerImage string,
workerSidecarImage string,
workerImagePullPolicy string,
storageRoot string,
storageBackend string,
storageHostPath string,
iamRole string,
imagePullSecret string,
noExposeDockerSocket bool,
reporter *metrics.Reporter,
) (ppsclient.APIServer, error) {
etcdClient, err := etcd.New(etcd.Config{
Endpoints: []string{etcdAddress},
DialOptions: client.DefaultDialOptions(),
})
if err != nil {
return nil, fmt.Errorf("could not create etcd client: %v", err)
}
apiServer := &apiServer{
Logger: log.NewLogger("pps.API"),
etcdPrefix: etcdPrefix,
address: address,
etcdClient: etcdClient,
kubeClient: kubeClient,
namespace: namespace,
workerImage: workerImage,
workerSidecarImage: workerSidecarImage,
workerImagePullPolicy: workerImagePullPolicy,
storageRoot: storageRoot,
storageBackend: storageBackend,
storageHostPath: storageHostPath,
iamRole: iamRole,
imagePullSecret: imagePullSecret,
noExposeDockerSocket: noExposeDockerSocket,
reporter: reporter,
pipelines: ppsdb.Pipelines(etcdClient, etcdPrefix),
jobs: ppsdb.Jobs(etcdClient, etcdPrefix),
monitorCancels: make(map[string]func()),
}
apiServer.validateKube()
go apiServer.master() // calls a.getPachClient(), which initializes spec repo
return apiServer, nil
}
// NewSidecarAPIServer creates an APIServer that has limited functionalities
// and is meant to be run as a worker sidecar. It cannot, for instance,
// create pipelines.
func NewSidecarAPIServer(
etcdAddress string,
etcdPrefix string,
address string,
iamRole string,
reporter *metrics.Reporter,
) (ppsclient.APIServer, error) {
etcdClient, err := etcd.New(etcd.Config{
Endpoints: []string{etcdAddress},
DialOptions: client.DefaultDialOptions(),
})
if err != nil {
return nil, err
}
apiServer := &apiServer{
Logger: log.NewLogger("pps.API"),
address: address,
etcdPrefix: etcdPrefix,
etcdClient: etcdClient,
iamRole: iamRole,
reporter: reporter,
pipelines: ppsdb.Pipelines(etcdClient, etcdPrefix),
jobs: ppsdb.Jobs(etcdClient, etcdPrefix),
}
go apiServer.getPachClient() // connects back to pachd and inits spec repo
return apiServer, nil
}