{"record":{"id":"769c822ace821c96","repo":"kubernetes/kops","slug":"acceleratorcount-must-be-positive-or-0","errorCode":null,"errorMessage":"acceleratorCount must be positive or 0","messagePattern":"acceleratorCount must be positive or 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/gcetasks/accelerator_config.go","lineNumber":41,"sourceCode":")\n\n// AcceleratorConfig defines an accelerator config\ntype AcceleratorConfig struct {\n\tAcceleratorCount int64  `json:\"acceleratorCount,omitempty\"`\n\tAcceleratorType  string `json:\"acceleratorType,omitempty\"`\n}\n\nvar (\n\t_ fi.CloudupHasDependencies = &AcceleratorConfig{}\n)\n\nfunc (a *AcceleratorConfig) GetDependencies(tasks map[string]fi.CloudupTask) []fi.CloudupTask {\n\treturn nil\n}\n\nfunc (_ *AcceleratorConfig) ShouldCreate(a, e, changes *AcceleratorConfig) (bool, error) {\n\tif e.AcceleratorCount < 0 {\n\t\treturn false, fmt.Errorf(\"acceleratorCount must be positive or 0\")\n\t}\n\tif e.AcceleratorType == \"\" {\n\t\treturn false, fmt.Errorf(\"acceleratorType must not be empty\")\n\t}\n\treturn true, nil\n}\n","sourceCodeStart":23,"sourceCodeEnd":48,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/gcetasks/accelerator_config.go#L23-L48","documentation":"This error is thrown by AcceleratorConfig.ShouldCreate in the GCE task layer before kOps attempts to create a GCE accelerator attachment. The field e.AcceleratorCount is negative, which is never valid for a GPU/accelerator resource on GCE. ShouldCreate acts as a pre-flight validation gate: returning an error aborts creation of the resource rather than issuing an invalid Compute API call.","triggerScenarios":"fi.CloudupTask.ShouldCreate is invoked during the GCE apply phase with changes containing e.AcceleratorCount < 0, i.e. a cluster spec or instance template sets acceleratorCount to a negative number (typo such as -1, or arithmetic on a default producing a negative value).","commonSituations":"Cluster spec mistakes: users writing acceleratorCount: -1 accidentally, tooling subtracting counts from limits and going below zero, or generated templates with unvalidated arithmetic on accelerator counts.","solutions":["Set acceleratorCount to a positive integer (number of GPUs to attach) or 0 (no accelerators) in the cluster/instance-group spec.","Search the cluster manifest and any template/rendering code for negative arithmetic on acceleratorCount and fix the source value.","If you intentionally want no GPUs, remove the accelerator fields entirely instead of using a negative count.","Run `kops replace -f cluster.yaml` / `kops update cluster` with the corrected spec and re-apply."],"exampleFix":"// before (cluster.yaml)\naccelerators:\n- acceleratorCount: -1\n  acceleratorType: nvidia-tesla-t4\n// after\naccelerators:\n- acceleratorCount: 1\n  acceleratorType: nvidia-tesla-t4","handlingStrategy":"validation","validationCode":"if spec.AcceleratorCount != nil && *spec.AcceleratorCount < 0 {\n    return fmt.Errorf(\"acceleratorCount must be positive or 0, got %d\", *spec.AcceleratorCount)\n}","typeGuard":"func validAcceleratorCount(n int) bool { return n >= 0 }","tryCatchPattern":null,"preventionTips":["Validate acceleratorCount >= 0 in cluster spec validation tooling/CI before running kops update.","Prefer omitting the accelerators block entirely over using 0/negative counts when no GPUs are needed.","Guard any arithmetic that derives accelerator counts from limits against going below zero."],"tags":["gce","validation","gpu","config"],"backgroundTag":"invalid-accelerator-count","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}