Skip to content

Commit

Permalink
feat(api): compare hatchery and job region for register (#6156)
Browse files Browse the repository at this point in the history
  • Loading branch information
richardlt authored Apr 27, 2022
1 parent 97a158c commit 152dda5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions engine/api/worker/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 152dda5

Please sign in to comment.