Skip to content

Commit

Permalink
feat(hatcheries): ignoreJobWithNoRegion conf (#5233)
Browse files Browse the repository at this point in the history
* feat(hatcheries): ignoreJobWithNoRegion conf

Ignore job without a region prerequisite if ignoreJobWithNoRegion=true

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Jun 5, 2020
1 parent 614b834 commit 0dc2ef8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 42 deletions.
1 change: 1 addition & 0 deletions engine/service/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type HatcheryCommonConfiguration struct {
MaxConcurrentRegistering int `toml:"maxConcurrentRegistering" default:"2" comment:"Maximum allowed simultaneous workers registering. -1 to disable registering on this hatchery" json:"maxConcurrentRegistering"`
RegisterFrequency int `toml:"registerFrequency" default:"60" comment:"Check if some worker model have to be registered each n Seconds" json:"registerFrequency"`
Region string `toml:"region" default:"" comment:"region of this hatchery - optional. With a free text as 'myregion', user can set a prerequisite 'region' with value 'myregion' on CDS Job" json:"region"`
IgnoreJobWithNoRegion bool `toml:"ignoreJobWithNoRegion" default:"false" comment:"Ignore job without a region prerequisite if ignoreJobWithNoRegion=true"`
WorkerLogsOptions struct {
Graylog struct {
Host string `toml:"host" comment:"Example: thot.ovh.com" json:"host"`
Expand Down
15 changes: 14 additions & 1 deletion sdk/hatchery/hatchery.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,20 @@ func Create(ctx context.Context, h Interface) error {
// Check at least one worker model can match
var chosenModel *sdk.Model
var canTakeJob bool
if isWithModels {

var containsRegionRequirement bool
for _, r := range workerRequest.requirements {
switch r.Type {
case sdk.RegionRequirement:
containsRegionRequirement = true
break
}
}

if !containsRegionRequirement && h.Configuration().Provision.IgnoreJobWithNoRegion {
log.Debug("cannot launch this job because it does not contains a region prerequisite and IgnoreJobWithNoRegion=true in hatchery configuration")
canTakeJob = false
} else if isWithModels {
for i := range models {
if canRunJobWithModel(ctx, hWithModels, workerRequest, &models[i]) {
chosenModel = &models[i]
Expand Down
41 changes: 0 additions & 41 deletions sdk/hatchery/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,6 @@ type WorkerJWTClaims struct {
Worker SpawnArguments
}

// CommonConfiguration is the base configuration for all hatcheries
type CommonConfiguration struct {
Name string `toml:"name" default:"" comment:"Name of Hatchery" json:"name"`
HTTP struct {
Addr string `toml:"addr" default:"" commented:"true" comment:"Listen address without port, example: 127.0.0.1" json:"addr"`
Port int `toml:"port" default:"8086" json:"port"`
} `toml:"http" comment:"######################\n CDS Hatchery HTTP Configuration \n######################" json:"http"`
URL string `toml:"url" default:"http://localhost:8086" comment:"URL of this Hatchery" json:"url"`
API struct {
HTTP struct {
URL string `toml:"url" default:"http://localhost:8081" comment:"CDS API URL" json:"url"`
Insecure bool `toml:"insecure" default:"false" commented:"true" comment:"sslInsecureSkipVerify, set to true if you use a self-signed SSL on CDS API" json:"insecure"`
} `toml:"http" json:"http"`
Token string `toml:"token" default:"" comment:"CDS Token to reach CDS API. See https://ovh.github.io/cds/docs/components/cdsctl/token/ " json:"-"`
RequestTimeout int `toml:"requestTimeout" default:"10" comment:"Request CDS API: timeout in seconds" json:"requestTimeout"`
MaxHeartbeatFailures int `toml:"maxHeartbeatFailures" default:"10" comment:"Maximum allowed consecutives failures on heatbeat routine" json:"maxHeartbeatFailures"`
} `toml:"api" json:"api"`
Provision struct {
Frequency int `toml:"frequency" default:"30" comment:"Check provisioning each n Seconds" json:"frequency"`
MaxWorker int `toml:"maxWorker" default:"10" comment:"Maximum allowed simultaneous workers" json:"maxWorker"`
MaxConcurrentProvisioning int `toml:"maxConcurrentProvisioning" default:"10" comment:"Maximum allowed simultaneous workers provisioning" json:"maxConcurrentProvisioning"`
MaxConcurrentRegistering int `toml:"maxConcurrentRegistering" default:"2" comment:"Maximum allowed simultaneous workers registering. -1 to disable registering on this hatchery" json:"maxConcurrentRegistering"`
RegisterFrequency int `toml:"registerFrequency" default:"60" comment:"Check if some worker model have to be registered each n Seconds" json:"registerFrequency"`
WorkerLogsOptions struct {
Graylog struct {
Host string `toml:"host" comment:"Example: thot.ovh.com" json:"host"`
Port int `toml:"port" comment:"Example: 12202" json:"port"`
Protocol string `toml:"protocol" default:"tcp" comment:"tcp or udp" json:"protocol"`
ExtraKey string `toml:"extraKey" comment:"Example: X-OVH-TOKEN. You can use many keys: aaa,bbb" json:"extraKey"`
ExtraValue string `toml:"extraValue" comment:"value for extraKey field. For many keys: valueaaa,valuebbb" json:"-"`
} `toml:"graylog" json:"graylog"`
} `toml:"workerLogsOptions" comment:"Worker Log Configuration" json:"workerLogsOptions"`
} `toml:"provision" json:"provision"`
LogOptions struct {
SpawnOptions struct {
ThresholdCritical int `toml:"thresholdCritical" default:"480" comment:"log critical if spawn take more than this value (in seconds)" json:"thresholdCritical"`
ThresholdWarning int `toml:"thresholdWarning" default:"360" comment:"log warning if spawn take more than this value (in seconds)" json:"thresholdWarning"`
} `toml:"spawnOptions" json:"spawnOptions"`
} `toml:"logOptions" comment:"Hatchery Log Configuration" json:"logOptions"`
}

// SpawnArguments contains arguments to func SpawnWorker
type SpawnArguments struct {
WorkerName string `json:"worker_model"`
Expand Down

0 comments on commit 0dc2ef8

Please sign in to comment.