Skip to content

Commit

Permalink
Merge pull request kubernetes#1333 from pmorie/validation
Browse files Browse the repository at this point in the history
Expose validation method for ReplicationControllerState
  • Loading branch information
dchen1107 committed Sep 16, 2014
2 parents c47dca5 + f94198c commit 45f5f8d
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,17 +341,24 @@ func ValidateReplicationController(controller *api.ReplicationController) errs.E
if len(controller.ID) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("id", controller.ID))
}
if labels.Set(controller.DesiredState.ReplicaSelector).AsSelector().Empty() {
allErrs = append(allErrs, errs.NewFieldRequired("desiredState.replicaSelector", controller.DesiredState.ReplicaSelector))
allErrs = append(allErrs, ValidateReplicationControllerState(&controller.DesiredState).Prefix("desiredState")...)
return allErrs
}

// ValidateReplicationControllerState tests if required fields in the replication controller state are set.
func ValidateReplicationControllerState(state *api.ReplicationControllerState) errs.ErrorList {
allErrs := errs.ErrorList{}
if labels.Set(state.ReplicaSelector).AsSelector().Empty() {
allErrs = append(allErrs, errs.NewFieldRequired("replicaSelector", state.ReplicaSelector))
}
selector := labels.Set(controller.DesiredState.ReplicaSelector).AsSelector()
labels := labels.Set(controller.DesiredState.PodTemplate.Labels)
selector := labels.Set(state.ReplicaSelector).AsSelector()
labels := labels.Set(state.PodTemplate.Labels)
if !selector.Matches(labels) {
allErrs = append(allErrs, errs.NewFieldInvalid("desiredState.podTemplate.labels", controller.DesiredState.PodTemplate))
allErrs = append(allErrs, errs.NewFieldInvalid("podTemplate.labels", state.PodTemplate))
}
if controller.DesiredState.Replicas < 0 {
allErrs = append(allErrs, errs.NewFieldInvalid("desiredState.replicas", controller.DesiredState.Replicas))
if state.Replicas < 0 {
allErrs = append(allErrs, errs.NewFieldInvalid("replicas", state.Replicas))
}
allErrs = append(allErrs, ValidateManifest(&controller.DesiredState.PodTemplate.DesiredState.Manifest).Prefix("desiredState.podTemplate.desiredState.manifest")...)
allErrs = append(allErrs, ValidateManifest(&state.PodTemplate.DesiredState.Manifest).Prefix("podTemplate.desiredState.manifest")...)
return allErrs
}

0 comments on commit 45f5f8d

Please sign in to comment.