hashicorp/nomad · error
Job must be in a namespace
Error message
Job must be in a namespace
What it means
Job.Validate() requires every job to belong to a namespace. Namespaces partition jobs, allocations, and quotas in enterprise and OSS Nomad. If j.Namespace is the empty string, this error is appended to the validation multierror.
Source
Thrown at nomad/structs/structs.go:4757
if j.Region == "" && j.Multiregion == nil {
mErr.Errors = append(mErr.Errors, errors.New("Missing job region"))
}
if j.ID == "" {
mErr.Errors = append(mErr.Errors, errors.New("Missing job ID"))
} else if strings.Contains(j.ID, " ") {
mErr.Errors = append(mErr.Errors, errors.New("Job ID contains a space"))
} else if strings.Contains(j.ID, "\000") {
mErr.Errors = append(mErr.Errors, errors.New("Job ID contains a null character"))
}
if j.Name == "" {
mErr.Errors = append(mErr.Errors, errors.New("Missing job name"))
} else if strings.Contains(j.Name, "\000") {
mErr.Errors = append(mErr.Errors, errors.New("Job Name contains a null character"))
}
if j.Namespace == "" {
mErr.Errors = append(mErr.Errors, errors.New("Job must be in a namespace"))
}
switch j.Type {
case JobTypeCore, JobTypeService, JobTypeBatch, JobTypeSystem, JobTypeSysBatch:
case "":
mErr.Errors = append(mErr.Errors, errors.New("Missing job type"))
default:
mErr.Errors = append(mErr.Errors, fmt.Errorf("Invalid job type: %q", j.Type))
}
if len(j.Datacenters) == 0 && !j.IsMultiregion() {
mErr.Errors = append(mErr.Errors, errors.New("Missing job datacenters"))
} else {
for _, v := range j.Datacenters {
if v == "" {
mErr.Errors = append(mErr.Errors, errors.New("Job datacenter must be non-empty string"))
}
}
}
View on GitHub (pinned to 482b49bf1a)
Solutions
- Set `namespace = "default"` (or target namespace) in the job HCL/JSON
- Pass -namespace on the CLI (nomad job run -namespace=prod) or set the X-Nomad-Namespace header
- Assign j.Namespace = "default" when constructing the job in Go before Validate()
Example fix
// before
job "web-app" {
...
}
// after
job "web-app" {
namespace = "prod"
...
} Defensive patterns
Strategy: validation
Validate before calling
if j.Namespace == "" {
j.Namespace = structs.DefaultNamespace // "default"
} Type guard
func hasNamespace(j *structs.Job) bool { return j != nil && j.Namespace != "" } Try / catch
if err := job.Validate(); err != nil {
if strings.Contains(err.Error(), "namespace") {
return fmt.Errorf("job must target a namespace (use -namespace or the namespace stanza): %w", err)
}
} Prevention
- Set namespace explicitly in job files used across environments
- Pass -namespace on CLI commands or set the X-Nomad-Namespace header
- Default j.Namespace = "default" in programmatic job builders
When it happens
Trigger: Submitting a job with no `namespace` set in the job spec and no default namespace applied client-side; calling Job.Validate() on a structs.Job whose Namespace field was never populated.
Common situations: Using a Nomad Enterprise namespace with clients/ACL tokens not setting the namespace; upgrading tooling that previously relied on the server defaulting the namespace; API payloads built by hand that omit namespace.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- job_submission requires a namespace
- Missing job ID
- Job ID contains a space
- Job ID contains a null character
- Missing job name
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/9e2e4136bd8a501a.
Report an issue: GitHub.