hashicorp/nomad · error
missing target namespace
Error message
missing target namespace
What it means
ScalingPolicy.validateTargetHorizontal() checks that a horizontal policy's `target` map contains a non-empty `Namespace` key. Nomad horizontal policies must identify the job and group they scale via Namespace/Job/TaskGroup target keys; a missing Namespace produces this error.
Source
Thrown at nomad/structs/structs.go:6466
}
if p.Min < 0 {
mErr.Errors = append(mErr.Errors,
fmt.Errorf("minimum count must be specified and non-negative"))
}
return mErr.ErrorOrNil()
}
func (p *ScalingPolicy) validateTargetHorizontal() (mErr multierror.Error) {
if len(p.Target) == 0 {
// This is probably not a Nomad horizontal policy
return
}
// Nomad horizontal policies should have Namespace, Job and TaskGroup
if p.Target[ScalingTargetNamespace] == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("missing target namespace"))
}
if p.Target[ScalingTargetJob] == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("missing target job"))
}
if p.Target[ScalingTargetGroup] == "" {
mErr.Errors = append(mErr.Errors, fmt.Errorf("missing target group"))
}
return
}
// Diff indicates whether the specification for a given scaling policy has changed
func (p *ScalingPolicy) Diff(p2 *ScalingPolicy) bool {
copy := *p2
copy.ID = p.ID
copy.CreateIndex = p.CreateIndex
copy.ModifyIndex = p.ModifyIndex
return !reflect.DeepEqual(*p, copy)
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Add `namespace = "default"` (or the correct namespace) inside the policy's target block.
- When using the API, set Target["Namespace"] in the policy JSON.
- Validate with `nomad job validate` or the scaling policy validate endpoint.
Example fix
// before
policy {
type = "horizontal"
target {}
}
// after
policy {
type = "horizontal"
target {
namespace = "default"
job = "web"
group = "frontend"
}
} Defensive patterns
Strategy: validation
Validate before calling
required := []string{"Namespace", "Job", "TaskGroup"}
for _, k := range required {
if policy.Target[k] == "" {
return fmt.Errorf("horizontal policy target missing %s", k)
}
} Prevention
- Always populate the full target triple (namespace, job, group) for horizontal policies.
- For policies inside a job file, use inline scaling blocks so Nomad infers target keys.
- Validate standalone API policies against the required-key checklist before registering.
When it happens
Trigger: Submitting a scaling policy whose `policy { target { } }` block omits `namespace`, or an API object with Target["Namespace"] == "", when the policy type is horizontal.
Common situations: Hand-written policy blocks missing the target stanza; external autoscaler tooling building Target maps without the Namespace key; cluster namespace renamed but policy not updated (though omission, not wrong value, triggers this).
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
- missing target job
- missing target group
- missing scaling policy type
- maximum count must be specified and non-negative
- maximum count must not be less than minimum count
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/f067157d9605219b.
Report an issue: GitHub.