diff --git a/nomad/deployment_watcher_shims.go b/nomad/deployment_watcher_shims.go index ad2dbdcda..fe2f22cf5 100644 --- a/nomad/deployment_watcher_shims.go +++ b/nomad/deployment_watcher_shims.go @@ -6,6 +6,10 @@ import "github.com/hashicorp/nomad/nomad/structs" // methods. These should be set by the server and passed to the deployment // watcher. type deploymentWatcherStateShim struct { + // region is the region the server is a member of. It is used to + // auto-populate requests that do not have it set + region string + // evaluations returns the set of evaluations for the given job evaluations func(args *structs.JobSpecificRequest, reply *structs.JobEvaluationsResponse) error @@ -25,22 +29,42 @@ type deploymentWatcherStateShim struct { } func (d *deploymentWatcherStateShim) Evaluations(args *structs.JobSpecificRequest, reply *structs.JobEvaluationsResponse) error { + if args.Region == "" { + args.Region = d.region + } + return d.evaluations(args, reply) } func (d *deploymentWatcherStateShim) Allocations(args *structs.DeploymentSpecificRequest, reply *structs.AllocListResponse) error { + if args.Region == "" { + args.Region = d.region + } + return d.allocations(args, reply) } func (d *deploymentWatcherStateShim) List(args *structs.DeploymentListRequest, reply *structs.DeploymentListResponse) error { + if args.Region == "" { + args.Region = d.region + } + return d.list(args, reply) } func (d *deploymentWatcherStateShim) GetJobVersions(args *structs.JobSpecificRequest, reply *structs.JobVersionsResponse) error { + if args.Region == "" { + args.Region = d.region + } + return d.getJobVersions(args, reply) } func (d *deploymentWatcherStateShim) GetJob(args *structs.JobSpecificRequest, reply *structs.SingleJobResponse) error { + if args.Region == "" { + args.Region = d.region + } + return d.getJob(args, reply) } diff --git a/nomad/server.go b/nomad/server.go index ed07a94d5..51a287e8e 100644 --- a/nomad/server.go +++ b/nomad/server.go @@ -686,6 +686,7 @@ func (s *Server) setupDeploymentWatcher() error { // Create the shims stateShim := &deploymentWatcherStateShim{ + region: s.Region(), evaluations: s.endpoints.Job.Evaluations, allocations: s.endpoints.Deployment.Allocations, list: s.endpoints.Deployment.List, diff --git a/nomad/state/schema.go b/nomad/state/schema.go index 600c551c9..6d9675c86 100644 --- a/nomad/state/schema.go +++ b/nomad/state/schema.go @@ -383,7 +383,7 @@ func allocTableSchema() *memdb.TableSchema { // Deployment index is used to lookup allocations by deployment "deployment": &memdb.IndexSchema{ Name: "deployment", - AllowMissing: false, + AllowMissing: true, Unique: false, Indexer: &memdb.UUIDFieldIndex{ Field: "DeploymentID",