hashicorp/nomad · warning
namespace not found
Error message
namespace not found
What it means
NamespaceDelete requires the namespace to exist and rejects deleting the built-in default namespace. This error is returned when no namespace with the given name is found in the state store, so the delete is a no-op failure.
Source
Thrown at nomad/state/state_store.go:7123
}
// Reconcile changed quotas
return s.quotaReconcile(index, txn, ns.Quota, oldQuota)
}
// DeleteNamespaces is used to remove a set of namespaces
func (s *StateStore) DeleteNamespaces(index uint64, names []string) error {
txn := s.db.WriteTxn(index)
defer txn.Abort()
for _, name := range names {
// Lookup the namespace
existing, err := txn.First(TableNamespaces, "id", name)
if err != nil {
return fmt.Errorf("namespace lookup failed: %v", err)
}
if existing == nil {
return fmt.Errorf("namespace not found")
}
ns := existing.(*structs.Namespace)
if ns.Name == structs.DefaultNamespace {
return fmt.Errorf("default namespace can not be deleted")
}
// Ensure that the namespace doesn't have any non-terminal jobs
iter, err := s.jobsByNamespaceImpl(nil, name, txn, SortDefault)
if err != nil {
return err
}
for {
raw := iter.Next()
if raw == nil {
break
}View on GitHub (pinned to 482b49bf1a)
Solutions
- Verify the namespace exists with `nomad namespace list` and check spelling
- Delete only if present in your script (ignore not-found for idempotency)
- Confirm you are targeting the intended region/agent context
- Use the default namespace check to avoid attempting to delete `default` (that raises a different error)
Example fix
// before nomad namespace delete prod // fails if absent // after nomad namespace list | grep -q '^prod ' && nomad namespace delete prod || true
Defensive patterns
Strategy: try-catch
Validate before calling
_, _, err := client.Namespaces().Info(name, nil)
if err != nil { return nil // already absent; delete is a no-op } Type guard
func namespaceExists(c *api.Client, name string) bool { _, _, err := c.Namespaces().Info(name, nil); return err == nil } Try / catch
_, err := client.Namespaces().Delete(name, nil)
if err != nil && strings.Contains(err.Error(), "namespace not found") {
return nil // idempotent delete
} else if err != nil {
return err
} Prevention
- Make delete scripts idempotent by treating not-found as success
- Confirm namespace names via `nomad namespace list` before deleting
- Set the correct region/context so you delete in the intended cluster
When it happens
Trigger: `nomad namespace delete <name>` or Namespace.Delete API with a name that was never created or was already deleted.
Common situations: Typo in the namespace name; idempotent cleanup scripts running delete twice; wrong region/cluster context; namespace removed by another operator first.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- job %q is in nonexistent namespace %q
- default namespace can not be deleted
- namespace %q contains at least one non-terminal job %q. All
- namespace %q contains at least one CSI volume %q. All CSI vo
- namespace %q contains at least one variable. All variables i
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/df722873456ffe81.
Report an issue: GitHub.