mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #772 from derekwaynecarr/stop_negative_values
Validate on replicas being non-negative
This commit is contained in:
commit
94e4aa70be
@ -318,6 +318,9 @@ func ValidateReplicationController(controller *ReplicationController) []error {
|
|||||||
if labels.Set(controller.DesiredState.ReplicaSelector).AsSelector().Empty() {
|
if labels.Set(controller.DesiredState.ReplicaSelector).AsSelector().Empty() {
|
||||||
errors = append(errors, makeInvalidError("ReplicationController.ReplicaSelector", controller.DesiredState.ReplicaSelector))
|
errors = append(errors, makeInvalidError("ReplicationController.ReplicaSelector", controller.DesiredState.ReplicaSelector))
|
||||||
}
|
}
|
||||||
|
if controller.DesiredState.Replicas < 0 {
|
||||||
|
errors = append(errors, makeInvalidError("ReplicationController.Replicas", controller.DesiredState.Replicas ))
|
||||||
|
}
|
||||||
errors = append(errors, ValidateManifest(&controller.DesiredState.PodTemplate.DesiredState.Manifest)...)
|
errors = append(errors, ValidateManifest(&controller.DesiredState.PodTemplate.DesiredState.Manifest)...)
|
||||||
return errors
|
return errors
|
||||||
}
|
}
|
||||||
|
@ -417,6 +417,13 @@ func TestValidateReplicationController(t *testing.T) {
|
|||||||
ReplicaSelector: validSelector,
|
ReplicaSelector: validSelector,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"negative_replicas": {
|
||||||
|
JSONBase: JSONBase{ID: "abc"},
|
||||||
|
DesiredState: ReplicationControllerState{
|
||||||
|
Replicas: -1,
|
||||||
|
ReplicaSelector: validSelector,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for k, v := range errorCases {
|
for k, v := range errorCases {
|
||||||
if errs := ValidateReplicationController(&v); len(errs) == 0 {
|
if errs := ValidateReplicationController(&v); len(errs) == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user