kubernetes/kops · error

acceleratorCount must be positive or 0

Error message

acceleratorCount must be positive or 0

What it means

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.

Source

Thrown at upup/pkg/fi/cloudup/gcetasks/accelerator_config.go:41

)

// AcceleratorConfig defines an accelerator config
type AcceleratorConfig struct {
	AcceleratorCount int64  `json:"acceleratorCount,omitempty"`
	AcceleratorType  string `json:"acceleratorType,omitempty"`
}

var (
	_ fi.CloudupHasDependencies = &AcceleratorConfig{}
)

func (a *AcceleratorConfig) GetDependencies(tasks map[string]fi.CloudupTask) []fi.CloudupTask {
	return nil
}

func (_ *AcceleratorConfig) ShouldCreate(a, e, changes *AcceleratorConfig) (bool, error) {
	if e.AcceleratorCount < 0 {
		return false, fmt.Errorf("acceleratorCount must be positive or 0")
	}
	if e.AcceleratorType == "" {
		return false, fmt.Errorf("acceleratorType must not be empty")
	}
	return true, nil
}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Set acceleratorCount to a positive integer (number of GPUs to attach) or 0 (no accelerators) in the cluster/instance-group spec.
  2. Search the cluster manifest and any template/rendering code for negative arithmetic on acceleratorCount and fix the source value.
  3. If you intentionally want no GPUs, remove the accelerator fields entirely instead of using a negative count.
  4. Run `kops replace -f cluster.yaml` / `kops update cluster` with the corrected spec and re-apply.

Example fix

// before (cluster.yaml)
accelerators:
- acceleratorCount: -1
  acceleratorType: nvidia-tesla-t4
// after
accelerators:
- acceleratorCount: 1
  acceleratorType: nvidia-tesla-t4
Defensive patterns

Strategy: validation

Validate before calling

if spec.AcceleratorCount != nil && *spec.AcceleratorCount < 0 {
    return fmt.Errorf("acceleratorCount must be positive or 0, got %d", *spec.AcceleratorCount)
}

Type guard

func validAcceleratorCount(n int) bool { return n >= 0 }

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/769c822ace821c96. Report an issue: GitHub.