hashicorp/nomad · error

volume validation failed: no such namespace %q

Error message

volume validation failed: no such namespace %q

What it means

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.

Source

Thrown at nomad/host_volume_endpoint.go:427

	reply.Index = index
	return nil
}

func (v *HostVolume) validateVolumeUpdate(
	vol *structs.HostVolume, snap *state.StateSnapshot) (*structs.HostVolume, error) {

	// validate the volume spec
	err := vol.Validate()
	if err != nil {
		return nil, fmt.Errorf("volume validation failed: %w", err)
	}

	ns, err := snap.NamespaceByName(nil, vol.Namespace)
	if err != nil {
		return nil, err // should never hit, bail out
	}
	if ns == nil {
		return nil, fmt.Errorf("volume validation failed: no such namespace %q", vol.Namespace)
	}

	// validate any update we're making
	var existing *structs.HostVolume
	if vol.ID != "" {
		existing, err = snap.HostVolumeByID(nil, vol.Namespace, vol.ID, true)
		if err != nil {
			return nil, err // should never hit, bail out
		}
		if existing == nil {
			return nil, fmt.Errorf("cannot update volume %q: volume does not exist", vol.ID)
		}
		err = vol.ValidateUpdate(existing)
		if err != nil {
			return existing, fmt.Errorf("validating volume %q update failed: %v", vol.ID, err)
		}
	}
	return existing, nil

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Create the missing namespace first (`nomad namespace apply <name>`) or fix the name.
  2. Remove the explicit namespace field so it defaults to the request namespace.
  3. List namespaces with `nomad namespace list` and match the spec to an existing one.
  4. Check the spec for cross-cluster copy/paste of namespace names.

Example fix

// before
volume {
  name      = "web-data"
  namespace = "prod-eu"  // does not exist
}
// after
nomad namespace apply prod-eu
# or
volume {
  name = "web-data"
  # namespace omitted -> defaults to request namespace
}
Defensive patterns

Strategy: validation

Validate before calling

namespaces, _, _ := client.Namespaces().List(nil)
found := false
for _, ns := range namespaces {
    if ns.Name == vol.Namespace { found = true }
}
if !found { return fmt.Errorf("namespace %q does not exist", vol.Namespace) }

Type guard

func namespaceExists(name string, nsList []*api.Namespace) bool {
    for _, ns := range nsList { if ns.Name == name { return true } }
    return false
}

Try / catch

if strings.Contains(err.Error(), "no such namespace") {
    // create the namespace or fix the spec's namespace field
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/59f88e93737618d9. Report an issue: GitHub.