Require namespace on controller, pod, service objects

This commit is contained in:
derekwaynecarr
2014-09-29 17:17:42 -04:00
parent 1b2c62a8ca
commit e4ec49ee6b
10 changed files with 142 additions and 3 deletions

View File

@@ -313,6 +313,7 @@ func ValidatePod(pod *api.Pod) errs.ErrorList {
if len(pod.ID) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("id", pod.ID))
}
allErrs = append(allErrs, validateNotEmptyDNSSubdomain(pod.Namespace, "pod.Namespace")...)
allErrs = append(allErrs, ValidatePodState(&pod.DesiredState).Prefix("desiredState")...)
return allErrs
}
@@ -325,6 +326,7 @@ func ValidateService(service *api.Service) errs.ErrorList {
} else if !util.IsDNS952Label(service.ID) {
allErrs = append(allErrs, errs.NewFieldInvalid("id", service.ID))
}
allErrs = append(allErrs, validateNotEmptyDNSSubdomain(service.Namespace, "service.Namespace")...)
if !util.IsValidPortNum(service.Port) {
allErrs = append(allErrs, errs.NewFieldInvalid("Service.Port", service.Port))
}
@@ -345,6 +347,7 @@ func ValidateReplicationController(controller *api.ReplicationController) errs.E
if len(controller.ID) == 0 {
allErrs = append(allErrs, errs.NewFieldRequired("id", controller.ID))
}
allErrs = append(allErrs, validateNotEmptyDNSSubdomain(controller.Namespace, "controller.Namespace")...)
allErrs = append(allErrs, ValidateReplicationControllerState(&controller.DesiredState).Prefix("desiredState")...)
return allErrs
}
@@ -366,3 +369,14 @@ func ValidateReplicationControllerState(state *api.ReplicationControllerState) e
allErrs = append(allErrs, ValidateManifest(&state.PodTemplate.DesiredState.Manifest).Prefix("podTemplate.desiredState.manifest")...)
return allErrs
}
// validateNotEmptyDNSSubdomain validates the provided value is not empty and is a dns subdomain.
func validateNotEmptyDNSSubdomain(value string, label string) errs.ErrorList {
allErrs := errs.ErrorList{}
if value == "" {
allErrs = append(allErrs, errs.NewFieldInvalid(label, value))
} else if !util.IsDNSSubdomain(value) {
allErrs = append(allErrs, errs.NewFieldInvalid(label, value))
}
return allErrs
}