// validateTemplateBody checks the body of a template. func validateTemplateBody(template *api.Template) (allErrs field.ErrorList) { for i := range template.Parameters { allErrs = append(allErrs, ValidateParameter(&template.Parameters[i], field.NewPath("parameters").Index(i))...) } allErrs = append(allErrs, unversionedvalidation.ValidateLabels(template.ObjectLabels, field.NewPath("labels"))...) return }
func ValidateProjectLimitBySelector(limit api.ProjectLimitBySelector, path *field.Path) field.ErrorList { allErrs := field.ErrorList{} allErrs = append(allErrs, unversionedvalidation.ValidateLabels(limit.Selector, path.Child("selector"))...) if limit.MaxProjects != nil && *limit.MaxProjects < 0 { allErrs = append(allErrs, field.Invalid(path.Child("maxProjects"), *limit.MaxProjects, "cannot be a negative number")) } return allErrs }
func validateDeploymentStrategy(strategy *deployapi.DeploymentStrategy, pod *kapi.PodSpec, fldPath *field.Path) field.ErrorList { errs := field.ErrorList{} if len(strategy.Type) == 0 { errs = append(errs, field.Required(fldPath.Child("type"), "")) } if strategy.CustomParams != nil { errs = append(errs, validateCustomParams(strategy.CustomParams, fldPath.Child("customParams"))...) } switch strategy.Type { case deployapi.DeploymentStrategyTypeRecreate: if strategy.RecreateParams != nil { errs = append(errs, validateRecreateParams(strategy.RecreateParams, pod, fldPath.Child("recreateParams"))...) } case deployapi.DeploymentStrategyTypeRolling: if strategy.RollingParams == nil { errs = append(errs, field.Required(fldPath.Child("rollingParams"), "")) } else { errs = append(errs, validateRollingParams(strategy.RollingParams, pod, fldPath.Child("rollingParams"))...) } case deployapi.DeploymentStrategyTypeCustom: if strategy.CustomParams == nil { errs = append(errs, field.Required(fldPath.Child("customParams"), "")) } if strategy.RollingParams != nil { errs = append(errs, validateRollingParams(strategy.RollingParams, pod, fldPath.Child("rollingParams"))...) } if strategy.RecreateParams != nil { errs = append(errs, validateRecreateParams(strategy.RecreateParams, pod, fldPath.Child("recreateParams"))...) } case "": errs = append(errs, field.Required(fldPath.Child("type"), "strategy type is required")) default: errs = append(errs, field.Invalid(fldPath.Child("type"), strategy.Type, "unsupported strategy type, use \"Custom\" instead and specify your own strategy")) } if strategy.Labels != nil { errs = append(errs, unversionedvalidation.ValidateLabels(strategy.Labels, fldPath.Child("labels"))...) } if strategy.Annotations != nil { errs = append(errs, validation.ValidateAnnotations(strategy.Annotations, fldPath.Child("annotations"))...) } errs = append(errs, validation.ValidateResourceRequirements(&strategy.Resources, fldPath.Child("resources"))...) return errs }
// Validates the given template and ensures that it is in accordance with the desired selector. func ValidatePodTemplateSpecForStatefulSet(template *api.PodTemplateSpec, selector labels.Selector, fldPath *field.Path) field.ErrorList { allErrs := field.ErrorList{} if template == nil { allErrs = append(allErrs, field.Required(fldPath, "")) } else { if !selector.Empty() { // Verify that the StatefulSet selector matches the labels in template. labels := labels.Set(template.Labels) if !selector.Matches(labels) { allErrs = append(allErrs, field.Invalid(fldPath.Child("metadata", "labels"), template.Labels, "`selector` does not match template `labels`")) } } // TODO: Add validation for PodSpec, currently this will check volumes, which we know will // fail. We should really check that the union of the given volumes and volumeClaims match // volume mounts in the containers. // allErrs = append(allErrs, apivalidation.ValidatePodTemplateSpec(template, fldPath)...) allErrs = append(allErrs, unversionedvalidation.ValidateLabels(template.Labels, fldPath.Child("labels"))...) allErrs = append(allErrs, apivalidation.ValidateAnnotations(template.Annotations, fldPath.Child("annotations"))...) allErrs = append(allErrs, apivalidation.ValidatePodSpecificAnnotations(template.Annotations, &template.Spec, fldPath.Child("annotations"))...) } return allErrs }
func validateDeploymentStrategy(strategy *deployapi.DeploymentStrategy, pod *kapi.PodSpec, fldPath *field.Path) field.ErrorList { errs := field.ErrorList{} if len(strategy.Type) == 0 { errs = append(errs, field.Required(fldPath.Child("type"), "")) } if strategy.CustomParams != nil { errs = append(errs, validateCustomParams(strategy.CustomParams, fldPath.Child("customParams"))...) } switch strategy.Type { case deployapi.DeploymentStrategyTypeRecreate: if strategy.RecreateParams != nil { errs = append(errs, validateRecreateParams(strategy.RecreateParams, pod, fldPath.Child("recreateParams"))...) } case deployapi.DeploymentStrategyTypeRolling: if strategy.RollingParams == nil { errs = append(errs, field.Required(fldPath.Child("rollingParams"), "")) } else { errs = append(errs, validateRollingParams(strategy.RollingParams, pod, fldPath.Child("rollingParams"))...) } case deployapi.DeploymentStrategyTypeCustom: if strategy.CustomParams == nil { errs = append(errs, field.Required(fldPath.Child("customParams"), "")) } if strategy.RollingParams != nil { errs = append(errs, validateRollingParams(strategy.RollingParams, pod, fldPath.Child("rollingParams"))...) } if strategy.RecreateParams != nil { errs = append(errs, validateRecreateParams(strategy.RecreateParams, pod, fldPath.Child("recreateParams"))...) } case "": errs = append(errs, field.Required(fldPath.Child("type"), "strategy type is required")) default: errs = append(errs, field.Invalid(fldPath.Child("type"), strategy.Type, "unsupported strategy type, use \"Custom\" instead and specify your own strategy")) } if strategy.Labels != nil { errs = append(errs, unversionedvalidation.ValidateLabels(strategy.Labels, fldPath.Child("labels"))...) } if strategy.Annotations != nil { errs = append(errs, validation.ValidateAnnotations(strategy.Annotations, fldPath.Child("annotations"))...) } errs = append(errs, validation.ValidateResourceRequirements(&strategy.Resources, fldPath.Child("resources"))...) if strategy.ActiveDeadlineSeconds != nil { errs = append(errs, kapivalidation.ValidateNonnegativeField(*strategy.ActiveDeadlineSeconds, fldPath.Child("activeDeadlineSeconds"))...) var timeoutSeconds *int64 if strategy.RollingParams != nil { timeoutSeconds = strategy.RollingParams.TimeoutSeconds } else if strategy.RecreateParams != nil { timeoutSeconds = strategy.RecreateParams.TimeoutSeconds } if timeoutSeconds != nil && *strategy.ActiveDeadlineSeconds <= *timeoutSeconds { errs = append(errs, field.Invalid(fldPath.Child("activeDeadlineSeconds"), *strategy.ActiveDeadlineSeconds, "activeDeadlineSeconds must be greater than timeoutSeconds")) } } return errs }