{"record":{"id":"0751cbb7a76df823","repo":"hashicorp/nomad","slug":"default-namespace-can-not-be-deleted","errorCode":null,"errorMessage":"default namespace can not be deleted","messagePattern":"default namespace can not be deleted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store.go","lineNumber":7128,"sourceCode":"\n// DeleteNamespaces is used to remove a set of namespaces\nfunc (s *StateStore) DeleteNamespaces(index uint64, names []string) error {\n\ttxn := s.db.WriteTxn(index)\n\tdefer txn.Abort()\n\n\tfor _, name := range names {\n\t\t// Lookup the namespace\n\t\texisting, err := txn.First(TableNamespaces, \"id\", name)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"namespace lookup failed: %v\", err)\n\t\t}\n\t\tif existing == nil {\n\t\t\treturn fmt.Errorf(\"namespace not found\")\n\t\t}\n\n\t\tns := existing.(*structs.Namespace)\n\t\tif ns.Name == structs.DefaultNamespace {\n\t\t\treturn fmt.Errorf(\"default namespace can not be deleted\")\n\t\t}\n\n\t\t// Ensure that the namespace doesn't have any non-terminal jobs\n\t\titer, err := s.jobsByNamespaceImpl(nil, name, txn, SortDefault)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tfor {\n\t\t\traw := iter.Next()\n\t\t\tif raw == nil {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tjob := raw.(*structs.Job)\n\n\t\t\tif job.Status != structs.JobStatusDead {\n\t\t\t\treturn fmt.Errorf(\"namespace %q contains at least one non-terminal job %q. \"+\n\t\t\t\t\t\"All jobs must be terminal in namespace before it can be deleted\", name, job.ID)","sourceCodeStart":7110,"sourceCodeEnd":7146,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L7110-L7146","documentation":"Nomad's state store rejects deletion of the built-in \"default\" namespace in DeleteNamespace. The default namespace is a system-reserved namespace that jobs and other objects fall back to, so it must always exist. Any DeleteNamespace RPC targeting it fails immediately inside the state-store transaction.","triggerScenarios":"Calling the Namespace Delete API (DELETE /v1/namespace/default), `nomad namespace delete default`, or a `namespace_delete` job/agent action naming the default namespace.","commonSituations":"Cleanup scripts that iterate all namespaces and delete each one; Terraform/automation that manages namespaces and tries to converge by removing the default; operators mistaking default for an unused namespace.","solutions":["Exclude structs.DefaultNamespace (\"default\") from any automated namespace deletion list.","Delete only namespaces you explicitly created.","If the goal is to remove workload from default, move jobs to a new namespace instead of deleting default."],"exampleFix":"// before\nfor _, ns := range namespaces {\n    client.Namespaces().Delete(ns.Name, nil)\n}\n// after\nfor _, ns := range namespaces {\n    if ns.Name != \"default\" {\n        client.Namespaces().Delete(ns.Name, nil)\n    }\n}","handlingStrategy":"validation","validationCode":"if ns == \"default\" {\n    return fmt.Errorf(\"refusing to delete reserved namespace %q\", ns)\n}\nreturn client.Namespaces().Delete(ns, nil)","typeGuard":"func isReservedNamespace(name string) bool { return name == \"default\" }","tryCatchPattern":null,"preventionTips":["Hardcode/exclude \"default\" in any namespace cleanup automation.","Manage namespaces via IaC with an explicit keep-list."],"tags":["nomad","state-store","namespace"],"backgroundTag":"reserved-resource-delete-rejected","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"}