-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
dagent.go
53 lines (43 loc) · 1.41 KB
/
dagent.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
package dagent
import (
"context"
"log"
"github.com/dyrector-io/dyrectorio/agent/internal/grpc"
"github.com/dyrector-io/dyrectorio/agent/pkg/dagent/config"
"github.com/dyrector-io/dyrectorio/agent/pkg/dagent/model"
"github.com/dyrector-io/dyrectorio/agent/pkg/dagent/update"
"github.com/dyrector-io/dyrectorio/agent/pkg/dagent/utils"
)
func Serve(cfg *config.Configuration) {
utils.PreflightChecks(cfg)
log.Println("Starting dyrector.io DAgent service")
grpcToken := cfg.GrpcToken
grpcInsecure := cfg.GrpcInsecure
if grpcToken == "" {
log.Panic("no grpc address was provided")
}
if cfg.TraefikEnabled {
params := model.TraefikDeployRequest{
LogLevel: cfg.TraefikLogLevel,
TLS: cfg.TraefikTLS,
AcmeMail: cfg.TraefikAcmeMail,
}
err := utils.ExecTraefik(context.Background(), params, cfg)
if err != nil {
// we wanted to start traefik, but something is not ok, thus panic!
log.Panic("failed to start Traefik: ", err)
}
}
update.InitUpdater(cfg)
grpcParams, err := grpc.GrpcTokenToConnectionParams(grpcToken, grpcInsecure)
if err != nil {
log.Panic("gRPC token error: ", err)
}
grpcContext := grpc.WithGRPCConfig(context.Background(), cfg)
grpc.Init(grpcContext, grpcParams, &cfg.CommonConfiguration, grpc.WorkerFunctions{
Deploy: utils.DeployImage,
Watch: utils.GetContainersByNameCrux,
Delete: utils.DeleteContainerByName,
SecretList: utils.SecretList,
})
}