fix: reject negative process counts when scaling
A process count below zero was accepted and stored verbatim, leaving the scheduler to reject the value long after the command reported success. Counts below zero are now rejected, as are process tuples that omit a process type, across `ps:scale`, the `ps-set-scale` trigger and the `formation` key of `app.json`. A negative count persisted by an earlier version stays readable so it can be corrected with `ps:scale`.
This commit is contained in:
8 files changed
+292
-3
No files matched your search
+22
-1
@@ -196,7 +196,7 @@ func parseProcessTuples(processTuples []string) (FormationSlice, error) {
|
||||
processType := strings.TrimSpace(s[0])
|
||||
quantity, err := strconv.Atoi(strings.TrimSpace(s[1]))
|
||||
if err != nil {
|
||||
return formations, fmt.Errorf("Invalid count for process type %s", s[0])
|
||||
return formations, fmt.Errorf("Invalid count for process type %s", processType)
|
||||
}
|
||||
|
||||
if foundFormations[processType] {
|
||||
@@ -351,6 +351,10 @@ func scaleSet(input scaleSetInput) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := validateFormations(formations); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if input.clearExisting {
|
||||
formations = appendClearedFormations(formations, existingFormations)
|
||||
}
|
||||
@@ -484,3 +488,20 @@ func updateScale(appName string, clearExisting bool, formationUpdates FormationS
|
||||
|
||||
return common.PropertyListWrite("ps", appName, "scale", values)
|
||||
}
|
||||
|
||||
// validateFormations returns an error when a user specified formation cannot be scaled to.
|
||||
// Formations read back from the scale property are deliberately not validated so that a value
|
||||
// persisted by an older dokku version remains visible and repairable via ps:scale.
|
||||
func validateFormations(formations FormationSlice) error {
|
||||
for _, formation := range formations {
|
||||
if formation.ProcessType == "" {
|
||||
return fmt.Errorf("Missing process type for count %d", formation.Quantity)
|
||||
}
|
||||
|
||||
if formation.Quantity < 0 {
|
||||
return fmt.Errorf("Invalid count for process type %s: value must be zero or greater", formation.ProcessType)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user