From 152dda52bc988ac41108b080f16bdb2118b6832a Mon Sep 17 00:00:00 2001 From: Richard LT Date: Wed, 27 Apr 2022 18:01:32 +0200 Subject: [PATCH] feat(api): compare hatchery and job region for register (#6156) --- engine/api/worker/registration.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/engine/api/worker/registration.go b/engine/api/worker/registration.go index 4e5552e076..3564a9b3bb 100644 --- a/engine/api/worker/registration.go +++ b/engine/api/worker/registration.go @@ -110,6 +110,15 @@ func RegisterWorker(ctx context.Context, db gorpmapper.SqlExecutorWithTx, store return nil, sdk.WrapError(sdk.ErrForbidden, "hatchery can't register job (id: %q) with model (path: %q) for a group that is not in job's exec groups", spawnArgs.JobID, model.Path()) } } + + // Check additional information based on the consumer if a region is set, allows to register only job with same region. + // TODO add another information on the consumer to allow job with a specific region requirement or no region (runNodeJob.Region == nil). + if hatcheryConsumer.ServiceRegion != nil && *hatcheryConsumer.ServiceRegion != "" { + canTakeJobWithRegion := runNodeJob.Region != nil && *runNodeJob.Region == *hatcheryConsumer.ServiceRegion + if !canTakeJobWithRegion { + return nil, sdk.WrapError(sdk.ErrForbidden, "hatchery can't register job with id %q for region %s", spawnArgs.JobID, *runNodeJob.Region) + } + } } // Instanciate a new worker