{"record":{"id":"3a5c3d6e7346b876","repo":"hashicorp/nomad","slug":"invalid-constraint-s-host-volumes-of-the-same-na","errorCode":null,"errorMessage":"invalid constraint %s: host volumes of the same name are always on distinct hosts","messagePattern":"invalid constraint (.+?): host volumes of the same name are always on distinct hosts","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/host_volumes.go","lineNumber":165,"sourceCode":"\t\t\t\"capacity_max (%d) must be larger than capacity_min (%d)\",\n\t\t\thv.RequestedCapacityMaxBytes, hv.RequestedCapacityMinBytes))\n\t}\n\n\tfor _, cap := range hv.RequestedCapabilities {\n\t\terr := cap.Validate()\n\t\tif err != nil {\n\t\t\tmErr = multierror.Append(mErr, err)\n\t\t}\n\t}\n\n\tfor _, constraint := range hv.Constraints {\n\t\tif err := constraint.Validate(); err != nil {\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\"invalid constraint: %v\", err))\n\t\t}\n\t\tswitch constraint.Operand {\n\t\tcase ConstraintDistinctHosts, ConstraintDistinctProperty:\n\t\t\tmErr = multierror.Append(mErr, fmt.Errorf(\n\t\t\t\t\"invalid constraint %s: host volumes of the same name are always on distinct hosts\", constraint.Operand))\n\t\tdefault:\n\t\t}\n\t}\n\n\treturn helper.FlattenMultierror(mErr.ErrorOrNil())\n}\n\n// ValidateUpdate verifies that an update to a volume is safe to make.\nfunc (hv *HostVolume) ValidateUpdate(existing *HostVolume) error {\n\tif existing == nil {\n\t\treturn nil\n\t}\n\n\tvar mErr *multierror.Error\n\tif len(existing.Allocations) > 0 {\n\t\tallocIDs := helper.ConvertSlice(existing.Allocations,\n\t\t\tfunc(a *AllocListStub) string { return a.ID })\n\t\tmErr = multierror.Append(mErr, fmt.Errorf(","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/host_volumes.go#L147-L183","documentation":"Host volume validation rejects constraint operands that would be meaningless on a host volume: DistinctHosts and DistinctProperty. Because each host volume is bound to a specific node, volumes of the same name are inherently on distinct hosts, so these constraints are redundant and therefore rejected. Validation walks every constraint on the HostVolume and appends this error for each offending operand.","triggerScenarios":"Calling HostVolume.Validate (directly or via the volume register/update RPC -> validateVolumeUpdate) with a Constraints entry whose Operand is set to 'distinct_hosts' or 'distinct_property'.","commonSituations":"Copy-pasting a task/group constraint block into a host volume definition; migrating job-level volume config into the new host volume spec; tooling generating constraints generically without filtering by object type.","solutions":["Remove the distinct_hosts or distinct_property constraint from the host volume definition","If the intent was scheduling spread, move the constraint to the job/task group instead of the volume","Re-run nomad job validate / volume validate before submitting"],"exampleFix":"// before\nConstraints: []*Constraint{{Operand: \"distinct_hosts\"}}\n// after\nConstraints: nil // distinct-hosts semantics are implicit for host volumes","handlingStrategy":"validation","validationCode":"for _, c := range hv.Constraints {\n  if c.Operand == \"distinct_hosts\" || c.Operand == \"distinct_property\" {\n    return fmt.Errorf(\"constraint %s not allowed on host volumes\", c.Operand)\n  }\n}","typeGuard":"func isForbiddenVolumeConstraint(op string) bool {\n  return op == structs.ConstraintDistinctHosts || op == structs.ConstraintDistinctProperty\n}","tryCatchPattern":null,"preventionTips":["Never copy job/task constraint blocks into host volume definitions","Run nomad volume validate in CI before submitting volume specs","Lint HCL for distinct_hosts/distinct_property under host volume blocks"],"tags":["nomad","validation","host-volume","constraint"],"backgroundTag":"invalid-constraint-operand","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"}