-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
inject_scheduler.go
130 lines (122 loc) · 4.57 KB
/
inject_scheduler.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright 2019 Drone IO, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"github.com/drone/drone/cmd/drone-server/config"
"github.com/drone/drone/core"
"github.com/drone/drone/scheduler/kube"
"github.com/drone/drone/scheduler/nomad"
"github.com/drone/drone/scheduler/queue"
"github.com/google/wire"
"github.com/sirupsen/logrus"
)
// wire set for loading the scheduler.
var schedulerSet = wire.NewSet(
provideScheduler,
)
// provideScheduler is a Wire provider function that returns a
// scheduler based on the environment configuration.
func provideScheduler(store core.StageStore, config config.Config) core.Scheduler {
switch {
case config.Agent.Enabled:
return provideQueueScheduler(store, config)
case config.Kube.Enabled:
return provideKubernetesScheduler(config)
case config.Nomad.Enabled:
return provideNomadScheduler(config)
default:
return provideQueueScheduler(store, config)
}
}
// provideKubernetesScheduler is a Wire provider function that
// returns a nomad kubernetes from the environment configuration.
func provideKubernetesScheduler(config config.Config) core.Scheduler {
logrus.Info("main: kubernetes scheduler enabled")
sched, err := kube.FromConfig(kube.Config{
Namespace: config.Kube.Namespace,
ServiceAccount: config.Kube.ServiceAccountName,
ConfigURL: config.Kube.URL,
ConfigPath: config.Kube.Path,
TTL: config.Kube.TTL,
Image: config.Kube.Image,
ImagePullPolicy: config.Kube.PullPolicy,
ImagePrivileged: config.Runner.Privileged,
// LimitMemory: config.Nomad.Memory,
// LimitCompute: config.Nomad.CPU,
// RequestMemory: config.Nomad.Memory,
// RequestCompute: config.Nomad.CPU,
CallbackHost: config.RPC.Host,
CallbackProto: config.RPC.Proto,
CallbackSecret: config.RPC.Secret,
SecretToken: config.Secrets.Password,
SecretEndpoint: config.Secrets.Endpoint,
SecretInsecure: config.Secrets.SkipVerify,
RegistryToken: config.Registries.Password,
RegistryEndpoint: config.Registries.Endpoint,
RegistryInsecure: config.Registries.SkipVerify,
LogDebug: config.Logging.Debug,
LogTrace: config.Logging.Trace,
LogPretty: config.Logging.Pretty,
LogText: config.Logging.Text,
})
if err != nil {
logrus.WithError(err).
Fatalln("main: cannot create kubernetes client")
}
return sched
}
// provideNomadScheduler is a Wire provider function that returns
// a nomad scheduler from the environment configuration.
func provideNomadScheduler(config config.Config) core.Scheduler {
logrus.Info("main: nomad scheduler enabled")
sched, err := nomad.FromConfig(nomad.Config{
Datacenter: config.Nomad.Datacenters,
Namespace: config.Nomad.Namespace,
Region: config.Nomad.Region,
DockerImage: config.Nomad.Image,
DockerImagePull: config.Nomad.ImagePull,
DockerImagePriv: config.Runner.Privileged,
DockerHost: "",
DockerHostWin: "",
// LimitMemory: config.Nomad.Memory,
// LimitCompute: config.Nomad.CPU,
RequestMemory: config.Nomad.Memory,
RequestCompute: config.Nomad.CPU,
CallbackHost: config.RPC.Host,
CallbackProto: config.RPC.Proto,
CallbackSecret: config.RPC.Secret,
SecretToken: config.Secrets.Password,
SecretEndpoint: config.Secrets.Endpoint,
SecretInsecure: config.Secrets.SkipVerify,
RegistryToken: config.Registries.Password,
RegistryEndpoint: config.Registries.Endpoint,
RegistryInsecure: config.Registries.SkipVerify,
LogDebug: config.Logging.Debug,
LogTrace: config.Logging.Trace,
LogPretty: config.Logging.Pretty,
LogText: config.Logging.Text,
})
if err != nil {
logrus.WithError(err).
Fatalln("main: cannot create nomad client")
}
return sched
}
// provideQueueScheduler is a Wire provider function that
// returns an in-memory scheduler for use by the built-in
// docker runner, and by remote agents.
func provideQueueScheduler(store core.StageStore, config config.Config) core.Scheduler {
logrus.Info("main: internal scheduler enabled")
return queue.New(store)
}