diff --git a/engine/service/types.go b/engine/service/types.go index ccbe9995a8..44b0dbea44 100644 --- a/engine/service/types.go +++ b/engine/service/types.go @@ -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"` diff --git a/sdk/hatchery/hatchery.go b/sdk/hatchery/hatchery.go index 50a292e0af..9bef179e26 100644 --- a/sdk/hatchery/hatchery.go +++ b/sdk/hatchery/hatchery.go @@ -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] diff --git a/sdk/hatchery/types.go b/sdk/hatchery/types.go index 54d4fb8394..8fed50226d 100644 --- a/sdk/hatchery/types.go +++ b/sdk/hatchery/types.go @@ -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"`