Add default labels to all Nomad Drone Controller jobs on creation
This commit is contained in:
parent
f1dd01e50c
commit
b63c11cb3b
4 changed files with 20 additions and 9 deletions
|
@ -143,15 +143,16 @@ type (
|
|||
|
||||
// Nomad configuration.
|
||||
Nomad struct {
|
||||
Enabled bool `envconfig:"DRONE_NOMAD_ENABLED"`
|
||||
Datacenters []string `envconfig:"DRONE_NOMAD_DATACENTER" default:"dc1"`
|
||||
Namespace string `envconfig:"DRONE_NOMAD_NAMESPACE"`
|
||||
Region string `envconfig:"DRONE_NOMAD_REGION"`
|
||||
Prefix string `envconfig:"DRONE_NOMAD_JOB_PREFIX" default:"drone-job-"`
|
||||
Image string `envconfig:"DRONE_NOMAD_IMAGE"`
|
||||
ImagePull bool `envconfig:"DRONE_NOMAD_IMAGE_PULL"`
|
||||
Memory int `envconfig:"DRONE_NOMAD_DEFAULT_RAM" default:"1024"`
|
||||
CPU int `envconfig:"DRONE_NOMAD_DEFAULT_CPU" default:"500"`
|
||||
Enabled bool `envconfig:"DRONE_NOMAD_ENABLED"`
|
||||
Datacenters []string `envconfig:"DRONE_NOMAD_DATACENTER" default:"dc1"`
|
||||
Namespace string `envconfig:"DRONE_NOMAD_NAMESPACE"`
|
||||
Region string `envconfig:"DRONE_NOMAD_REGION"`
|
||||
Prefix string `envconfig:"DRONE_NOMAD_JOB_PREFIX" default:"drone-job-"`
|
||||
Image string `envconfig:"DRONE_NOMAD_IMAGE"`
|
||||
ImagePull bool `envconfig:"DRONE_NOMAD_IMAGE_PULL"`
|
||||
Memory int `envconfig:"DRONE_NOMAD_DEFAULT_RAM" default:"1024"`
|
||||
Labels map[string]string `envconfig:"DRONE_NOMAD_LABELS"`
|
||||
CPU int `envconfig:"DRONE_NOMAD_DEFAULT_CPU" default:"500"`
|
||||
}
|
||||
|
||||
// License provides license configuration
|
||||
|
|
|
@ -87,6 +87,7 @@ func provideNomadScheduler(config config.Config) core.Scheduler {
|
|||
logrus.Info("main: nomad scheduler enabled")
|
||||
sched, err := nomad.FromConfig(nomad.Config{
|
||||
Datacenter: config.Nomad.Datacenters,
|
||||
Labels: config.Nomad.Labels,
|
||||
Namespace: config.Nomad.Namespace,
|
||||
Region: config.Nomad.Region,
|
||||
DockerImage: config.Nomad.Image,
|
||||
|
|
|
@ -17,6 +17,7 @@ package nomad
|
|||
// Config is the configuration for the Nomad scheduler.
|
||||
type Config struct {
|
||||
Datacenter []string
|
||||
Labels map[string]string
|
||||
Namespace string
|
||||
Region string
|
||||
DockerImage string
|
||||
|
|
|
@ -157,6 +157,14 @@ func (s *nomadScheduler) Schedule(ctx context.Context, stage *core.Stage) error
|
|||
})
|
||||
}
|
||||
|
||||
for k, v := range s.config.Labels {
|
||||
job.Constraints = append(job.Constraints, &api.Constraint{
|
||||
LTarget: fmt.Sprintf("${meta.%s}", k),
|
||||
RTarget: v,
|
||||
Operand: "=",
|
||||
})
|
||||
}
|
||||
|
||||
log := logrus.WithFields(logrus.Fields{
|
||||
"stage-id": stage.ID,
|
||||
"stage-number": stage.Number,
|
||||
|
|
Loading…
Reference in a new issue