{"record":{"id":"f067157d9605219b","repo":"hashicorp/nomad","slug":"missing-target-namespace","errorCode":null,"errorMessage":"missing target namespace","messagePattern":"missing target namespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":6466,"sourceCode":"\t}\n\n\tif p.Min < 0 {\n\t\tmErr.Errors = append(mErr.Errors,\n\t\t\tfmt.Errorf(\"minimum count must be specified and non-negative\"))\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\nfunc (p *ScalingPolicy) validateTargetHorizontal() (mErr multierror.Error) {\n\tif len(p.Target) == 0 {\n\t\t// This is probably not a Nomad horizontal policy\n\t\treturn\n\t}\n\n\t// Nomad horizontal policies should have Namespace, Job and TaskGroup\n\tif p.Target[ScalingTargetNamespace] == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"missing target namespace\"))\n\t}\n\tif p.Target[ScalingTargetJob] == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"missing target job\"))\n\t}\n\tif p.Target[ScalingTargetGroup] == \"\" {\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"missing target group\"))\n\t}\n\treturn\n}\n\n// Diff indicates whether the specification for a given scaling policy has changed\nfunc (p *ScalingPolicy) Diff(p2 *ScalingPolicy) bool {\n\tcopy := *p2\n\tcopy.ID = p.ID\n\tcopy.CreateIndex = p.CreateIndex\n\tcopy.ModifyIndex = p.ModifyIndex\n\treturn !reflect.DeepEqual(*p, copy)\n}","sourceCodeStart":6448,"sourceCodeEnd":6484,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L6448-L6484","documentation":"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.","triggerScenarios":"Submitting a scaling policy whose `policy { target { } }` block omits `namespace`, or an API object with Target[\"Namespace\"] == \"\", when the policy type is horizontal.","commonSituations":"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).","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."],"exampleFix":"// before\npolicy {\n  type = \"horizontal\"\n  target {}\n}\n// after\npolicy {\n  type = \"horizontal\"\n  target {\n    namespace = \"default\"\n    job       = \"web\"\n    group     = \"frontend\"\n  }\n}","handlingStrategy":"validation","validationCode":"required := []string{\"Namespace\", \"Job\", \"TaskGroup\"}\nfor _, k := range required {\n\tif policy.Target[k] == \"\" {\n\t\treturn fmt.Errorf(\"horizontal policy target missing %s\", k)\n\t}\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["nomad","scaling-policy","target","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}