{"record":{"id":"2490b71be41e6dbd","repo":"hashicorp/nomad","slug":"namespace-q-contains-at-least-one-variable-all-v","errorCode":null,"errorMessage":"namespace %q contains at least one variable. All variables in namespace must be deleted before it can be deleted","messagePattern":"namespace %q contains at least one variable\\. All variables in namespace must be deleted before it can be deleted","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store.go","lineNumber":7168,"sourceCode":"\t\tvIter, err := s.csiVolumesByNamespaceImpl(txn, nil, name, \"\")\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\trawVol := vIter.Next()\n\t\tif rawVol != nil {\n\t\t\tvol := rawVol.(*structs.CSIVolume)\n\t\t\treturn fmt.Errorf(\"namespace %q contains at least one CSI volume %q. \"+\n\t\t\t\t\"All CSI volumes in namespace must be deleted before it can be deleted\", name, vol.ID)\n\t\t}\n\n\t\tvarIter, err := s.getVariablesByNamespaceImpl(txn, nil, name)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif varIter.Next() != nil {\n\t\t\t// unlike job/volume, don't show the path here because the user may\n\t\t\t// not have List permissions on the vars in this namespace\n\t\t\treturn fmt.Errorf(\"namespace %q contains at least one variable. \"+\n\t\t\t\t\"All variables in namespace must be deleted before it can be deleted\", name)\n\t\t}\n\n\t\t// Delete the namespace\n\t\tif err := txn.Delete(TableNamespaces, existing); err != nil {\n\t\t\treturn fmt.Errorf(\"namespace deletion failed: %v\", err)\n\t\t}\n\t}\n\n\tif err := txn.Insert(\"index\", &IndexEntry{TableNamespaces, index}); err != nil {\n\t\treturn fmt.Errorf(\"index update failed: %v\", err)\n\t}\n\n\treturn txn.Commit()\n}\n\nfunc (s *StateStore) DeleteScalingPolicies(index uint64, ids []string) error {\n\ttxn := s.db.WriteTxn(index)","sourceCodeStart":7150,"sourceCodeEnd":7186,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L7150-L7186","documentation":"DeleteNamespace refuses deletion when any structured variables (Nomad's secret/config storage) exist under the namespace. Unlike jobs/volumes, the offending variable path is intentionally omitted from the message because the caller may lack List permission on variables in that namespace.","triggerScenarios":"DELETE /v1/namespace/<name> while `nomad var` entries exist at paths under that namespace.","commonSituations":"Variables created by job deployments or CI pipelines left behind after workload removal; operators unable to discover which vars block deletion because paths are hidden.","solutions":["List variables with sufficient ACL permissions (`nomad var list -namespace <ns>`) and delete them (`nomad var delete -namespace <ns> <path>`), then retry.","If access is denied, ask an operator with the variables:list/write ACL capability to clear the namespace's variables.","Recreate the namespace only after `nomad var list -namespace <ns>` returns empty."],"exampleFix":"# before\nnomad namespace delete app-team   # fails, reason hidden\n# after\nnomad var list -namespace app-team\nnomad var delete -namespace app-team secret/app/config\nnomad namespace delete app-team","handlingStrategy":"validation","validationCode":"vars, _, _ := client.Variables().List(&nomad.QueryOptions{Namespace: ns})\nif len(vars) > 0 {\n    return fmt.Errorf(\"%d variables remain in %s; delete them first\", len(vars), ns)\n}","typeGuard":null,"tryCatchPattern":"if strings.Contains(err.Error(), \"contains at least one variable\") {\n    // list vars with adequate ACLs, delete them, then retry\n}","preventionTips":["Ensure the deleting principal has variables:list ACL capability so it can discover blockers.","Delete namespace-scoped variable paths during teardown before removing the namespace."],"tags":["nomad","state-store","namespace","variables"],"backgroundTag":"namespace-not-empty","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"}