{"record":{"id":"a7975dfbcb5ac850","repo":"hashicorp/nomad","slug":"limitbytes-cannot-be-less-than-requiredbytes","errorCode":null,"errorMessage":"LimitBytes cannot be less than RequiredBytes","messagePattern":"LimitBytes cannot be less than RequiredBytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/csi/plugin.go","lineNumber":506,"sourceCode":"\n\treturn req\n}\n\nfunc (r *ControllerCreateVolumeRequest) Validate() error {\n\tif r.Name == \"\" {\n\t\treturn errors.New(\"missing Name\")\n\t}\n\tif r.VolumeCapabilities == nil {\n\t\treturn errors.New(\"missing VolumeCapabilities\")\n\t}\n\tif r.CapacityRange != nil {\n\t\tif r.CapacityRange.LimitBytes == 0 && r.CapacityRange.RequiredBytes == 0 {\n\t\t\treturn errors.New(\n\t\t\t\t\"one of LimitBytes or RequiredBytes must be set if CapacityRange is set\")\n\t\t}\n\t\tif r.CapacityRange.LimitBytes > 0 &&\n\t\t\tr.CapacityRange.LimitBytes < r.CapacityRange.RequiredBytes {\n\t\t\treturn errors.New(\"LimitBytes cannot be less than RequiredBytes\")\n\t\t}\n\t}\n\tif r.ContentSource != nil {\n\t\tif r.ContentSource.CloneID != \"\" && r.ContentSource.SnapshotID != \"\" {\n\t\t\treturn errors.New(\n\t\t\t\t\"one of SnapshotID or CloneID must be set if ContentSource is set\")\n\t\t}\n\t}\n\treturn nil\n}\n\n// VolumeContentSource is snapshot or volume that the plugin will use to\n// create the new volume. At most one of these fields can be set, but nil (and\n// not an empty struct) is expected by CSI plugins if neither field is set.\ntype VolumeContentSource struct {\n\tSnapshotID string\n\tCloneID    string\n}","sourceCodeStart":488,"sourceCodeEnd":524,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/plugins/csi/plugin.go#L488-L524","documentation":"This error is returned by VolumeOptions.Validate in the CSI plugin client when a volume request's CapacityRange sets a positive LimitBytes that is smaller than RequiredBytes. The CSI spec requires that the limit (maximum capacity the CO can accept) be greater than or equal to the required capacity (minimum the SP must provide), so a contradictory range is rejected before any gRPC call is made. It is a fail-fast guard to avoid a guaranteed rejection by the storage provider.","triggerScenarios":"Calling NodePublishVolume (via a volume registration whose validate volume options path invokes Validate) with CapacityRange set to {RequiredBytes: 1073741824, LimitBytes: 536870912}. Note that if both RequiredBytes and LimitBytes are 0 the earlier 'one of LimitBytes or RequiredBytes must be set' error fires instead; this error only fires when LimitBytes > 0 and LimitBytes < RequiredBytes.","commonSituations":"Hand-editing a Nomad CSI volume spec and swapping the two numbers; templating tools that fill RequiredBytes from an environment value larger than a hard-coded LimitBytes; unit confusion (GB vs GiB) causing limit < required; copying an example spec and scaling required capacity upward without updating the limit.","solutions":["Swap the values so LimitBytes >= RequiredBytes in the volume's CapacityRange.","If no maximum is intended, omit LimitBytes (set it to 0) and only specify RequiredBytes.","Recheck units (GB vs GiB, MB vs MiB) and recompute both byte values consistently.","Re-register or re-submit the volume/job spec with the corrected capacity range."],"exampleFix":"// before\nCapacityRange: &CSICapacityRange{\n  RequiredBytes: 10 * 1024 * 1024 * 1024,\n  LimitBytes:    5 * 1024 * 1024 * 1024,\n}\n// after\nCapacityRange: &CSICapacityRange{\n  RequiredBytes: 5 * 1024 * 1024 * 1024,\n  LimitBytes:    10 * 1024 * 1024 * 1024,\n}","handlingStrategy":"validation","validationCode":"func validateCapacityRange(required, limit int64) error {\n\tif required == 0 && limit == 0 {\n\t\treturn fmt.Errorf(\"one of LimitBytes or RequiredBytes must be set\")\n\t}\n\tif limit > 0 && limit < required {\n\t\treturn fmt.Errorf(\"LimitBytes (%d) must be >= RequiredBytes (%d)\", limit, required)\n\t}\n\treturn nil\n}","typeGuard":"func validCapacity(c *CSICapacityRange) bool {\n\treturn c == nil || (c.LimitBytes == 0 || c.LimitBytes >= c.RequiredBytes)\n}","tryCatchPattern":null,"preventionTips":["Define capacity as (minimum, maximum) pairs in one config source to keep them consistent.","Use explicit byte constants (GiB) to avoid GB/GiB confusion.","Omit LimitBytes entirely when no cap is needed.","Run a dry-run validation of volume specs in CI before deployment."],"tags":["csi","validation","capacity-range","storage"],"backgroundTag":"capacity-range-invalid","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"}