Пример #1
0
// Validates given deployment spec.
func ValidateDeploymentSpec(spec *extensions.DeploymentSpec) validation.ErrorList {
	allErrs := validation.ErrorList{}
	allErrs = append(allErrs, apivalidation.ValidateNonEmptySelector(spec.Selector, "selector")...)
	allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(spec.Replicas), "replicas")...)
	allErrs = append(allErrs, apivalidation.ValidatePodTemplateSpecForRC(&spec.Template, spec.Selector, spec.Replicas, "template")...)
	allErrs = append(allErrs, ValidateDeploymentStrategy(&spec.Strategy, "strategy")...)
	// empty string is a valid UniqueLabelKey
	if len(spec.UniqueLabelKey) > 0 {
		allErrs = append(allErrs, apivalidation.ValidateLabelName(spec.UniqueLabelKey, "uniqueLabel")...)
	}
	return allErrs
}
Пример #2
0
func ValidatePodSelectorRequirement(sr extensions.PodSelectorRequirement) validation.ErrorList {
	allErrs := validation.ErrorList{}
	switch sr.Operator {
	case extensions.PodSelectorOpIn, extensions.PodSelectorOpNotIn:
		if len(sr.Values) == 0 {
			allErrs = append(allErrs, validation.NewInvalidError("values", sr.Values, "must be non-empty when operator is In or NotIn"))
		}
	case extensions.PodSelectorOpExists, extensions.PodSelectorOpDoesNotExist:
		if len(sr.Values) > 0 {
			allErrs = append(allErrs, validation.NewInvalidError("values", sr.Values, "must be empty when operator is Exists or DoesNotExist"))
		}
	default:
		allErrs = append(allErrs, validation.NewInvalidError("operator", sr.Operator, "not a valid pod selector operator"))
	}
	allErrs = append(allErrs, apivalidation.ValidateLabelName(sr.Key, "key")...)
	return allErrs
}