{"record":{"id":"59f88e93737618d9","repo":"hashicorp/nomad","slug":"volume-validation-failed-no-such-namespace-q","errorCode":null,"errorMessage":"volume validation failed: no such namespace %q","messagePattern":"volume validation failed: no such namespace %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/host_volume_endpoint.go","lineNumber":427,"sourceCode":"\treply.Index = index\n\treturn nil\n}\n\nfunc (v *HostVolume) validateVolumeUpdate(\n\tvol *structs.HostVolume, snap *state.StateSnapshot) (*structs.HostVolume, error) {\n\n\t// validate the volume spec\n\terr := vol.Validate()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"volume validation failed: %w\", err)\n\t}\n\n\tns, err := snap.NamespaceByName(nil, vol.Namespace)\n\tif err != nil {\n\t\treturn nil, err // should never hit, bail out\n\t}\n\tif ns == nil {\n\t\treturn nil, fmt.Errorf(\"volume validation failed: no such namespace %q\", vol.Namespace)\n\t}\n\n\t// validate any update we're making\n\tvar existing *structs.HostVolume\n\tif vol.ID != \"\" {\n\t\texisting, err = snap.HostVolumeByID(nil, vol.Namespace, vol.ID, true)\n\t\tif err != nil {\n\t\t\treturn nil, err // should never hit, bail out\n\t\t}\n\t\tif existing == nil {\n\t\t\treturn nil, fmt.Errorf(\"cannot update volume %q: volume does not exist\", vol.ID)\n\t\t}\n\t\terr = vol.ValidateUpdate(existing)\n\t\tif err != nil {\n\t\t\treturn existing, fmt.Errorf(\"validating volume %q update failed: %v\", vol.ID, err)\n\t\t}\n\t}\n\treturn existing, nil","sourceCodeStart":409,"sourceCodeEnd":445,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/host_volume_endpoint.go#L409-L445","documentation":"After structural validation, validateVolumeUpdate looks up the volume's namespace in the state snapshot. If the lookup returns no namespace, the volume references a namespace that does not exist and the update fails with this explicit message. Create and Register both funnel through this check.","triggerScenarios":"Submitting a host volume via Create or Register whose vol.Namespace names a namespace absent from state, and the namespace field wasn't defaulted from the request namespace (Register defaults only when empty).","commonSituations":"Typo in the namespace field; namespace deleted after the spec was written; multi-namespace clusters where specs are reused across clusters; ACL tokens scoped to a different namespace causing confusion.","solutions":["Create the missing namespace first (`nomad namespace apply <name>`) or fix the name.","Remove the explicit namespace field so it defaults to the request namespace.","List namespaces with `nomad namespace list` and match the spec to an existing one.","Check the spec for cross-cluster copy/paste of namespace names."],"exampleFix":"// before\nvolume {\n  name      = \"web-data\"\n  namespace = \"prod-eu\"  // does not exist\n}\n// after\nnomad namespace apply prod-eu\n# or\nvolume {\n  name = \"web-data\"\n  # namespace omitted -> defaults to request namespace\n}","handlingStrategy":"validation","validationCode":"namespaces, _, _ := client.Namespaces().List(nil)\nfound := false\nfor _, ns := range namespaces {\n    if ns.Name == vol.Namespace { found = true }\n}\nif !found { return fmt.Errorf(\"namespace %q does not exist\", vol.Namespace) }","typeGuard":"func namespaceExists(name string, nsList []*api.Namespace) bool {\n    for _, ns := range nsList { if ns.Name == name { return true } }\n    return false\n}","tryCatchPattern":"if strings.Contains(err.Error(), \"no such namespace\") {\n    // create the namespace or fix the spec's namespace field\n}","preventionTips":["Confirm namespaces with `nomad namespace list` before deploying specs","Omit namespace to inherit the request namespace","Template namespaces per environment instead of hard-coding","Reconcile specs after namespace deletions"],"tags":["nomad","host-volumes","namespace","validation"],"backgroundTag":"namespace-not-found","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"}