{"record":{"id":"085b2f595d354b4b","repo":"kubernetes/kops","slug":"count-must-be-positive-or-0","errorCode":null,"errorMessage":"Count must be positive or 0","messagePattern":"Count must be positive or 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/linodetasks/instance.go","lineNumber":172,"sourceCode":"\t\t}\n\t\tif changes.Subnet != nil {\n\t\t\treturn fi.CannotChangeField(\"Subnet\")\n\t\t}\n\t\tif changes.RequirePublicInterface != nil {\n\t\t\treturn fi.CannotChangeField(\"RequirePublicInterface\")\n\t\t}\n\t} else {\n\t\tif expected.Name == nil {\n\t\t\treturn fi.RequiredField(\"Name\")\n\t\t}\n\t\tif expected.Region == \"\" {\n\t\t\treturn fi.RequiredField(\"Region\")\n\t\t}\n\t\tif expected.Type == \"\" {\n\t\t\treturn fi.RequiredField(\"Type\")\n\t\t}\n\t\tif expected.Count < 0 {\n\t\t\treturn fmt.Errorf(\"Count must be positive or 0\")\n\t\t}\n\t\tif expected.Subnet == nil {\n\t\t\treturn fi.RequiredField(\"Subnet\")\n\t\t}\n\t\tif expected.RequirePublicInterface == nil {\n\t\t\treturn fi.RequiredField(\"RequirePublicInterface\")\n\t\t}\n\t\tif expected.Image == \"\" {\n\t\t\treturn fi.RequiredField(\"Image\")\n\t\t}\n\t\tif expected.UserData == nil {\n\t\t\treturn fi.RequiredField(\"UserData\")\n\t\t}\n\t\tif len(expected.AuthorizedKeys) < 1 {\n\t\t\treturn fi.RequiredField(\"AuthorizedKeys\")\n\t\t}\n\t\tif len(expected.Tags) == 0 {\n\t\t\treturn fi.RequiredField(\"Tags\")","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/linodetasks/instance.go#L154-L190","documentation":"CheckChanges validates the desired Instance task during the apply diff phase. It throws this error when the declared instance group count is negative, since a group must have zero or more instances. kOps cannot compute a valid create/resize delta from a negative Count.","triggerScenarios":"An Instance task in the cluster spec has Count set to a negative integer (e.g. Count: -1), so expected.Count < 0 during CheckChanges.","commonSituations":"Template or variable interpolation producing a negative count (e.g. autoscaler math like desired - current going below zero), a hand-edited cluster.yaml with a typo, or a script computing replicas wrongly.","solutions":["Fix the Count field in the Instance task spec to be >= 0","Inspect whatever computed Count (templates, scripts) and clamp to 0 or above","Re-run kops update with the corrected spec"],"exampleFix":"// before\nCount: -2\n// after\nCount: 2","handlingStrategy":"validation","validationCode":"if instanceTask.Count < 0 { return fmt.Errorf(\"instance group %q: Count must be >= 0, got %d\", name, instanceTask.Count) }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never compute Count with subtraction that can go negative; clamp with math.Max(0, n)","Validate the cluster spec before apply (kops toolbox / spec lint)","Pin counts to non-negative constants where possible"],"tags":["validation","linode","config"],"backgroundTag":"negative-count-validation","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"}