-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathmimoscheduler.go
More file actions
121 lines (94 loc) · 2.52 KB
/
mimoscheduler.go
File metadata and controls
121 lines (94 loc) · 2.52 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"os"
"os/signal"
"syscall"
"github.com/sirupsen/logrus"
"github.com/Azure/go-autorest/tracing"
"github.com/Azure/ARO-RP/pkg/database"
"github.com/Azure/ARO-RP/pkg/env"
"github.com/Azure/ARO-RP/pkg/metrics/statsd"
"github.com/Azure/ARO-RP/pkg/metrics/statsd/azure"
"github.com/Azure/ARO-RP/pkg/metrics/statsd/golang"
"github.com/Azure/ARO-RP/pkg/mimo/scheduler"
"github.com/Azure/ARO-RP/pkg/mimo/tasks"
"github.com/Azure/ARO-RP/pkg/util/encryption"
)
func mimoScheduler(ctx context.Context, _log *logrus.Entry) error {
stop := make(chan struct{})
_env, err := env.NewEnv(ctx, _log, env.SERVICE_MIMO_SCHEDULER)
if err != nil {
return err
}
keys := []string{}
if !_env.IsLocalDevelopmentMode() {
keys = []string{
"MDM_ACCOUNT",
"MDM_NAMESPACE",
}
}
if err = env.ValidateVars(keys...); err != nil {
return err
}
log := _env.Logger()
m := statsd.New(ctx, _env, os.Getenv("MDM_ACCOUNT"), os.Getenv("MDM_NAMESPACE"), os.Getenv("MDM_STATSD_SOCKET"))
go m.Run(stop)
g, err := golang.NewMetrics(log, m)
if err != nil {
return err
}
go g.Run()
tracing.Register(azure.New(m))
aead, err := encryption.NewAEADWithCore(ctx, _env, env.EncryptionSecretV2Name, env.EncryptionSecretName)
if err != nil {
return err
}
dbc, err := database.NewDatabaseClientFromEnv(ctx, _env, m, aead)
if err != nil {
return err
}
dbName, err := env.DBName(_env)
if err != nil {
return err
}
clusters, err := database.NewOpenShiftClusters(ctx, dbc, dbName)
if err != nil {
return err
}
subscriptions, err := database.NewSubscriptions(ctx, dbc, dbName)
if err != nil {
return err
}
manifests, err := database.NewMaintenanceManifests(ctx, dbc, dbName)
if err != nil {
return err
}
schedules, err := database.NewMaintenanceSchedules(ctx, dbc, dbName)
if err != nil {
return err
}
poolWorkers, err := database.NewPoolWorkers(ctx, dbc, dbName)
if err != nil {
return err
}
dbg := database.NewDBGroup().
WithOpenShiftClusters(clusters).
WithSubscriptions(subscriptions).
WithMaintenanceManifests(manifests).
WithMaintenanceSchedules(schedules).
WithPoolWorkers(poolWorkers)
a := scheduler.NewService(_env, log, dbg, m)
a.SetMaintenanceTasks(tasks.DEFAULT_MAINTENANCE_TASKS)
sigterm := make(chan os.Signal, 1)
done := make(chan struct{})
signal.Notify(sigterm, syscall.SIGTERM)
go a.Run(ctx, stop, done)
<-sigterm
log.Print("received SIGTERM")
close(stop)
<-done
return nil
}