Add some lifecycle validation.

This commit is contained in:
Brendan Burns
2014-09-12 16:04:10 -07:00
parent 9b6042ea2c
commit 6efafb141f
2 changed files with 82 additions and 0 deletions

View File

@@ -180,6 +180,45 @@ func checkHostPortConflicts(containers []api.Container) errs.ErrorList {
return AccumulateUniquePorts(containers, allPorts, func(p *api.Port) int { return p.HostPort })
}
func validateExecAction(exec *api.ExecAction) errs.ErrorList {
allErrors := errs.ErrorList{}
if len(exec.Command) == 0 {
allErrors = append(allErrors, errs.NewFieldRequired("command", exec.Command))
}
return allErrors
}
func validateHTTPGetAction(http *api.HTTPGetAction) errs.ErrorList {
allErrors := errs.ErrorList{}
if len(http.Path) == 0 {
allErrors = append(allErrors, errs.NewFieldRequired("path", http.Path))
}
return allErrors
}
func validateHandler(handler *api.Handler) errs.ErrorList {
allErrors := errs.ErrorList{}
if handler.Exec != nil {
allErrors = append(allErrors, validateExecAction(handler.Exec).Prefix("exec")...)
} else if handler.HTTPGet != nil {
allErrors = append(allErrors, validateHTTPGetAction(handler.HTTPGet).Prefix("httpGet")...)
} else {
allErrors = append(allErrors, errs.NewFieldInvalid("", handler))
}
return allErrors
}
func validateLifecycle(lifecycle *api.Lifecycle) errs.ErrorList {
allErrs := errs.ErrorList{}
if lifecycle.PostStart != nil {
allErrs = append(allErrs, validateHandler(lifecycle.PostStart).Prefix("postStart")...)
}
if lifecycle.PreStop != nil {
allErrs = append(allErrs, validateHandler(lifecycle.PreStop).Prefix("preStop")...)
}
return allErrs
}
func validateContainers(containers []api.Container, volumes util.StringSet) errs.ErrorList {
allErrs := errs.ErrorList{}
@@ -199,6 +238,9 @@ func validateContainers(containers []api.Container, volumes util.StringSet) errs
if len(ctr.Image) == 0 {
cErrs = append(cErrs, errs.NewFieldRequired("image", ctr.Image))
}
if ctr.Lifecycle != nil {
cErrs = append(cErrs, validateLifecycle(ctr.Lifecycle).Prefix("lifecycle")...)
}
cErrs = append(cErrs, validatePorts(ctr.Ports).Prefix("ports")...)
cErrs = append(cErrs, validateEnv(ctr.Env).Prefix("env")...)
cErrs = append(cErrs, validateVolumeMounts(ctr.VolumeMounts, volumes).Prefix("volumeMounts")...)