s/ValidationErrorList/ErrorList/

pull/6/head
Tim Hockin 2015-11-03 13:38:40 -08:00
parent d64d1fbb3d
commit 48b49a5cae
39 changed files with 379 additions and 379 deletions

View File

@ -159,7 +159,7 @@ func NewConflict(kind, name string, err error) error {
} }
// NewInvalid returns an error indicating the item is invalid and cannot be processed. // NewInvalid returns an error indicating the item is invalid and cannot be processed.
func NewInvalid(kind, name string, errs validation.ValidationErrorList) error { func NewInvalid(kind, name string, errs validation.ErrorList) error {
causes := make([]unversioned.StatusCause, 0, len(errs)) causes := make([]unversioned.StatusCause, 0, len(errs))
for i := range errs { for i := range errs {
if err, ok := errs[i].(*validation.Error); ok { if err, ok := errs[i].(*validation.Error); ok {

View File

@ -150,7 +150,7 @@ func TestNewInvalid(t *testing.T) {
for i, testCase := range testCases { for i, testCase := range testCases {
vErr, expected := testCase.Err, testCase.Details vErr, expected := testCase.Err, testCase.Details
expected.Causes[0].Message = vErr.ErrorBody() expected.Causes[0].Message = vErr.ErrorBody()
err := NewInvalid("kind", "name", validation.ValidationErrorList{vErr}) err := NewInvalid("kind", "name", validation.ErrorList{vErr})
status := err.(*StatusError).ErrStatus status := err.(*StatusError).ErrStatus
if status.Code != 422 || status.Reason != unversioned.StatusReasonInvalid { if status.Code != 422 || status.Reason != unversioned.StatusReasonInvalid {
t.Errorf("%d: unexpected status: %#v", i, status) t.Errorf("%d: unexpected status: %#v", i, status)

View File

@ -42,7 +42,7 @@ type RESTCreateStrategy interface {
PrepareForCreate(obj runtime.Object) PrepareForCreate(obj runtime.Object)
// Validate is invoked after default fields in the object have been filled in before // Validate is invoked after default fields in the object have been filled in before
// the object is persisted. This method should not mutate the object. // the object is persisted. This method should not mutate the object.
Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList
// Canonicalize is invoked after validation has succeeded but before the // Canonicalize is invoked after validation has succeeded but before the
// object has been persisted. This method may mutate the object. // object has been persisted. This method may mutate the object.
Canonicalize(obj runtime.Object) Canonicalize(obj runtime.Object)

View File

@ -42,7 +42,7 @@ type RESTUpdateStrategy interface {
// ValidateUpdate is invoked after default fields in the object have been // ValidateUpdate is invoked after default fields in the object have been
// filled in before the object is persisted. This method should not mutate // filled in before the object is persisted. This method should not mutate
// the object. // the object.
ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList
// Canonicalize is invoked after validation has succeeded but before the // Canonicalize is invoked after validation has succeeded but before the
// object has been persisted. This method may mutate the object. // object has been persisted. This method may mutate the object.
Canonicalize(obj runtime.Object) Canonicalize(obj runtime.Object)
@ -53,8 +53,8 @@ type RESTUpdateStrategy interface {
} }
// TODO: add other common fields that require global validation. // TODO: add other common fields that require global validation.
func validateCommonFields(obj, old runtime.Object) utilvalidation.ValidationErrorList { func validateCommonFields(obj, old runtime.Object) utilvalidation.ErrorList {
allErrs := utilvalidation.ValidationErrorList{} allErrs := utilvalidation.ErrorList{}
objectMeta, err := api.ObjectMetaFor(obj) objectMeta, err := api.ObjectMetaFor(obj)
if err != nil { if err != nil {
return append(allErrs, errors.NewInternalError(err)) return append(allErrs, errors.NewInternalError(err))

View File

@ -42,7 +42,7 @@ func TestCompatibility(
t *testing.T, t *testing.T,
version string, version string,
input []byte, input []byte,
validator func(obj runtime.Object) validation.ValidationErrorList, validator func(obj runtime.Object) validation.ErrorList,
expectedKeys map[string]string, expectedKeys map[string]string,
absentKeys []string, absentKeys []string,
) { ) {

View File

@ -217,7 +217,7 @@ func TestCompatibility_v1_PodSecurityContext(t *testing.T) {
}, },
} }
validator := func(obj runtime.Object) utilvalidation.ValidationErrorList { validator := func(obj runtime.Object) utilvalidation.ErrorList {
return validation.ValidatePodSpec(&(obj.(*api.Pod).Spec)) return validation.ValidatePodSpec(&(obj.(*api.Pod).Spec))
} }

View File

@ -22,8 +22,8 @@ import (
) )
// ValidateEvent makes sure that the event makes sense. // ValidateEvent makes sure that the event makes sense.
func ValidateEvent(event *api.Event) validation.ValidationErrorList { func ValidateEvent(event *api.Event) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
// TODO: There is no namespace required for node. // TODO: There is no namespace required for node.
if event.InvolvedObject.Kind != "Node" && if event.InvolvedObject.Kind != "Node" &&
event.Namespace != event.InvolvedObject.Namespace { event.Namespace != event.InvolvedObject.Namespace {

View File

@ -70,8 +70,8 @@ func NewSwaggerSchemaFromBytes(data []byte) (Schema, error) {
// validateList unpack a list and validate every item in the list. // validateList unpack a list and validate every item in the list.
// It return nil if every item is ok. // It return nil if every item is ok.
// Otherwise it return an error list contain errors of every item. // Otherwise it return an error list contain errors of every item.
func (s *SwaggerSchema) validateList(obj map[string]interface{}) validation.ValidationErrorList { func (s *SwaggerSchema) validateList(obj map[string]interface{}) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
items, exists := obj["items"] items, exists := obj["items"]
if !exists { if !exists {
return append(allErrs, fmt.Errorf("no items field in %#v", obj)) return append(allErrs, fmt.Errorf("no items field in %#v", obj))
@ -160,8 +160,8 @@ func (s *SwaggerSchema) ValidateBytes(data []byte) error {
return utilerrors.NewAggregate(allErrs) return utilerrors.NewAggregate(allErrs)
} }
func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName string) validation.ValidationErrorList { func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
models := s.api.Models models := s.api.Models
model, ok := models.At(typeName) model, ok := models.At(typeName)
if !ok { if !ok {
@ -215,7 +215,7 @@ func (s *SwaggerSchema) ValidateObject(obj interface{}, fieldName, typeName stri
// This matches type name in the swagger spec, such as "v1.Binding". // This matches type name in the swagger spec, such as "v1.Binding".
var versionRegexp = regexp.MustCompile(`^v.+\..*`) var versionRegexp = regexp.MustCompile(`^v.+\..*`)
func (s *SwaggerSchema) validateField(value interface{}, fieldName, fieldType string, fieldDetails *swagger.ModelProperty) validation.ValidationErrorList { func (s *SwaggerSchema) validateField(value interface{}, fieldName, fieldType string, fieldDetails *swagger.ModelProperty) validation.ErrorList {
// TODO: caesarxuchao: because we have multiple group/versions and objects // TODO: caesarxuchao: because we have multiple group/versions and objects
// may reference objects in other group, the commented out way of checking // may reference objects in other group, the commented out way of checking
// if a filedType is a type defined by us is outdated. We use a hacky way // if a filedType is a type defined by us is outdated. We use a hacky way
@ -229,7 +229,7 @@ func (s *SwaggerSchema) validateField(value interface{}, fieldName, fieldType st
// if strings.HasPrefix(fieldType, apiVersion) { // if strings.HasPrefix(fieldType, apiVersion) {
return s.ValidateObject(value, fieldName, fieldType) return s.ValidateObject(value, fieldName, fieldType)
} }
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
switch fieldType { switch fieldType {
case "string": case "string":
// Be loose about what we accept for 'string' since we use IntOrString in a couple of places // Be loose about what we accept for 'string' since we use IntOrString in a couple of places

View File

@ -61,8 +61,8 @@ var PortNameErrorMsg string = fmt.Sprintf(`must be an IANA_SVC_NAME (at most 15
const totalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB const totalAnnotationSizeLimitB int = 256 * (1 << 10) // 256 kB
func ValidateLabelName(labelName, fieldName string) validation.ValidationErrorList { func ValidateLabelName(labelName, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if !validation.IsQualifiedName(labelName) { if !validation.IsQualifiedName(labelName) {
allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, labelName, qualifiedNameErrorMsg)) allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, labelName, qualifiedNameErrorMsg))
} }
@ -70,8 +70,8 @@ func ValidateLabelName(labelName, fieldName string) validation.ValidationErrorLi
} }
// ValidateLabels validates that a set of labels are correctly defined. // ValidateLabels validates that a set of labels are correctly defined.
func ValidateLabels(labels map[string]string, field string) validation.ValidationErrorList { func ValidateLabels(labels map[string]string, field string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for k, v := range labels { for k, v := range labels {
allErrs = append(allErrs, ValidateLabelName(k, field)...) allErrs = append(allErrs, ValidateLabelName(k, field)...)
if !validation.IsValidLabelValue(v) { if !validation.IsValidLabelValue(v) {
@ -82,8 +82,8 @@ func ValidateLabels(labels map[string]string, field string) validation.Validatio
} }
// ValidateAnnotations validates that a set of annotations are correctly defined. // ValidateAnnotations validates that a set of annotations are correctly defined.
func ValidateAnnotations(annotations map[string]string, field string) validation.ValidationErrorList { func ValidateAnnotations(annotations map[string]string, field string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
var totalSize int64 var totalSize int64
for k, v := range annotations { for k, v := range annotations {
if !validation.IsQualifiedName(strings.ToLower(k)) { if !validation.IsQualifiedName(strings.ToLower(k)) {
@ -217,8 +217,8 @@ func NameIsDNS952Label(name string, prefix bool) (bool, string) {
} }
// Validates that given value is not negative. // Validates that given value is not negative.
func ValidatePositiveField(value int64, fieldName string) validation.ValidationErrorList { func ValidatePositiveField(value int64, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if value < 0 { if value < 0 {
allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, value, isNegativeErrorMsg)) allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, value, isNegativeErrorMsg))
} }
@ -226,16 +226,16 @@ func ValidatePositiveField(value int64, fieldName string) validation.ValidationE
} }
// Validates that a Quantity is not negative // Validates that a Quantity is not negative
func ValidatePositiveQuantity(value resource.Quantity, fieldName string) validation.ValidationErrorList { func ValidatePositiveQuantity(value resource.Quantity, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if value.Cmp(resource.Quantity{}) < 0 { if value.Cmp(resource.Quantity{}) < 0 {
allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, value.String(), isNegativeErrorMsg)) allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, value.String(), isNegativeErrorMsg))
} }
return allErrs return allErrs
} }
func ValidateImmutableField(new, old interface{}, fieldName string) validation.ValidationErrorList { func ValidateImmutableField(new, old interface{}, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if !api.Semantic.DeepEqual(old, new) { if !api.Semantic.DeepEqual(old, new) {
allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, new, fieldImmutableErrorMsg)) allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, new, fieldImmutableErrorMsg))
} }
@ -246,8 +246,8 @@ func ValidateImmutableField(new, old interface{}, fieldName string) validation.V
// been performed. // been performed.
// It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before. // It doesn't return an error for rootscoped resources with namespace, because namespace should already be cleared before.
// TODO: Remove calls to this method scattered in validations of specific resources, e.g., ValidatePodUpdate. // TODO: Remove calls to this method scattered in validations of specific resources, e.g., ValidatePodUpdate.
func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn ValidateNameFunc) validation.ValidationErrorList { func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn ValidateNameFunc) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(meta.GenerateName) != 0 { if len(meta.GenerateName) != 0 {
if ok, qualifier := nameFn(meta.GenerateName, true); !ok { if ok, qualifier := nameFn(meta.GenerateName, true); !ok {
@ -285,8 +285,8 @@ func ValidateObjectMeta(meta *api.ObjectMeta, requiresNamespace bool, nameFn Val
} }
// ValidateObjectMetaUpdate validates an object's metadata when updated // ValidateObjectMetaUpdate validates an object's metadata when updated
func ValidateObjectMetaUpdate(new, old *api.ObjectMeta) validation.ValidationErrorList { func ValidateObjectMetaUpdate(new, old *api.ObjectMeta) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if !RepairMalformedUpdates && new.UID != old.UID { if !RepairMalformedUpdates && new.UID != old.UID {
allErrs = append(allErrs, validation.NewFieldInvalid("uid", new.UID, "field is immutable")) allErrs = append(allErrs, validation.NewFieldInvalid("uid", new.UID, "field is immutable"))
@ -334,8 +334,8 @@ func ValidateObjectMetaUpdate(new, old *api.ObjectMeta) validation.ValidationErr
return allErrs return allErrs
} }
func validateVolumes(volumes []api.Volume) (sets.String, validation.ValidationErrorList) { func validateVolumes(volumes []api.Volume) (sets.String, validation.ErrorList) {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allNames := sets.String{} allNames := sets.String{}
for i, vol := range volumes { for i, vol := range volumes {
@ -356,9 +356,9 @@ func validateVolumes(volumes []api.Volume) (sets.String, validation.ValidationEr
return allNames, allErrs return allNames, allErrs
} }
func validateSource(source *api.VolumeSource) validation.ValidationErrorList { func validateSource(source *api.VolumeSource) validation.ErrorList {
numVolumes := 0 numVolumes := 0
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if source.HostPath != nil { if source.HostPath != nil {
numVolumes++ numVolumes++
allErrs = append(allErrs, validateHostPathVolumeSource(source.HostPath).Prefix("hostPath")...) allErrs = append(allErrs, validateHostPathVolumeSource(source.HostPath).Prefix("hostPath")...)
@ -430,24 +430,24 @@ func validateSource(source *api.VolumeSource) validation.ValidationErrorList {
return allErrs return allErrs
} }
func validateHostPathVolumeSource(hostPath *api.HostPathVolumeSource) validation.ValidationErrorList { func validateHostPathVolumeSource(hostPath *api.HostPathVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if hostPath.Path == "" { if hostPath.Path == "" {
allErrs = append(allErrs, validation.NewFieldRequired("path")) allErrs = append(allErrs, validation.NewFieldRequired("path"))
} }
return allErrs return allErrs
} }
func validateGitRepoVolumeSource(gitRepo *api.GitRepoVolumeSource) validation.ValidationErrorList { func validateGitRepoVolumeSource(gitRepo *api.GitRepoVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if gitRepo.Repository == "" { if gitRepo.Repository == "" {
allErrs = append(allErrs, validation.NewFieldRequired("repository")) allErrs = append(allErrs, validation.NewFieldRequired("repository"))
} }
return allErrs return allErrs
} }
func validateISCSIVolumeSource(iscsi *api.ISCSIVolumeSource) validation.ValidationErrorList { func validateISCSIVolumeSource(iscsi *api.ISCSIVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if iscsi.TargetPortal == "" { if iscsi.TargetPortal == "" {
allErrs = append(allErrs, validation.NewFieldRequired("targetPortal")) allErrs = append(allErrs, validation.NewFieldRequired("targetPortal"))
} }
@ -463,8 +463,8 @@ func validateISCSIVolumeSource(iscsi *api.ISCSIVolumeSource) validation.Validati
return allErrs return allErrs
} }
func validateFCVolumeSource(fc *api.FCVolumeSource) validation.ValidationErrorList { func validateFCVolumeSource(fc *api.FCVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(fc.TargetWWNs) < 1 { if len(fc.TargetWWNs) < 1 {
allErrs = append(allErrs, validation.NewFieldRequired("targetWWNs")) allErrs = append(allErrs, validation.NewFieldRequired("targetWWNs"))
} }
@ -482,8 +482,8 @@ func validateFCVolumeSource(fc *api.FCVolumeSource) validation.ValidationErrorLi
return allErrs return allErrs
} }
func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource) validation.ValidationErrorList { func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if PD.PDName == "" { if PD.PDName == "" {
allErrs = append(allErrs, validation.NewFieldRequired("pdName")) allErrs = append(allErrs, validation.NewFieldRequired("pdName"))
} }
@ -496,8 +496,8 @@ func validateGCEPersistentDiskVolumeSource(PD *api.GCEPersistentDiskVolumeSource
return allErrs return allErrs
} }
func validateAWSElasticBlockStoreVolumeSource(PD *api.AWSElasticBlockStoreVolumeSource) validation.ValidationErrorList { func validateAWSElasticBlockStoreVolumeSource(PD *api.AWSElasticBlockStoreVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if PD.VolumeID == "" { if PD.VolumeID == "" {
allErrs = append(allErrs, validation.NewFieldRequired("volumeID")) allErrs = append(allErrs, validation.NewFieldRequired("volumeID"))
} }
@ -510,24 +510,24 @@ func validateAWSElasticBlockStoreVolumeSource(PD *api.AWSElasticBlockStoreVolume
return allErrs return allErrs
} }
func validateSecretVolumeSource(secretSource *api.SecretVolumeSource) validation.ValidationErrorList { func validateSecretVolumeSource(secretSource *api.SecretVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if secretSource.SecretName == "" { if secretSource.SecretName == "" {
allErrs = append(allErrs, validation.NewFieldRequired("secretName")) allErrs = append(allErrs, validation.NewFieldRequired("secretName"))
} }
return allErrs return allErrs
} }
func validatePersistentClaimVolumeSource(claim *api.PersistentVolumeClaimVolumeSource) validation.ValidationErrorList { func validatePersistentClaimVolumeSource(claim *api.PersistentVolumeClaimVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if claim.ClaimName == "" { if claim.ClaimName == "" {
allErrs = append(allErrs, validation.NewFieldRequired("claimName")) allErrs = append(allErrs, validation.NewFieldRequired("claimName"))
} }
return allErrs return allErrs
} }
func validateNFS(nfs *api.NFSVolumeSource) validation.ValidationErrorList { func validateNFS(nfs *api.NFSVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if nfs.Server == "" { if nfs.Server == "" {
allErrs = append(allErrs, validation.NewFieldRequired("server")) allErrs = append(allErrs, validation.NewFieldRequired("server"))
} }
@ -540,8 +540,8 @@ func validateNFS(nfs *api.NFSVolumeSource) validation.ValidationErrorList {
return allErrs return allErrs
} }
func validateGlusterfs(glusterfs *api.GlusterfsVolumeSource) validation.ValidationErrorList { func validateGlusterfs(glusterfs *api.GlusterfsVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if glusterfs.EndpointsName == "" { if glusterfs.EndpointsName == "" {
allErrs = append(allErrs, validation.NewFieldRequired("endpoints")) allErrs = append(allErrs, validation.NewFieldRequired("endpoints"))
} }
@ -551,8 +551,8 @@ func validateGlusterfs(glusterfs *api.GlusterfsVolumeSource) validation.Validati
return allErrs return allErrs
} }
func validateFlocker(flocker *api.FlockerVolumeSource) validation.ValidationErrorList { func validateFlocker(flocker *api.FlockerVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if flocker.DatasetName == "" { if flocker.DatasetName == "" {
allErrs = append(allErrs, validation.NewFieldRequired("datasetName")) allErrs = append(allErrs, validation.NewFieldRequired("datasetName"))
} }
@ -564,8 +564,8 @@ func validateFlocker(flocker *api.FlockerVolumeSource) validation.ValidationErro
var validDownwardAPIFieldPathExpressions = sets.NewString("metadata.name", "metadata.namespace", "metadata.labels", "metadata.annotations") var validDownwardAPIFieldPathExpressions = sets.NewString("metadata.name", "metadata.namespace", "metadata.labels", "metadata.annotations")
func validateDownwardAPIVolumeSource(downwardAPIVolume *api.DownwardAPIVolumeSource) validation.ValidationErrorList { func validateDownwardAPIVolumeSource(downwardAPIVolume *api.DownwardAPIVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for _, downwardAPIVolumeFile := range downwardAPIVolume.Items { for _, downwardAPIVolumeFile := range downwardAPIVolume.Items {
if len(downwardAPIVolumeFile.Path) == 0 { if len(downwardAPIVolumeFile.Path) == 0 {
allErrs = append(allErrs, validation.NewFieldRequired("path")) allErrs = append(allErrs, validation.NewFieldRequired("path"))
@ -587,8 +587,8 @@ func validateDownwardAPIVolumeSource(downwardAPIVolume *api.DownwardAPIVolumeSou
return allErrs return allErrs
} }
func validateRBD(rbd *api.RBDVolumeSource) validation.ValidationErrorList { func validateRBD(rbd *api.RBDVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(rbd.CephMonitors) == 0 { if len(rbd.CephMonitors) == 0 {
allErrs = append(allErrs, validation.NewFieldRequired("monitors")) allErrs = append(allErrs, validation.NewFieldRequired("monitors"))
} }
@ -601,8 +601,8 @@ func validateRBD(rbd *api.RBDVolumeSource) validation.ValidationErrorList {
return allErrs return allErrs
} }
func validateCinderVolumeSource(cd *api.CinderVolumeSource) validation.ValidationErrorList { func validateCinderVolumeSource(cd *api.CinderVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if cd.VolumeID == "" { if cd.VolumeID == "" {
allErrs = append(allErrs, validation.NewFieldRequired("volumeID")) allErrs = append(allErrs, validation.NewFieldRequired("volumeID"))
} }
@ -612,8 +612,8 @@ func validateCinderVolumeSource(cd *api.CinderVolumeSource) validation.Validatio
return allErrs return allErrs
} }
func validateCephFS(cephfs *api.CephFSVolumeSource) validation.ValidationErrorList { func validateCephFS(cephfs *api.CephFSVolumeSource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(cephfs.Monitors) == 0 { if len(cephfs.Monitors) == 0 {
allErrs = append(allErrs, validation.NewFieldRequired("monitors")) allErrs = append(allErrs, validation.NewFieldRequired("monitors"))
} }
@ -624,8 +624,8 @@ func ValidatePersistentVolumeName(name string, prefix bool) (bool, string) {
return NameIsDNSSubdomain(name, prefix) return NameIsDNSSubdomain(name, prefix)
} }
func ValidatePersistentVolume(pv *api.PersistentVolume) validation.ValidationErrorList { func ValidatePersistentVolume(pv *api.PersistentVolume) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&pv.ObjectMeta, false, ValidatePersistentVolumeName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&pv.ObjectMeta, false, ValidatePersistentVolumeName).Prefix("metadata")...)
if len(pv.Spec.AccessModes) == 0 { if len(pv.Spec.AccessModes) == 0 {
@ -703,8 +703,8 @@ func ValidatePersistentVolume(pv *api.PersistentVolume) validation.ValidationErr
// ValidatePersistentVolumeUpdate tests to see if the update is legal for an end user to make. // ValidatePersistentVolumeUpdate tests to see if the update is legal for an end user to make.
// newPv is updated with fields that cannot be changed. // newPv is updated with fields that cannot be changed.
func ValidatePersistentVolumeUpdate(newPv, oldPv *api.PersistentVolume) validation.ValidationErrorList { func ValidatePersistentVolumeUpdate(newPv, oldPv *api.PersistentVolume) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = ValidatePersistentVolume(newPv) allErrs = ValidatePersistentVolume(newPv)
newPv.Status = oldPv.Status newPv.Status = oldPv.Status
return allErrs return allErrs
@ -712,8 +712,8 @@ func ValidatePersistentVolumeUpdate(newPv, oldPv *api.PersistentVolume) validati
// ValidatePersistentVolumeStatusUpdate tests to see if the status update is legal for an end user to make. // ValidatePersistentVolumeStatusUpdate tests to see if the status update is legal for an end user to make.
// newPv is updated with fields that cannot be changed. // newPv is updated with fields that cannot be changed.
func ValidatePersistentVolumeStatusUpdate(newPv, oldPv *api.PersistentVolume) validation.ValidationErrorList { func ValidatePersistentVolumeStatusUpdate(newPv, oldPv *api.PersistentVolume) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPv.ObjectMeta, &oldPv.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPv.ObjectMeta, &oldPv.ObjectMeta).Prefix("metadata")...)
if newPv.ResourceVersion == "" { if newPv.ResourceVersion == "" {
allErrs = append(allErrs, validation.NewFieldRequired("resourceVersion")) allErrs = append(allErrs, validation.NewFieldRequired("resourceVersion"))
@ -722,7 +722,7 @@ func ValidatePersistentVolumeStatusUpdate(newPv, oldPv *api.PersistentVolume) va
return allErrs return allErrs
} }
func ValidatePersistentVolumeClaim(pvc *api.PersistentVolumeClaim) validation.ValidationErrorList { func ValidatePersistentVolumeClaim(pvc *api.PersistentVolumeClaim) validation.ErrorList {
allErrs := ValidateObjectMeta(&pvc.ObjectMeta, true, ValidatePersistentVolumeName) allErrs := ValidateObjectMeta(&pvc.ObjectMeta, true, ValidatePersistentVolumeName)
if len(pvc.Spec.AccessModes) == 0 { if len(pvc.Spec.AccessModes) == 0 {
allErrs = append(allErrs, validation.NewFieldInvalid("persistentVolumeClaim.Spec.AccessModes", pvc.Spec.AccessModes, "at least 1 PersistentVolumeAccessMode is required")) allErrs = append(allErrs, validation.NewFieldInvalid("persistentVolumeClaim.Spec.AccessModes", pvc.Spec.AccessModes, "at least 1 PersistentVolumeAccessMode is required"))
@ -738,15 +738,15 @@ func ValidatePersistentVolumeClaim(pvc *api.PersistentVolumeClaim) validation.Va
return allErrs return allErrs
} }
func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) validation.ValidationErrorList { func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = ValidatePersistentVolumeClaim(newPvc) allErrs = ValidatePersistentVolumeClaim(newPvc)
newPvc.Status = oldPvc.Status newPvc.Status = oldPvc.Status
return allErrs return allErrs
} }
func ValidatePersistentVolumeClaimStatusUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) validation.ValidationErrorList { func ValidatePersistentVolumeClaimStatusUpdate(newPvc, oldPvc *api.PersistentVolumeClaim) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPvc.ObjectMeta, &oldPvc.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPvc.ObjectMeta, &oldPvc.ObjectMeta).Prefix("metadata")...)
if newPvc.ResourceVersion == "" { if newPvc.ResourceVersion == "" {
allErrs = append(allErrs, validation.NewFieldRequired("resourceVersion")) allErrs = append(allErrs, validation.NewFieldRequired("resourceVersion"))
@ -763,12 +763,12 @@ func ValidatePersistentVolumeClaimStatusUpdate(newPvc, oldPvc *api.PersistentVol
var supportedPortProtocols = sets.NewString(string(api.ProtocolTCP), string(api.ProtocolUDP)) var supportedPortProtocols = sets.NewString(string(api.ProtocolTCP), string(api.ProtocolUDP))
func validatePorts(ports []api.ContainerPort) validation.ValidationErrorList { func validatePorts(ports []api.ContainerPort) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allNames := sets.String{} allNames := sets.String{}
for i, port := range ports { for i, port := range ports {
pErrs := validation.ValidationErrorList{} pErrs := validation.ErrorList{}
if len(port.Name) > 0 { if len(port.Name) > 0 {
if !validation.IsValidPortName(port.Name) { if !validation.IsValidPortName(port.Name) {
pErrs = append(pErrs, validation.NewFieldInvalid("name", port.Name, PortNameErrorMsg)) pErrs = append(pErrs, validation.NewFieldInvalid("name", port.Name, PortNameErrorMsg))
@ -796,11 +796,11 @@ func validatePorts(ports []api.ContainerPort) validation.ValidationErrorList {
return allErrs return allErrs
} }
func validateEnv(vars []api.EnvVar) validation.ValidationErrorList { func validateEnv(vars []api.EnvVar) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for i, ev := range vars { for i, ev := range vars {
vErrs := validation.ValidationErrorList{} vErrs := validation.ErrorList{}
if len(ev.Name) == 0 { if len(ev.Name) == 0 {
vErrs = append(vErrs, validation.NewFieldRequired("name")) vErrs = append(vErrs, validation.NewFieldRequired("name"))
} else if !validation.IsCIdentifier(ev.Name) { } else if !validation.IsCIdentifier(ev.Name) {
@ -814,8 +814,8 @@ func validateEnv(vars []api.EnvVar) validation.ValidationErrorList {
var validFieldPathExpressionsEnv = sets.NewString("metadata.name", "metadata.namespace", "status.podIP") var validFieldPathExpressionsEnv = sets.NewString("metadata.name", "metadata.namespace", "status.podIP")
func validateEnvVarValueFrom(ev api.EnvVar) validation.ValidationErrorList { func validateEnvVarValueFrom(ev api.EnvVar) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if ev.ValueFrom == nil { if ev.ValueFrom == nil {
return allErrs return allErrs
@ -836,8 +836,8 @@ func validateEnvVarValueFrom(ev api.EnvVar) validation.ValidationErrorList {
return allErrs return allErrs
} }
func validateObjectFieldSelector(fs *api.ObjectFieldSelector, expressions *sets.String) validation.ValidationErrorList { func validateObjectFieldSelector(fs *api.ObjectFieldSelector, expressions *sets.String) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if fs.APIVersion == "" { if fs.APIVersion == "" {
allErrs = append(allErrs, validation.NewFieldRequired("apiVersion")) allErrs = append(allErrs, validation.NewFieldRequired("apiVersion"))
@ -855,11 +855,11 @@ func validateObjectFieldSelector(fs *api.ObjectFieldSelector, expressions *sets.
return allErrs return allErrs
} }
func validateVolumeMounts(mounts []api.VolumeMount, volumes sets.String) validation.ValidationErrorList { func validateVolumeMounts(mounts []api.VolumeMount, volumes sets.String) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for i, mnt := range mounts { for i, mnt := range mounts {
mErrs := validation.ValidationErrorList{} mErrs := validation.ErrorList{}
if len(mnt.Name) == 0 { if len(mnt.Name) == 0 {
mErrs = append(mErrs, validation.NewFieldRequired("name")) mErrs = append(mErrs, validation.NewFieldRequired("name"))
} else if !volumes.Has(mnt.Name) { } else if !volumes.Has(mnt.Name) {
@ -873,8 +873,8 @@ func validateVolumeMounts(mounts []api.VolumeMount, volumes sets.String) validat
return allErrs return allErrs
} }
func validateProbe(probe *api.Probe) validation.ValidationErrorList { func validateProbe(probe *api.Probe) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if probe == nil { if probe == nil {
return allErrs return allErrs
@ -890,11 +890,11 @@ func validateProbe(probe *api.Probe) validation.ValidationErrorList {
// AccumulateUniqueHostPorts extracts each HostPort of each Container, // AccumulateUniqueHostPorts extracts each HostPort of each Container,
// accumulating the results and returning an error if any ports conflict. // accumulating the results and returning an error if any ports conflict.
func AccumulateUniqueHostPorts(containers []api.Container, accumulator *sets.String) validation.ValidationErrorList { func AccumulateUniqueHostPorts(containers []api.Container, accumulator *sets.String) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for ci, ctr := range containers { for ci, ctr := range containers {
cErrs := validation.ValidationErrorList{} cErrs := validation.ErrorList{}
for pi := range ctr.Ports { for pi := range ctr.Ports {
port := ctr.Ports[pi].HostPort port := ctr.Ports[pi].HostPort
if port == 0 { if port == 0 {
@ -914,21 +914,21 @@ func AccumulateUniqueHostPorts(containers []api.Container, accumulator *sets.Str
// checkHostPortConflicts checks for colliding Port.HostPort values across // checkHostPortConflicts checks for colliding Port.HostPort values across
// a slice of containers. // a slice of containers.
func checkHostPortConflicts(containers []api.Container) validation.ValidationErrorList { func checkHostPortConflicts(containers []api.Container) validation.ErrorList {
allPorts := sets.String{} allPorts := sets.String{}
return AccumulateUniqueHostPorts(containers, &allPorts) return AccumulateUniqueHostPorts(containers, &allPorts)
} }
func validateExecAction(exec *api.ExecAction) validation.ValidationErrorList { func validateExecAction(exec *api.ExecAction) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
if len(exec.Command) == 0 { if len(exec.Command) == 0 {
allErrors = append(allErrors, validation.NewFieldRequired("command")) allErrors = append(allErrors, validation.NewFieldRequired("command"))
} }
return allErrors return allErrors
} }
func validateHTTPGetAction(http *api.HTTPGetAction) validation.ValidationErrorList { func validateHTTPGetAction(http *api.HTTPGetAction) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
if len(http.Path) == 0 { if len(http.Path) == 0 {
allErrors = append(allErrors, validation.NewFieldRequired("path")) allErrors = append(allErrors, validation.NewFieldRequired("path"))
} }
@ -944,8 +944,8 @@ func validateHTTPGetAction(http *api.HTTPGetAction) validation.ValidationErrorLi
return allErrors return allErrors
} }
func validateTCPSocketAction(tcp *api.TCPSocketAction) validation.ValidationErrorList { func validateTCPSocketAction(tcp *api.TCPSocketAction) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
if tcp.Port.Type == intstr.Int && !validation.IsValidPortNum(tcp.Port.IntVal) { if tcp.Port.Type == intstr.Int && !validation.IsValidPortNum(tcp.Port.IntVal) {
allErrors = append(allErrors, validation.NewFieldInvalid("port", tcp.Port, PortRangeErrorMsg)) allErrors = append(allErrors, validation.NewFieldInvalid("port", tcp.Port, PortRangeErrorMsg))
} else if tcp.Port.Type == intstr.String && !validation.IsValidPortName(tcp.Port.StrVal) { } else if tcp.Port.Type == intstr.String && !validation.IsValidPortName(tcp.Port.StrVal) {
@ -954,9 +954,9 @@ func validateTCPSocketAction(tcp *api.TCPSocketAction) validation.ValidationErro
return allErrors return allErrors
} }
func validateHandler(handler *api.Handler) validation.ValidationErrorList { func validateHandler(handler *api.Handler) validation.ErrorList {
numHandlers := 0 numHandlers := 0
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
if handler.Exec != nil { if handler.Exec != nil {
numHandlers++ numHandlers++
allErrors = append(allErrors, validateExecAction(handler.Exec).Prefix("exec")...) allErrors = append(allErrors, validateExecAction(handler.Exec).Prefix("exec")...)
@ -975,8 +975,8 @@ func validateHandler(handler *api.Handler) validation.ValidationErrorList {
return allErrors return allErrors
} }
func validateLifecycle(lifecycle *api.Lifecycle) validation.ValidationErrorList { func validateLifecycle(lifecycle *api.Lifecycle) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if lifecycle.PostStart != nil { if lifecycle.PostStart != nil {
allErrs = append(allErrs, validateHandler(lifecycle.PostStart).Prefix("postStart")...) allErrs = append(allErrs, validateHandler(lifecycle.PostStart).Prefix("postStart")...)
} }
@ -986,8 +986,8 @@ func validateLifecycle(lifecycle *api.Lifecycle) validation.ValidationErrorList
return allErrs return allErrs
} }
func validatePullPolicy(ctr *api.Container) validation.ValidationErrorList { func validatePullPolicy(ctr *api.Container) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
switch ctr.ImagePullPolicy { switch ctr.ImagePullPolicy {
case api.PullAlways, api.PullIfNotPresent, api.PullNever: case api.PullAlways, api.PullIfNotPresent, api.PullNever:
@ -1002,8 +1002,8 @@ func validatePullPolicy(ctr *api.Container) validation.ValidationErrorList {
return allErrors return allErrors
} }
func validateContainers(containers []api.Container, volumes sets.String) validation.ValidationErrorList { func validateContainers(containers []api.Container, volumes sets.String) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(containers) == 0 { if len(containers) == 0 {
return append(allErrs, validation.NewFieldRequired("")) return append(allErrs, validation.NewFieldRequired(""))
@ -1011,7 +1011,7 @@ func validateContainers(containers []api.Container, volumes sets.String) validat
allNames := sets.String{} allNames := sets.String{}
for i, ctr := range containers { for i, ctr := range containers {
cErrs := validation.ValidationErrorList{} cErrs := validation.ErrorList{}
if len(ctr.Name) == 0 { if len(ctr.Name) == 0 {
cErrs = append(cErrs, validation.NewFieldRequired("name")) cErrs = append(cErrs, validation.NewFieldRequired("name"))
} else if !validation.IsDNS1123Label(ctr.Name) { } else if !validation.IsDNS1123Label(ctr.Name) {
@ -1048,8 +1048,8 @@ func validateContainers(containers []api.Container, volumes sets.String) validat
return allErrs return allErrs
} }
func validateRestartPolicy(restartPolicy *api.RestartPolicy) validation.ValidationErrorList { func validateRestartPolicy(restartPolicy *api.RestartPolicy) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
switch *restartPolicy { switch *restartPolicy {
case api.RestartPolicyAlways, api.RestartPolicyOnFailure, api.RestartPolicyNever: case api.RestartPolicyAlways, api.RestartPolicyOnFailure, api.RestartPolicyNever:
break break
@ -1063,8 +1063,8 @@ func validateRestartPolicy(restartPolicy *api.RestartPolicy) validation.Validati
return allErrors return allErrors
} }
func validateDNSPolicy(dnsPolicy *api.DNSPolicy) validation.ValidationErrorList { func validateDNSPolicy(dnsPolicy *api.DNSPolicy) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
switch *dnsPolicy { switch *dnsPolicy {
case api.DNSClusterFirst, api.DNSDefault: case api.DNSClusterFirst, api.DNSDefault:
break break
@ -1077,8 +1077,8 @@ func validateDNSPolicy(dnsPolicy *api.DNSPolicy) validation.ValidationErrorList
return allErrors return allErrors
} }
func validateHostNetwork(hostNetwork bool, containers []api.Container) validation.ValidationErrorList { func validateHostNetwork(hostNetwork bool, containers []api.Container) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
if hostNetwork { if hostNetwork {
for _, container := range containers { for _, container := range containers {
for _, port := range container.Ports { for _, port := range container.Ports {
@ -1093,8 +1093,8 @@ func validateHostNetwork(hostNetwork bool, containers []api.Container) validatio
// validateImagePullSecrets checks to make sure the pull secrets are well formed. Right now, we only expect name to be set (it's the only field). If this ever changes // validateImagePullSecrets checks to make sure the pull secrets are well formed. Right now, we only expect name to be set (it's the only field). If this ever changes
// and someone decides to set those fields, we'd like to know. // and someone decides to set those fields, we'd like to know.
func validateImagePullSecrets(imagePullSecrets []api.LocalObjectReference) validation.ValidationErrorList { func validateImagePullSecrets(imagePullSecrets []api.LocalObjectReference) validation.ErrorList {
allErrors := validation.ValidationErrorList{} allErrors := validation.ErrorList{}
for i, currPullSecret := range imagePullSecrets { for i, currPullSecret := range imagePullSecrets {
strippedRef := api.LocalObjectReference{Name: currPullSecret.Name} strippedRef := api.LocalObjectReference{Name: currPullSecret.Name}
@ -1106,8 +1106,8 @@ func validateImagePullSecrets(imagePullSecrets []api.LocalObjectReference) valid
} }
// ValidatePod tests if required fields in the pod are set. // ValidatePod tests if required fields in the pod are set.
func ValidatePod(pod *api.Pod) validation.ValidationErrorList { func ValidatePod(pod *api.Pod) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&pod.ObjectMeta, true, ValidatePodName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&pod.ObjectMeta, true, ValidatePodName).Prefix("metadata")...)
allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidatePodSpec(&pod.Spec).Prefix("spec")...)
@ -1118,8 +1118,8 @@ func ValidatePod(pod *api.Pod) validation.ValidationErrorList {
// This includes checking formatting and uniqueness. It also canonicalizes the // This includes checking formatting and uniqueness. It also canonicalizes the
// structure by setting default values and implementing any backwards-compatibility // structure by setting default values and implementing any backwards-compatibility
// tricks. // tricks.
func ValidatePodSpec(spec *api.PodSpec) validation.ValidationErrorList { func ValidatePodSpec(spec *api.PodSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allVolumes, vErrs := validateVolumes(spec.Volumes) allVolumes, vErrs := validateVolumes(spec.Volumes)
allErrs = append(allErrs, vErrs.Prefix("volumes")...) allErrs = append(allErrs, vErrs.Prefix("volumes")...)
@ -1144,8 +1144,8 @@ func ValidatePodSpec(spec *api.PodSpec) validation.ValidationErrorList {
} }
// ValidatePodSecurityContext test that the specified PodSecurityContext has valid data. // ValidatePodSecurityContext test that the specified PodSecurityContext has valid data.
func ValidatePodSecurityContext(securityContext *api.PodSecurityContext, spec *api.PodSpec) validation.ValidationErrorList { func ValidatePodSecurityContext(securityContext *api.PodSecurityContext, spec *api.PodSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if securityContext != nil { if securityContext != nil {
allErrs = append(allErrs, validateHostNetwork(securityContext.HostNetwork, spec.Containers).Prefix("hostNetwork")...) allErrs = append(allErrs, validateHostNetwork(securityContext.HostNetwork, spec.Containers).Prefix("hostNetwork")...)
@ -1156,8 +1156,8 @@ func ValidatePodSecurityContext(securityContext *api.PodSecurityContext, spec *a
// ValidatePodUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields // ValidatePodUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields
// that cannot be changed. // that cannot be changed.
func ValidatePodUpdate(newPod, oldPod *api.Pod) validation.ValidationErrorList { func ValidatePodUpdate(newPod, oldPod *api.Pod) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPod.ObjectMeta, &oldPod.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPod.ObjectMeta, &oldPod.ObjectMeta).Prefix("metadata")...)
@ -1185,8 +1185,8 @@ func ValidatePodUpdate(newPod, oldPod *api.Pod) validation.ValidationErrorList {
// ValidatePodStatusUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields // ValidatePodStatusUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields
// that cannot be changed. // that cannot be changed.
func ValidatePodStatusUpdate(newPod, oldPod *api.Pod) validation.ValidationErrorList { func ValidatePodStatusUpdate(newPod, oldPod *api.Pod) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPod.ObjectMeta, &oldPod.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newPod.ObjectMeta, &oldPod.ObjectMeta).Prefix("metadata")...)
@ -1202,8 +1202,8 @@ func ValidatePodStatusUpdate(newPod, oldPod *api.Pod) validation.ValidationError
} }
// ValidatePodTemplate tests if required fields in the pod template are set. // ValidatePodTemplate tests if required fields in the pod template are set.
func ValidatePodTemplate(pod *api.PodTemplate) validation.ValidationErrorList { func ValidatePodTemplate(pod *api.PodTemplate) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&pod.ObjectMeta, true, ValidatePodName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&pod.ObjectMeta, true, ValidatePodName).Prefix("metadata")...)
allErrs = append(allErrs, ValidatePodTemplateSpec(&pod.Template).Prefix("template")...) allErrs = append(allErrs, ValidatePodTemplateSpec(&pod.Template).Prefix("template")...)
return allErrs return allErrs
@ -1211,8 +1211,8 @@ func ValidatePodTemplate(pod *api.PodTemplate) validation.ValidationErrorList {
// ValidatePodTemplateUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields // ValidatePodTemplateUpdate tests to see if the update is legal for an end user to make. newPod is updated with fields
// that cannot be changed. // that cannot be changed.
func ValidatePodTemplateUpdate(newPod, oldPod *api.PodTemplate) validation.ValidationErrorList { func ValidatePodTemplateUpdate(newPod, oldPod *api.PodTemplate) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&oldPod.ObjectMeta, &newPod.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&oldPod.ObjectMeta, &newPod.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidatePodTemplateSpec(&newPod.Template).Prefix("template")...) allErrs = append(allErrs, ValidatePodTemplateSpec(&newPod.Template).Prefix("template")...)
return allErrs return allErrs
@ -1223,8 +1223,8 @@ var supportedServiceType = sets.NewString(string(api.ServiceTypeClusterIP), stri
string(api.ServiceTypeLoadBalancer)) string(api.ServiceTypeLoadBalancer))
// ValidateService tests if required fields in the service are set. // ValidateService tests if required fields in the service are set.
func ValidateService(service *api.Service) validation.ValidationErrorList { func ValidateService(service *api.Service) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&service.ObjectMeta, true, ValidateServiceName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&service.ObjectMeta, true, ValidateServiceName).Prefix("metadata")...)
if len(service.Spec.Ports) == 0 && service.Spec.ClusterIP != api.ClusterIPNone { if len(service.Spec.Ports) == 0 && service.Spec.ClusterIP != api.ClusterIPNone {
@ -1308,8 +1308,8 @@ func ValidateService(service *api.Service) validation.ValidationErrorList {
return allErrs return allErrs
} }
func validateServicePort(sp *api.ServicePort, requireName bool, allNames *sets.String) validation.ValidationErrorList { func validateServicePort(sp *api.ServicePort, requireName bool, allNames *sets.String) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if requireName && sp.Name == "" { if requireName && sp.Name == "" {
allErrs = append(allErrs, validation.NewFieldRequired("name")) allErrs = append(allErrs, validation.NewFieldRequired("name"))
@ -1344,8 +1344,8 @@ func validateServicePort(sp *api.ServicePort, requireName bool, allNames *sets.S
} }
// ValidateServiceUpdate tests if required fields in the service are set during an update // ValidateServiceUpdate tests if required fields in the service are set during an update
func ValidateServiceUpdate(service, oldService *api.Service) validation.ValidationErrorList { func ValidateServiceUpdate(service, oldService *api.Service) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&service.ObjectMeta, &oldService.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&service.ObjectMeta, &oldService.ObjectMeta).Prefix("metadata")...)
if api.IsServiceIPSet(oldService) { if api.IsServiceIPSet(oldService) {
@ -1357,24 +1357,24 @@ func ValidateServiceUpdate(service, oldService *api.Service) validation.Validati
} }
// ValidateReplicationController tests if required fields in the replication controller are set. // ValidateReplicationController tests if required fields in the replication controller are set.
func ValidateReplicationController(controller *api.ReplicationController) validation.ValidationErrorList { func ValidateReplicationController(controller *api.ReplicationController) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&controller.ObjectMeta, true, ValidateReplicationControllerName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&controller.ObjectMeta, true, ValidateReplicationControllerName).Prefix("metadata")...)
allErrs = append(allErrs, ValidateReplicationControllerSpec(&controller.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateReplicationControllerSpec(&controller.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
// ValidateReplicationControllerUpdate tests if required fields in the replication controller are set. // ValidateReplicationControllerUpdate tests if required fields in the replication controller are set.
func ValidateReplicationControllerUpdate(controller, oldController *api.ReplicationController) validation.ValidationErrorList { func ValidateReplicationControllerUpdate(controller, oldController *api.ReplicationController) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateReplicationControllerSpec(&controller.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateReplicationControllerSpec(&controller.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
// ValidateReplicationControllerStatusUpdate tests if required fields in the replication controller are set. // ValidateReplicationControllerStatusUpdate tests if required fields in the replication controller are set.
func ValidateReplicationControllerStatusUpdate(controller, oldController *api.ReplicationController) validation.ValidationErrorList { func ValidateReplicationControllerStatusUpdate(controller, oldController *api.ReplicationController) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidatePositiveField(int64(controller.Status.Replicas), "status.replicas")...) allErrs = append(allErrs, ValidatePositiveField(int64(controller.Status.Replicas), "status.replicas")...)
allErrs = append(allErrs, ValidatePositiveField(int64(controller.Status.ObservedGeneration), "status.observedGeneration")...) allErrs = append(allErrs, ValidatePositiveField(int64(controller.Status.ObservedGeneration), "status.observedGeneration")...)
@ -1382,8 +1382,8 @@ func ValidateReplicationControllerStatusUpdate(controller, oldController *api.Re
} }
// Validates that the given selector is non-empty. // Validates that the given selector is non-empty.
func ValidateNonEmptySelector(selectorMap map[string]string, fieldName string) validation.ValidationErrorList { func ValidateNonEmptySelector(selectorMap map[string]string, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
selector := labels.Set(selectorMap).AsSelector() selector := labels.Set(selectorMap).AsSelector()
if selector.Empty() { if selector.Empty() {
allErrs = append(allErrs, validation.NewFieldRequired(fieldName)) allErrs = append(allErrs, validation.NewFieldRequired(fieldName))
@ -1392,8 +1392,8 @@ func ValidateNonEmptySelector(selectorMap map[string]string, fieldName string) v
} }
// Validates the given template and ensures that it is in accordance with the desrired selector and replicas. // Validates the given template and ensures that it is in accordance with the desrired selector and replicas.
func ValidatePodTemplateSpecForRC(template *api.PodTemplateSpec, selectorMap map[string]string, replicas int, fieldName string) validation.ValidationErrorList { func ValidatePodTemplateSpecForRC(template *api.PodTemplateSpec, selectorMap map[string]string, replicas int, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if template == nil { if template == nil {
allErrs = append(allErrs, validation.NewFieldRequired(fieldName)) allErrs = append(allErrs, validation.NewFieldRequired(fieldName))
} else { } else {
@ -1418,8 +1418,8 @@ func ValidatePodTemplateSpecForRC(template *api.PodTemplateSpec, selectorMap map
} }
// ValidateReplicationControllerSpec tests if required fields in the replication controller spec are set. // ValidateReplicationControllerSpec tests if required fields in the replication controller spec are set.
func ValidateReplicationControllerSpec(spec *api.ReplicationControllerSpec) validation.ValidationErrorList { func ValidateReplicationControllerSpec(spec *api.ReplicationControllerSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateNonEmptySelector(spec.Selector, "selector")...) allErrs = append(allErrs, ValidateNonEmptySelector(spec.Selector, "selector")...)
allErrs = append(allErrs, ValidatePositiveField(int64(spec.Replicas), "replicas")...) allErrs = append(allErrs, ValidatePositiveField(int64(spec.Replicas), "replicas")...)
@ -1428,16 +1428,16 @@ func ValidateReplicationControllerSpec(spec *api.ReplicationControllerSpec) vali
} }
// ValidatePodTemplateSpec validates the spec of a pod template // ValidatePodTemplateSpec validates the spec of a pod template
func ValidatePodTemplateSpec(spec *api.PodTemplateSpec) validation.ValidationErrorList { func ValidatePodTemplateSpec(spec *api.PodTemplateSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateLabels(spec.Labels, "labels")...) allErrs = append(allErrs, ValidateLabels(spec.Labels, "labels")...)
allErrs = append(allErrs, ValidateAnnotations(spec.Annotations, "annotations")...) allErrs = append(allErrs, ValidateAnnotations(spec.Annotations, "annotations")...)
allErrs = append(allErrs, ValidatePodSpec(&spec.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidatePodSpec(&spec.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
func ValidateReadOnlyPersistentDisks(volumes []api.Volume) validation.ValidationErrorList { func ValidateReadOnlyPersistentDisks(volumes []api.Volume) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for _, vol := range volumes { for _, vol := range volumes {
if vol.GCEPersistentDisk != nil { if vol.GCEPersistentDisk != nil {
if vol.GCEPersistentDisk.ReadOnly == false { if vol.GCEPersistentDisk.ReadOnly == false {
@ -1450,8 +1450,8 @@ func ValidateReadOnlyPersistentDisks(volumes []api.Volume) validation.Validation
} }
// ValidateNode tests if required fields in the node are set. // ValidateNode tests if required fields in the node are set.
func ValidateNode(node *api.Node) validation.ValidationErrorList { func ValidateNode(node *api.Node) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&node.ObjectMeta, false, ValidateNodeName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&node.ObjectMeta, false, ValidateNodeName).Prefix("metadata")...)
// Only validate spec. All status fields are optional and can be updated later. // Only validate spec. All status fields are optional and can be updated later.
@ -1466,8 +1466,8 @@ func ValidateNode(node *api.Node) validation.ValidationErrorList {
} }
// ValidateNodeUpdate tests to make sure a node update can be applied. Modifies oldNode. // ValidateNodeUpdate tests to make sure a node update can be applied. Modifies oldNode.
func ValidateNodeUpdate(node, oldNode *api.Node) validation.ValidationErrorList { func ValidateNodeUpdate(node, oldNode *api.Node) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&node.ObjectMeta, &oldNode.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&node.ObjectMeta, &oldNode.ObjectMeta).Prefix("metadata")...)
// TODO: Enable the code once we have better api object.status update model. Currently, // TODO: Enable the code once we have better api object.status update model. Currently,
@ -1508,8 +1508,8 @@ func ValidateNodeUpdate(node, oldNode *api.Node) validation.ValidationErrorList
// Validate compute resource typename. // Validate compute resource typename.
// Refer to docs/design/resources.md for more details. // Refer to docs/design/resources.md for more details.
func validateResourceName(value string, field string) validation.ValidationErrorList { func validateResourceName(value string, field string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if !validation.IsQualifiedName(value) { if !validation.IsQualifiedName(value) {
return append(allErrs, validation.NewFieldInvalid(field, value, "resource typename: "+qualifiedNameErrorMsg)) return append(allErrs, validation.NewFieldInvalid(field, value, "resource typename: "+qualifiedNameErrorMsg))
} }
@ -1520,12 +1520,12 @@ func validateResourceName(value string, field string) validation.ValidationError
} }
} }
return validation.ValidationErrorList{} return validation.ErrorList{}
} }
// ValidateLimitRange tests if required fields in the LimitRange are set. // ValidateLimitRange tests if required fields in the LimitRange are set.
func ValidateLimitRange(limitRange *api.LimitRange) validation.ValidationErrorList { func ValidateLimitRange(limitRange *api.LimitRange) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&limitRange.ObjectMeta, true, ValidateLimitRangeName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&limitRange.ObjectMeta, true, ValidateLimitRangeName).Prefix("metadata")...)
// ensure resource names are properly qualified per docs/design/resources.md // ensure resource names are properly qualified per docs/design/resources.md
@ -1636,15 +1636,15 @@ func ValidateLimitRange(limitRange *api.LimitRange) validation.ValidationErrorLi
} }
// ValidateServiceAccount tests if required fields in the ServiceAccount are set. // ValidateServiceAccount tests if required fields in the ServiceAccount are set.
func ValidateServiceAccount(serviceAccount *api.ServiceAccount) validation.ValidationErrorList { func ValidateServiceAccount(serviceAccount *api.ServiceAccount) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&serviceAccount.ObjectMeta, true, ValidateServiceAccountName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&serviceAccount.ObjectMeta, true, ValidateServiceAccountName).Prefix("metadata")...)
return allErrs return allErrs
} }
// ValidateServiceAccountUpdate tests if required fields in the ServiceAccount are set. // ValidateServiceAccountUpdate tests if required fields in the ServiceAccount are set.
func ValidateServiceAccountUpdate(newServiceAccount, oldServiceAccount *api.ServiceAccount) validation.ValidationErrorList { func ValidateServiceAccountUpdate(newServiceAccount, oldServiceAccount *api.ServiceAccount) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newServiceAccount.ObjectMeta, &oldServiceAccount.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newServiceAccount.ObjectMeta, &oldServiceAccount.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateServiceAccount(newServiceAccount)...) allErrs = append(allErrs, ValidateServiceAccount(newServiceAccount)...)
return allErrs return allErrs
@ -1661,8 +1661,8 @@ func IsSecretKey(value string) bool {
} }
// ValidateSecret tests if required fields in the Secret are set. // ValidateSecret tests if required fields in the Secret are set.
func ValidateSecret(secret *api.Secret) validation.ValidationErrorList { func ValidateSecret(secret *api.Secret) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&secret.ObjectMeta, true, ValidateSecretName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&secret.ObjectMeta, true, ValidateSecretName).Prefix("metadata")...)
totalSize := 0 totalSize := 0
@ -1707,8 +1707,8 @@ func ValidateSecret(secret *api.Secret) validation.ValidationErrorList {
} }
// ValidateSecretUpdate tests if required fields in the Secret are set. // ValidateSecretUpdate tests if required fields in the Secret are set.
func ValidateSecretUpdate(newSecret, oldSecret *api.Secret) validation.ValidationErrorList { func ValidateSecretUpdate(newSecret, oldSecret *api.Secret) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newSecret.ObjectMeta, &oldSecret.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newSecret.ObjectMeta, &oldSecret.ObjectMeta).Prefix("metadata")...)
if len(newSecret.Type) == 0 { if len(newSecret.Type) == 0 {
@ -1721,16 +1721,16 @@ func ValidateSecretUpdate(newSecret, oldSecret *api.Secret) validation.Validatio
return allErrs return allErrs
} }
func validateBasicResource(quantity resource.Quantity) validation.ValidationErrorList { func validateBasicResource(quantity resource.Quantity) validation.ErrorList {
if quantity.Value() < 0 { if quantity.Value() < 0 {
return validation.ValidationErrorList{validation.NewFieldInvalid("", quantity.Value(), "must be a valid resource quantity")} return validation.ErrorList{validation.NewFieldInvalid("", quantity.Value(), "must be a valid resource quantity")}
} }
return validation.ValidationErrorList{} return validation.ErrorList{}
} }
// Validates resource requirement spec. // Validates resource requirement spec.
func ValidateResourceRequirements(requirements *api.ResourceRequirements) validation.ValidationErrorList { func ValidateResourceRequirements(requirements *api.ResourceRequirements) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for resourceName, quantity := range requirements.Limits { for resourceName, quantity := range requirements.Limits {
// Validate resource name. // Validate resource name.
allErrs = append(allErrs, validateResourceName(resourceName.String(), fmt.Sprintf("resources.limits[%s]", resourceName))...) allErrs = append(allErrs, validateResourceName(resourceName.String(), fmt.Sprintf("resources.limits[%s]", resourceName))...)
@ -1764,8 +1764,8 @@ func ValidateResourceRequirements(requirements *api.ResourceRequirements) valida
} }
// ValidateResourceQuota tests if required fields in the ResourceQuota are set. // ValidateResourceQuota tests if required fields in the ResourceQuota are set.
func ValidateResourceQuota(resourceQuota *api.ResourceQuota) validation.ValidationErrorList { func ValidateResourceQuota(resourceQuota *api.ResourceQuota) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&resourceQuota.ObjectMeta, true, ValidateResourceQuotaName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&resourceQuota.ObjectMeta, true, ValidateResourceQuotaName).Prefix("metadata")...)
for k, v := range resourceQuota.Spec.Hard { for k, v := range resourceQuota.Spec.Hard {
@ -1784,8 +1784,8 @@ func ValidateResourceQuota(resourceQuota *api.ResourceQuota) validation.Validati
} }
// validateResourceQuantityValue enforces that specified quantity is valid for specified resource // validateResourceQuantityValue enforces that specified quantity is valid for specified resource
func validateResourceQuantityValue(resource string, value resource.Quantity) validation.ValidationErrorList { func validateResourceQuantityValue(resource string, value resource.Quantity) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidatePositiveQuantity(value, resource)...) allErrs = append(allErrs, ValidatePositiveQuantity(value, resource)...)
if api.IsIntegerResourceName(resource) { if api.IsIntegerResourceName(resource) {
if value.MilliValue()%int64(1000) != int64(0) { if value.MilliValue()%int64(1000) != int64(0) {
@ -1797,8 +1797,8 @@ func validateResourceQuantityValue(resource string, value resource.Quantity) val
// ValidateResourceQuotaUpdate tests to see if the update is legal for an end user to make. // ValidateResourceQuotaUpdate tests to see if the update is legal for an end user to make.
// newResourceQuota is updated with fields that cannot be changed. // newResourceQuota is updated with fields that cannot be changed.
func ValidateResourceQuotaUpdate(newResourceQuota, oldResourceQuota *api.ResourceQuota) validation.ValidationErrorList { func ValidateResourceQuotaUpdate(newResourceQuota, oldResourceQuota *api.ResourceQuota) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newResourceQuota.ObjectMeta, &oldResourceQuota.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newResourceQuota.ObjectMeta, &oldResourceQuota.ObjectMeta).Prefix("metadata")...)
for k, v := range newResourceQuota.Spec.Hard { for k, v := range newResourceQuota.Spec.Hard {
allErrs = append(allErrs, validateResourceName(string(k), string(newResourceQuota.TypeMeta.Kind))...) allErrs = append(allErrs, validateResourceName(string(k), string(newResourceQuota.TypeMeta.Kind))...)
@ -1810,8 +1810,8 @@ func ValidateResourceQuotaUpdate(newResourceQuota, oldResourceQuota *api.Resourc
// ValidateResourceQuotaStatusUpdate tests to see if the status update is legal for an end user to make. // ValidateResourceQuotaStatusUpdate tests to see if the status update is legal for an end user to make.
// newResourceQuota is updated with fields that cannot be changed. // newResourceQuota is updated with fields that cannot be changed.
func ValidateResourceQuotaStatusUpdate(newResourceQuota, oldResourceQuota *api.ResourceQuota) validation.ValidationErrorList { func ValidateResourceQuotaStatusUpdate(newResourceQuota, oldResourceQuota *api.ResourceQuota) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newResourceQuota.ObjectMeta, &oldResourceQuota.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newResourceQuota.ObjectMeta, &oldResourceQuota.ObjectMeta).Prefix("metadata")...)
if newResourceQuota.ResourceVersion == "" { if newResourceQuota.ResourceVersion == "" {
allErrs = append(allErrs, validation.NewFieldRequired("resourceVersion")) allErrs = append(allErrs, validation.NewFieldRequired("resourceVersion"))
@ -1829,8 +1829,8 @@ func ValidateResourceQuotaStatusUpdate(newResourceQuota, oldResourceQuota *api.R
} }
// ValidateNamespace tests if required fields are set. // ValidateNamespace tests if required fields are set.
func ValidateNamespace(namespace *api.Namespace) validation.ValidationErrorList { func ValidateNamespace(namespace *api.Namespace) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&namespace.ObjectMeta, false, ValidateNamespaceName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&namespace.ObjectMeta, false, ValidateNamespaceName).Prefix("metadata")...)
for i := range namespace.Spec.Finalizers { for i := range namespace.Spec.Finalizers {
allErrs = append(allErrs, validateFinalizerName(string(namespace.Spec.Finalizers[i]))...) allErrs = append(allErrs, validateFinalizerName(string(namespace.Spec.Finalizers[i]))...)
@ -1839,8 +1839,8 @@ func ValidateNamespace(namespace *api.Namespace) validation.ValidationErrorList
} }
// Validate finalizer names // Validate finalizer names
func validateFinalizerName(stringValue string) validation.ValidationErrorList { func validateFinalizerName(stringValue string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if !validation.IsQualifiedName(stringValue) { if !validation.IsQualifiedName(stringValue) {
return append(allErrs, validation.NewFieldInvalid("spec.finalizers", stringValue, qualifiedNameErrorMsg)) return append(allErrs, validation.NewFieldInvalid("spec.finalizers", stringValue, qualifiedNameErrorMsg))
} }
@ -1851,13 +1851,13 @@ func validateFinalizerName(stringValue string) validation.ValidationErrorList {
} }
} }
return validation.ValidationErrorList{} return validation.ErrorList{}
} }
// ValidateNamespaceUpdate tests to make sure a namespace update can be applied. // ValidateNamespaceUpdate tests to make sure a namespace update can be applied.
// newNamespace is updated with fields that cannot be changed // newNamespace is updated with fields that cannot be changed
func ValidateNamespaceUpdate(newNamespace *api.Namespace, oldNamespace *api.Namespace) validation.ValidationErrorList { func ValidateNamespaceUpdate(newNamespace *api.Namespace, oldNamespace *api.Namespace) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta).Prefix("metadata")...)
newNamespace.Spec.Finalizers = oldNamespace.Spec.Finalizers newNamespace.Spec.Finalizers = oldNamespace.Spec.Finalizers
newNamespace.Status = oldNamespace.Status newNamespace.Status = oldNamespace.Status
@ -1866,8 +1866,8 @@ func ValidateNamespaceUpdate(newNamespace *api.Namespace, oldNamespace *api.Name
// ValidateNamespaceStatusUpdate tests to see if the update is legal for an end user to make. newNamespace is updated with fields // ValidateNamespaceStatusUpdate tests to see if the update is legal for an end user to make. newNamespace is updated with fields
// that cannot be changed. // that cannot be changed.
func ValidateNamespaceStatusUpdate(newNamespace, oldNamespace *api.Namespace) validation.ValidationErrorList { func ValidateNamespaceStatusUpdate(newNamespace, oldNamespace *api.Namespace) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta).Prefix("metadata")...)
newNamespace.Spec = oldNamespace.Spec newNamespace.Spec = oldNamespace.Spec
if newNamespace.DeletionTimestamp.IsZero() { if newNamespace.DeletionTimestamp.IsZero() {
@ -1884,8 +1884,8 @@ func ValidateNamespaceStatusUpdate(newNamespace, oldNamespace *api.Namespace) va
// ValidateNamespaceFinalizeUpdate tests to see if the update is legal for an end user to make. // ValidateNamespaceFinalizeUpdate tests to see if the update is legal for an end user to make.
// newNamespace is updated with fields that cannot be changed. // newNamespace is updated with fields that cannot be changed.
func ValidateNamespaceFinalizeUpdate(newNamespace, oldNamespace *api.Namespace) validation.ValidationErrorList { func ValidateNamespaceFinalizeUpdate(newNamespace, oldNamespace *api.Namespace) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newNamespace.ObjectMeta, &oldNamespace.ObjectMeta).Prefix("metadata")...)
for i := range newNamespace.Spec.Finalizers { for i := range newNamespace.Spec.Finalizers {
allErrs = append(allErrs, validateFinalizerName(string(newNamespace.Spec.Finalizers[i]))...) allErrs = append(allErrs, validateFinalizerName(string(newNamespace.Spec.Finalizers[i]))...)
@ -1895,20 +1895,20 @@ func ValidateNamespaceFinalizeUpdate(newNamespace, oldNamespace *api.Namespace)
} }
// ValidateEndpoints tests if required fields are set. // ValidateEndpoints tests if required fields are set.
func ValidateEndpoints(endpoints *api.Endpoints) validation.ValidationErrorList { func ValidateEndpoints(endpoints *api.Endpoints) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMeta(&endpoints.ObjectMeta, true, ValidateEndpointsName).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMeta(&endpoints.ObjectMeta, true, ValidateEndpointsName).Prefix("metadata")...)
allErrs = append(allErrs, validateEndpointSubsets(endpoints.Subsets).Prefix("subsets")...) allErrs = append(allErrs, validateEndpointSubsets(endpoints.Subsets).Prefix("subsets")...)
return allErrs return allErrs
} }
func validateEndpointSubsets(subsets []api.EndpointSubset) validation.ValidationErrorList { func validateEndpointSubsets(subsets []api.EndpointSubset) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for i := range subsets { for i := range subsets {
ss := &subsets[i] ss := &subsets[i]
ssErrs := validation.ValidationErrorList{} ssErrs := validation.ErrorList{}
if len(ss.Addresses) == 0 && len(ss.NotReadyAddresses) == 0 { if len(ss.Addresses) == 0 && len(ss.NotReadyAddresses) == 0 {
ssErrs = append(ssErrs, validation.NewFieldRequired("addresses or notReadyAddresses")) ssErrs = append(ssErrs, validation.NewFieldRequired("addresses or notReadyAddresses"))
@ -1929,8 +1929,8 @@ func validateEndpointSubsets(subsets []api.EndpointSubset) validation.Validation
return allErrs return allErrs
} }
func validateEndpointAddress(address *api.EndpointAddress) validation.ValidationErrorList { func validateEndpointAddress(address *api.EndpointAddress) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if !validation.IsValidIPv4(address.IP) { if !validation.IsValidIPv4(address.IP) {
allErrs = append(allErrs, validation.NewFieldInvalid("ip", address.IP, "invalid IPv4 address")) allErrs = append(allErrs, validation.NewFieldInvalid("ip", address.IP, "invalid IPv4 address"))
return allErrs return allErrs
@ -1938,10 +1938,10 @@ func validateEndpointAddress(address *api.EndpointAddress) validation.Validation
return validateIpIsNotLinkLocalOrLoopback(address.IP, "ip") return validateIpIsNotLinkLocalOrLoopback(address.IP, "ip")
} }
func validateIpIsNotLinkLocalOrLoopback(ipAddress, fieldName string) validation.ValidationErrorList { func validateIpIsNotLinkLocalOrLoopback(ipAddress, fieldName string) validation.ErrorList {
// We disallow some IPs as endpoints or external-ips. Specifically, loopback addresses are // We disallow some IPs as endpoints or external-ips. Specifically, loopback addresses are
// nonsensical and link-local addresses tend to be used for node-centric purposes (e.g. metadata service). // nonsensical and link-local addresses tend to be used for node-centric purposes (e.g. metadata service).
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
ip := net.ParseIP(ipAddress) ip := net.ParseIP(ipAddress)
if ip == nil { if ip == nil {
allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, ipAddress, "not a valid IP address")) allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, ipAddress, "not a valid IP address"))
@ -1959,8 +1959,8 @@ func validateIpIsNotLinkLocalOrLoopback(ipAddress, fieldName string) validation.
return allErrs return allErrs
} }
func validateEndpointPort(port *api.EndpointPort, requireName bool) validation.ValidationErrorList { func validateEndpointPort(port *api.EndpointPort, requireName bool) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if requireName && port.Name == "" { if requireName && port.Name == "" {
allErrs = append(allErrs, validation.NewFieldRequired("name")) allErrs = append(allErrs, validation.NewFieldRequired("name"))
} else if port.Name != "" { } else if port.Name != "" {
@ -1980,16 +1980,16 @@ func validateEndpointPort(port *api.EndpointPort, requireName bool) validation.V
} }
// ValidateEndpointsUpdate tests to make sure an endpoints update can be applied. // ValidateEndpointsUpdate tests to make sure an endpoints update can be applied.
func ValidateEndpointsUpdate(newEndpoints, oldEndpoints *api.Endpoints) validation.ValidationErrorList { func ValidateEndpointsUpdate(newEndpoints, oldEndpoints *api.Endpoints) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateObjectMetaUpdate(&newEndpoints.ObjectMeta, &oldEndpoints.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, ValidateObjectMetaUpdate(&newEndpoints.ObjectMeta, &oldEndpoints.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, validateEndpointSubsets(newEndpoints.Subsets).Prefix("subsets")...) allErrs = append(allErrs, validateEndpointSubsets(newEndpoints.Subsets).Prefix("subsets")...)
return allErrs return allErrs
} }
// ValidateSecurityContext ensure the security context contains valid settings // ValidateSecurityContext ensure the security context contains valid settings
func ValidateSecurityContext(sc *api.SecurityContext) validation.ValidationErrorList { func ValidateSecurityContext(sc *api.SecurityContext) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
//this should only be true for testing since SecurityContext is defaulted by the api //this should only be true for testing since SecurityContext is defaulted by the api
if sc == nil { if sc == nil {
return allErrs return allErrs
@ -2009,8 +2009,8 @@ func ValidateSecurityContext(sc *api.SecurityContext) validation.ValidationError
return allErrs return allErrs
} }
func ValidatePodLogOptions(opts *api.PodLogOptions) validation.ValidationErrorList { func ValidatePodLogOptions(opts *api.PodLogOptions) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if opts.TailLines != nil && *opts.TailLines < 0 { if opts.TailLines != nil && *opts.TailLines < 0 {
allErrs = append(allErrs, validation.NewFieldInvalid("tailLines", *opts.TailLines, "tailLines must be a non-negative integer or nil")) allErrs = append(allErrs, validation.NewFieldInvalid("tailLines", *opts.TailLines, "tailLines must be a non-negative integer or nil"))
} }
@ -2030,8 +2030,8 @@ func ValidatePodLogOptions(opts *api.PodLogOptions) validation.ValidationErrorLi
} }
// ValidateLoadBalancerStatus validates required fields on a LoadBalancerStatus // ValidateLoadBalancerStatus validates required fields on a LoadBalancerStatus
func ValidateLoadBalancerStatus(status *api.LoadBalancerStatus) validation.ValidationErrorList { func ValidateLoadBalancerStatus(status *api.LoadBalancerStatus) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
for _, ingress := range status.Ingress { for _, ingress := range status.Ingress {
if len(ingress.IP) > 0 { if len(ingress.IP) > 0 {
if isIP := (net.ParseIP(ingress.IP) != nil); !isIP { if isIP := (net.ParseIP(ingress.IP) != nil); !isIP {

View File

@ -34,7 +34,7 @@ import (
"k8s.io/kubernetes/pkg/util/validation" "k8s.io/kubernetes/pkg/util/validation"
) )
func expectPrefix(t *testing.T, prefix string, errs validation.ValidationErrorList) { func expectPrefix(t *testing.T, prefix string, errs validation.ErrorList) {
for i := range errs { for i := range errs {
if f, p := errs[i].(*validation.Error).Field, prefix; !strings.HasPrefix(f, p) { if f, p := errs[i].(*validation.Error).Field, prefix; !strings.HasPrefix(f, p) {
t.Errorf("expected prefix '%s' for field '%s' (%v)", p, f, errs[i]) t.Errorf("expected prefix '%s' for field '%s' (%v)", p, f, errs[i])

View File

@ -39,8 +39,8 @@ func ValidateHorizontalPodAutoscalerName(name string, prefix bool) (bool, string
return apivalidation.ValidateReplicationControllerName(name, prefix) return apivalidation.ValidateReplicationControllerName(name, prefix)
} }
func validateHorizontalPodAutoscalerSpec(autoscaler extensions.HorizontalPodAutoscalerSpec) validation.ValidationErrorList { func validateHorizontalPodAutoscalerSpec(autoscaler extensions.HorizontalPodAutoscalerSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if autoscaler.MinReplicas != nil && *autoscaler.MinReplicas < 1 { if autoscaler.MinReplicas != nil && *autoscaler.MinReplicas < 1 {
allErrs = append(allErrs, validation.NewFieldInvalid("minReplicas", autoscaler.MinReplicas, `must be bigger or equal to 1`)) allErrs = append(allErrs, validation.NewFieldInvalid("minReplicas", autoscaler.MinReplicas, `must be bigger or equal to 1`))
} }
@ -61,8 +61,8 @@ func validateHorizontalPodAutoscalerSpec(autoscaler extensions.HorizontalPodAuto
return allErrs return allErrs
} }
func ValidateSubresourceReference(ref extensions.SubresourceReference) validation.ValidationErrorList { func ValidateSubresourceReference(ref extensions.SubresourceReference) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(ref.Kind) == 0 { if len(ref.Kind) == 0 {
allErrs = append(allErrs, validation.NewFieldRequired("kind")) allErrs = append(allErrs, validation.NewFieldRequired("kind"))
} else if ok, msg := apivalidation.IsValidPathSegmentName(ref.Kind); !ok { } else if ok, msg := apivalidation.IsValidPathSegmentName(ref.Kind); !ok {
@ -83,22 +83,22 @@ func ValidateSubresourceReference(ref extensions.SubresourceReference) validatio
return allErrs return allErrs
} }
func ValidateHorizontalPodAutoscaler(autoscaler *extensions.HorizontalPodAutoscaler) validation.ValidationErrorList { func ValidateHorizontalPodAutoscaler(autoscaler *extensions.HorizontalPodAutoscaler) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&autoscaler.ObjectMeta, true, ValidateHorizontalPodAutoscalerName).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&autoscaler.ObjectMeta, true, ValidateHorizontalPodAutoscalerName).Prefix("metadata")...)
allErrs = append(allErrs, validateHorizontalPodAutoscalerSpec(autoscaler.Spec)...) allErrs = append(allErrs, validateHorizontalPodAutoscalerSpec(autoscaler.Spec)...)
return allErrs return allErrs
} }
func ValidateHorizontalPodAutoscalerUpdate(newAutoscler, oldAutoscaler *extensions.HorizontalPodAutoscaler) validation.ValidationErrorList { func ValidateHorizontalPodAutoscalerUpdate(newAutoscler, oldAutoscaler *extensions.HorizontalPodAutoscaler) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&newAutoscler.ObjectMeta, &oldAutoscaler.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&newAutoscler.ObjectMeta, &oldAutoscaler.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, validateHorizontalPodAutoscalerSpec(newAutoscler.Spec)...) allErrs = append(allErrs, validateHorizontalPodAutoscalerSpec(newAutoscler.Spec)...)
return allErrs return allErrs
} }
func ValidateHorizontalPodAutoscalerStatusUpdate(controller, oldController *extensions.HorizontalPodAutoscaler) validation.ValidationErrorList { func ValidateHorizontalPodAutoscalerStatusUpdate(controller, oldController *extensions.HorizontalPodAutoscaler) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...)
status := controller.Status status := controller.Status
@ -107,8 +107,8 @@ func ValidateHorizontalPodAutoscalerStatusUpdate(controller, oldController *exte
return allErrs return allErrs
} }
func ValidateThirdPartyResourceUpdate(update, old *extensions.ThirdPartyResource) validation.ValidationErrorList { func ValidateThirdPartyResourceUpdate(update, old *extensions.ThirdPartyResource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateThirdPartyResource(update)...) allErrs = append(allErrs, ValidateThirdPartyResource(update)...)
return allErrs return allErrs
@ -118,8 +118,8 @@ func ValidateThirdPartyResourceName(name string, prefix bool) (bool, string) {
return apivalidation.NameIsDNSSubdomain(name, prefix) return apivalidation.NameIsDNSSubdomain(name, prefix)
} }
func ValidateThirdPartyResource(obj *extensions.ThirdPartyResource) validation.ValidationErrorList { func ValidateThirdPartyResource(obj *extensions.ThirdPartyResource) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateThirdPartyResourceName).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateThirdPartyResourceName).Prefix("metadata")...)
versions := sets.String{} versions := sets.String{}
@ -137,16 +137,16 @@ func ValidateThirdPartyResource(obj *extensions.ThirdPartyResource) validation.V
} }
// ValidateDaemonSet tests if required fields in the DaemonSet are set. // ValidateDaemonSet tests if required fields in the DaemonSet are set.
func ValidateDaemonSet(controller *extensions.DaemonSet) validation.ValidationErrorList { func ValidateDaemonSet(controller *extensions.DaemonSet) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&controller.ObjectMeta, true, ValidateDaemonSetName).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&controller.ObjectMeta, true, ValidateDaemonSetName).Prefix("metadata")...)
allErrs = append(allErrs, ValidateDaemonSetSpec(&controller.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateDaemonSetSpec(&controller.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
// ValidateDaemonSetUpdate tests if required fields in the DaemonSet are set. // ValidateDaemonSetUpdate tests if required fields in the DaemonSet are set.
func ValidateDaemonSetUpdate(controller, oldController *extensions.DaemonSet) validation.ValidationErrorList { func ValidateDaemonSetUpdate(controller, oldController *extensions.DaemonSet) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateDaemonSetSpec(&controller.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateDaemonSetSpec(&controller.Spec).Prefix("spec")...)
allErrs = append(allErrs, ValidateDaemonSetTemplateUpdate(controller.Spec.Template, oldController.Spec.Template).Prefix("spec.template")...) allErrs = append(allErrs, ValidateDaemonSetTemplateUpdate(controller.Spec.Template, oldController.Spec.Template).Prefix("spec.template")...)
@ -154,8 +154,8 @@ func ValidateDaemonSetUpdate(controller, oldController *extensions.DaemonSet) va
} }
// validateDaemonSetStatus validates a DaemonSetStatus // validateDaemonSetStatus validates a DaemonSetStatus
func validateDaemonSetStatus(status *extensions.DaemonSetStatus) validation.ValidationErrorList { func validateDaemonSetStatus(status *extensions.DaemonSetStatus) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.CurrentNumberScheduled), "currentNumberScheduled")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.CurrentNumberScheduled), "currentNumberScheduled")...)
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.NumberMisscheduled), "numberMisscheduled")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.NumberMisscheduled), "numberMisscheduled")...)
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.DesiredNumberScheduled), "desiredNumberScheduled")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.DesiredNumberScheduled), "desiredNumberScheduled")...)
@ -163,16 +163,16 @@ func validateDaemonSetStatus(status *extensions.DaemonSetStatus) validation.Vali
} }
// ValidateDaemonSetStatus validates tests if required fields in the DaemonSet Status section // ValidateDaemonSetStatus validates tests if required fields in the DaemonSet Status section
func ValidateDaemonSetStatusUpdate(controller, oldController *extensions.DaemonSet) validation.ValidationErrorList { func ValidateDaemonSetStatusUpdate(controller, oldController *extensions.DaemonSet) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&controller.ObjectMeta, &oldController.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, validateDaemonSetStatus(&controller.Status)...) allErrs = append(allErrs, validateDaemonSetStatus(&controller.Status)...)
return allErrs return allErrs
} }
// ValidateDaemonSetTemplateUpdate tests that certain fields in the daemon set's pod template are not updated. // ValidateDaemonSetTemplateUpdate tests that certain fields in the daemon set's pod template are not updated.
func ValidateDaemonSetTemplateUpdate(podTemplate, oldPodTemplate *api.PodTemplateSpec) validation.ValidationErrorList { func ValidateDaemonSetTemplateUpdate(podTemplate, oldPodTemplate *api.PodTemplateSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
podSpec := podTemplate.Spec podSpec := podTemplate.Spec
// podTemplate.Spec is not a pointer, so we can modify NodeSelector and NodeName directly. // podTemplate.Spec is not a pointer, so we can modify NodeSelector and NodeName directly.
podSpec.NodeSelector = oldPodTemplate.Spec.NodeSelector podSpec.NodeSelector = oldPodTemplate.Spec.NodeSelector
@ -186,8 +186,8 @@ func ValidateDaemonSetTemplateUpdate(podTemplate, oldPodTemplate *api.PodTemplat
} }
// ValidateDaemonSetSpec tests if required fields in the DaemonSetSpec are set. // ValidateDaemonSetSpec tests if required fields in the DaemonSetSpec are set.
func ValidateDaemonSetSpec(spec *extensions.DaemonSetSpec) validation.ValidationErrorList { func ValidateDaemonSetSpec(spec *extensions.DaemonSetSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidatePodSelector(spec.Selector)...) allErrs = append(allErrs, ValidatePodSelector(spec.Selector)...)
@ -224,8 +224,8 @@ func ValidateDeploymentName(name string, prefix bool) (bool, string) {
return apivalidation.NameIsDNSSubdomain(name, prefix) return apivalidation.NameIsDNSSubdomain(name, prefix)
} }
func ValidatePositiveIntOrPercent(intOrPercent intstr.IntOrString, fieldName string) validation.ValidationErrorList { func ValidatePositiveIntOrPercent(intOrPercent intstr.IntOrString, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if intOrPercent.Type == intstr.String { if intOrPercent.Type == intstr.String {
if !validation.IsValidPercent(intOrPercent.StrVal) { if !validation.IsValidPercent(intOrPercent.StrVal) {
allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, intOrPercent, "value should be int(5) or percentage(5%)")) allErrs = append(allErrs, validation.NewFieldInvalid(fieldName, intOrPercent, "value should be int(5) or percentage(5%)"))
@ -252,8 +252,8 @@ func getIntOrPercentValue(intOrStringValue intstr.IntOrString) int {
return intOrStringValue.IntVal return intOrStringValue.IntVal
} }
func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fieldName string) validation.ValidationErrorList { func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
value, isPercent := getPercentValue(intOrStringValue) value, isPercent := getPercentValue(intOrStringValue)
if !isPercent || value <= 100 { if !isPercent || value <= 100 {
return nil return nil
@ -262,8 +262,8 @@ func IsNotMoreThan100Percent(intOrStringValue intstr.IntOrString, fieldName stri
return allErrs return allErrs
} }
func ValidateRollingUpdateDeployment(rollingUpdate *extensions.RollingUpdateDeployment, fieldName string) validation.ValidationErrorList { func ValidateRollingUpdateDeployment(rollingUpdate *extensions.RollingUpdateDeployment, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxUnavailable, fieldName+"maxUnavailable")...) allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxUnavailable, fieldName+"maxUnavailable")...)
allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxSurge, fieldName+".maxSurge")...) allErrs = append(allErrs, ValidatePositiveIntOrPercent(rollingUpdate.MaxSurge, fieldName+".maxSurge")...)
if getIntOrPercentValue(rollingUpdate.MaxUnavailable) == 0 && getIntOrPercentValue(rollingUpdate.MaxSurge) == 0 { if getIntOrPercentValue(rollingUpdate.MaxUnavailable) == 0 && getIntOrPercentValue(rollingUpdate.MaxSurge) == 0 {
@ -276,8 +276,8 @@ func ValidateRollingUpdateDeployment(rollingUpdate *extensions.RollingUpdateDepl
return allErrs return allErrs
} }
func ValidateDeploymentStrategy(strategy *extensions.DeploymentStrategy, fieldName string) validation.ValidationErrorList { func ValidateDeploymentStrategy(strategy *extensions.DeploymentStrategy, fieldName string) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if strategy.RollingUpdate == nil { if strategy.RollingUpdate == nil {
return allErrs return allErrs
} }
@ -291,8 +291,8 @@ func ValidateDeploymentStrategy(strategy *extensions.DeploymentStrategy, fieldNa
} }
// Validates given deployment spec. // Validates given deployment spec.
func ValidateDeploymentSpec(spec *extensions.DeploymentSpec) validation.ValidationErrorList { func ValidateDeploymentSpec(spec *extensions.DeploymentSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateNonEmptySelector(spec.Selector, "selector")...) allErrs = append(allErrs, apivalidation.ValidateNonEmptySelector(spec.Selector, "selector")...)
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(spec.Replicas), "replicas")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(spec.Replicas), "replicas")...)
allErrs = append(allErrs, apivalidation.ValidatePodTemplateSpecForRC(&spec.Template, spec.Selector, spec.Replicas, "template")...) allErrs = append(allErrs, apivalidation.ValidatePodTemplateSpecForRC(&spec.Template, spec.Selector, spec.Replicas, "template")...)
@ -301,42 +301,42 @@ func ValidateDeploymentSpec(spec *extensions.DeploymentSpec) validation.Validati
return allErrs return allErrs
} }
func ValidateDeploymentUpdate(update, old *extensions.Deployment) validation.ValidationErrorList { func ValidateDeploymentUpdate(update, old *extensions.Deployment) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&update.ObjectMeta, &old.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateDeploymentSpec(&update.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateDeploymentSpec(&update.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
func ValidateDeployment(obj *extensions.Deployment) validation.ValidationErrorList { func ValidateDeployment(obj *extensions.Deployment) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateDeploymentName).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&obj.ObjectMeta, true, ValidateDeploymentName).Prefix("metadata")...)
allErrs = append(allErrs, ValidateDeploymentSpec(&obj.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateDeploymentSpec(&obj.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
func ValidateThirdPartyResourceDataUpdate(update, old *extensions.ThirdPartyResourceData) validation.ValidationErrorList { func ValidateThirdPartyResourceDataUpdate(update, old *extensions.ThirdPartyResourceData) validation.ErrorList {
return ValidateThirdPartyResourceData(update) return ValidateThirdPartyResourceData(update)
} }
func ValidateThirdPartyResourceData(obj *extensions.ThirdPartyResourceData) validation.ValidationErrorList { func ValidateThirdPartyResourceData(obj *extensions.ThirdPartyResourceData) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(obj.Name) == 0 { if len(obj.Name) == 0 {
allErrs = append(allErrs, validation.NewFieldInvalid("name", obj.Name, "name must be non-empty")) allErrs = append(allErrs, validation.NewFieldInvalid("name", obj.Name, "name must be non-empty"))
} }
return allErrs return allErrs
} }
func ValidateJob(job *extensions.Job) validation.ValidationErrorList { func ValidateJob(job *extensions.Job) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
// Jobs and rcs have the same name validation // Jobs and rcs have the same name validation
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&job.ObjectMeta, true, apivalidation.ValidateReplicationControllerName).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&job.ObjectMeta, true, apivalidation.ValidateReplicationControllerName).Prefix("metadata")...)
allErrs = append(allErrs, ValidateJobSpec(&job.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateJobSpec(&job.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
func ValidateJobSpec(spec *extensions.JobSpec) validation.ValidationErrorList { func ValidateJobSpec(spec *extensions.JobSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if spec.Parallelism != nil { if spec.Parallelism != nil {
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(*spec.Parallelism), "parallelism")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(*spec.Parallelism), "parallelism")...)
@ -366,30 +366,30 @@ func ValidateJobSpec(spec *extensions.JobSpec) validation.ValidationErrorList {
return allErrs return allErrs
} }
func ValidateJobStatus(status *extensions.JobStatus) validation.ValidationErrorList { func ValidateJobStatus(status *extensions.JobStatus) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.Active), "active")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.Active), "active")...)
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.Succeeded), "succeeded")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.Succeeded), "succeeded")...)
allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.Failed), "failed")...) allErrs = append(allErrs, apivalidation.ValidatePositiveField(int64(status.Failed), "failed")...)
return allErrs return allErrs
} }
func ValidateJobUpdate(job, oldJob *extensions.Job) validation.ValidationErrorList { func ValidateJobUpdate(job, oldJob *extensions.Job) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&oldJob.ObjectMeta, &job.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&oldJob.ObjectMeta, &job.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateJobSpecUpdate(job.Spec, oldJob.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateJobSpecUpdate(job.Spec, oldJob.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
func ValidateJobUpdateStatus(job, oldJob *extensions.Job) validation.ValidationErrorList { func ValidateJobUpdateStatus(job, oldJob *extensions.Job) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&oldJob.ObjectMeta, &job.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&oldJob.ObjectMeta, &job.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateJobStatusUpdate(job.Status, oldJob.Status).Prefix("status")...) allErrs = append(allErrs, ValidateJobStatusUpdate(job.Status, oldJob.Status).Prefix("status")...)
return allErrs return allErrs
} }
func ValidateJobSpecUpdate(spec, oldSpec extensions.JobSpec) validation.ValidationErrorList { func ValidateJobSpecUpdate(spec, oldSpec extensions.JobSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateJobSpec(&spec)...) allErrs = append(allErrs, ValidateJobSpec(&spec)...)
allErrs = append(allErrs, apivalidation.ValidateImmutableField(spec.Completions, oldSpec.Completions, "completions")...) allErrs = append(allErrs, apivalidation.ValidateImmutableField(spec.Completions, oldSpec.Completions, "completions")...)
allErrs = append(allErrs, apivalidation.ValidateImmutableField(spec.Selector, oldSpec.Selector, "selector")...) allErrs = append(allErrs, apivalidation.ValidateImmutableField(spec.Selector, oldSpec.Selector, "selector")...)
@ -397,15 +397,15 @@ func ValidateJobSpecUpdate(spec, oldSpec extensions.JobSpec) validation.Validati
return allErrs return allErrs
} }
func ValidateJobStatusUpdate(status, oldStatus extensions.JobStatus) validation.ValidationErrorList { func ValidateJobStatusUpdate(status, oldStatus extensions.JobStatus) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, ValidateJobStatus(&status)...) allErrs = append(allErrs, ValidateJobStatus(&status)...)
return allErrs return allErrs
} }
// ValidateIngress tests if required fields in the Ingress are set. // ValidateIngress tests if required fields in the Ingress are set.
func ValidateIngress(ingress *extensions.Ingress) validation.ValidationErrorList { func ValidateIngress(ingress *extensions.Ingress) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&ingress.ObjectMeta, true, ValidateIngressName).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&ingress.ObjectMeta, true, ValidateIngressName).Prefix("metadata")...)
allErrs = append(allErrs, ValidateIngressSpec(&ingress.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateIngressSpec(&ingress.Spec).Prefix("spec")...)
return allErrs return allErrs
@ -417,8 +417,8 @@ func ValidateIngressName(name string, prefix bool) (bool, string) {
} }
// ValidateIngressSpec tests if required fields in the IngressSpec are set. // ValidateIngressSpec tests if required fields in the IngressSpec are set.
func ValidateIngressSpec(spec *extensions.IngressSpec) validation.ValidationErrorList { func ValidateIngressSpec(spec *extensions.IngressSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
// TODO: Is a default backend mandatory? // TODO: Is a default backend mandatory?
if spec.Backend != nil { if spec.Backend != nil {
allErrs = append(allErrs, validateIngressBackend(spec.Backend).Prefix("backend")...) allErrs = append(allErrs, validateIngressBackend(spec.Backend).Prefix("backend")...)
@ -432,23 +432,23 @@ func ValidateIngressSpec(spec *extensions.IngressSpec) validation.ValidationErro
} }
// ValidateIngressUpdate tests if required fields in the Ingress are set. // ValidateIngressUpdate tests if required fields in the Ingress are set.
func ValidateIngressUpdate(ingress, oldIngress *extensions.Ingress) validation.ValidationErrorList { func ValidateIngressUpdate(ingress, oldIngress *extensions.Ingress) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&ingress.ObjectMeta, &oldIngress.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&ingress.ObjectMeta, &oldIngress.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, ValidateIngressSpec(&ingress.Spec).Prefix("spec")...) allErrs = append(allErrs, ValidateIngressSpec(&ingress.Spec).Prefix("spec")...)
return allErrs return allErrs
} }
// ValidateIngressStatusUpdate tests if required fields in the Ingress are set when updating status. // ValidateIngressStatusUpdate tests if required fields in the Ingress are set when updating status.
func ValidateIngressStatusUpdate(ingress, oldIngress *extensions.Ingress) validation.ValidationErrorList { func ValidateIngressStatusUpdate(ingress, oldIngress *extensions.Ingress) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&ingress.ObjectMeta, &oldIngress.ObjectMeta).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMetaUpdate(&ingress.ObjectMeta, &oldIngress.ObjectMeta).Prefix("metadata")...)
allErrs = append(allErrs, apivalidation.ValidateLoadBalancerStatus(&ingress.Status.LoadBalancer).Prefix("status.loadBalancer")...) allErrs = append(allErrs, apivalidation.ValidateLoadBalancerStatus(&ingress.Status.LoadBalancer).Prefix("status.loadBalancer")...)
return allErrs return allErrs
} }
func validateIngressRules(IngressRules []extensions.IngressRule) validation.ValidationErrorList { func validateIngressRules(IngressRules []extensions.IngressRule) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(IngressRules) == 0 { if len(IngressRules) == 0 {
return append(allErrs, validation.NewFieldRequired("IngressRules")) return append(allErrs, validation.NewFieldRequired("IngressRules"))
} }
@ -468,16 +468,16 @@ func validateIngressRules(IngressRules []extensions.IngressRule) validation.Vali
return allErrs return allErrs
} }
func validateIngressRuleValue(ingressRule *extensions.IngressRuleValue) validation.ValidationErrorList { func validateIngressRuleValue(ingressRule *extensions.IngressRuleValue) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if ingressRule.HTTP != nil { if ingressRule.HTTP != nil {
allErrs = append(allErrs, validateHTTPIngressRuleValue(ingressRule.HTTP).Prefix("http")...) allErrs = append(allErrs, validateHTTPIngressRuleValue(ingressRule.HTTP).Prefix("http")...)
} }
return allErrs return allErrs
} }
func validateHTTPIngressRuleValue(httpIngressRuleValue *extensions.HTTPIngressRuleValue) validation.ValidationErrorList { func validateHTTPIngressRuleValue(httpIngressRuleValue *extensions.HTTPIngressRuleValue) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if len(httpIngressRuleValue.Paths) == 0 { if len(httpIngressRuleValue.Paths) == 0 {
allErrs = append(allErrs, validation.NewFieldRequired("paths")) allErrs = append(allErrs, validation.NewFieldRequired("paths"))
} }
@ -506,8 +506,8 @@ func validateHTTPIngressRuleValue(httpIngressRuleValue *extensions.HTTPIngressRu
} }
// validateIngressBackend tests if a given backend is valid. // validateIngressBackend tests if a given backend is valid.
func validateIngressBackend(backend *extensions.IngressBackend) validation.ValidationErrorList { func validateIngressBackend(backend *extensions.IngressBackend) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
// All backends must reference a single local service by name, and a single service port by name or number. // All backends must reference a single local service by name, and a single service port by name or number.
if len(backend.ServiceName) == 0 { if len(backend.ServiceName) == 0 {
@ -528,8 +528,8 @@ func validateIngressBackend(backend *extensions.IngressBackend) validation.Valid
return allErrs return allErrs
} }
func validateClusterAutoscalerSpec(spec extensions.ClusterAutoscalerSpec) validation.ValidationErrorList { func validateClusterAutoscalerSpec(spec extensions.ClusterAutoscalerSpec) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if spec.MinNodes < 0 { if spec.MinNodes < 0 {
allErrs = append(allErrs, validation.NewFieldInvalid("minNodes", spec.MinNodes, `must be non-negative`)) allErrs = append(allErrs, validation.NewFieldInvalid("minNodes", spec.MinNodes, `must be non-negative`))
} }
@ -553,8 +553,8 @@ func validateClusterAutoscalerSpec(spec extensions.ClusterAutoscalerSpec) valida
return allErrs return allErrs
} }
func ValidateClusterAutoscaler(autoscaler *extensions.ClusterAutoscaler) validation.ValidationErrorList { func ValidateClusterAutoscaler(autoscaler *extensions.ClusterAutoscaler) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if autoscaler.Name != "ClusterAutoscaler" { if autoscaler.Name != "ClusterAutoscaler" {
allErrs = append(allErrs, validation.NewFieldInvalid("name", autoscaler.Name, `name must be ClusterAutoscaler`)) allErrs = append(allErrs, validation.NewFieldInvalid("name", autoscaler.Name, `name must be ClusterAutoscaler`))
} }
@ -565,8 +565,8 @@ func ValidateClusterAutoscaler(autoscaler *extensions.ClusterAutoscaler) validat
return allErrs return allErrs
} }
func ValidatePodSelector(ps *extensions.PodSelector) validation.ValidationErrorList { func ValidatePodSelector(ps *extensions.PodSelector) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
if ps == nil { if ps == nil {
return allErrs return allErrs
} }
@ -577,8 +577,8 @@ func ValidatePodSelector(ps *extensions.PodSelector) validation.ValidationErrorL
return allErrs return allErrs
} }
func ValidatePodSelectorRequirement(sr extensions.PodSelectorRequirement) validation.ValidationErrorList { func ValidatePodSelectorRequirement(sr extensions.PodSelectorRequirement) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
switch sr.Operator { switch sr.Operator {
case extensions.PodSelectorOpIn, extensions.PodSelectorOpNotIn: case extensions.PodSelectorOpIn, extensions.PodSelectorOpNotIn:
if len(sr.Values) == 0 { if len(sr.Values) == 0 {
@ -595,8 +595,8 @@ func ValidatePodSelectorRequirement(sr extensions.PodSelectorRequirement) valida
return allErrs return allErrs
} }
func ValidateScale(scale *extensions.Scale) validation.ValidationErrorList { func ValidateScale(scale *extensions.Scale) validation.ErrorList {
allErrs := validation.ValidationErrorList{} allErrs := validation.ErrorList{}
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&scale.ObjectMeta, true, apivalidation.NameIsDNSSubdomain).Prefix("metadata")...) allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&scale.ObjectMeta, true, apivalidation.NameIsDNSSubdomain).Prefix("metadata")...)
if scale.Spec.Replicas < 0 { if scale.Spec.Replicas < 0 {

View File

@ -274,15 +274,15 @@ func TestCheckInvalidErr(t *testing.T) {
expected string expected string
}{ }{
{ {
errors.NewInvalid("Invalid1", "invalidation", validation.ValidationErrorList{validation.NewFieldInvalid("Cause", "single", "details")}), errors.NewInvalid("Invalid1", "invalidation", validation.ErrorList{validation.NewFieldInvalid("Cause", "single", "details")}),
`Error from server: Invalid1 "invalidation" is invalid: Cause: invalid value 'single', Details: details`, `Error from server: Invalid1 "invalidation" is invalid: Cause: invalid value 'single', Details: details`,
}, },
{ {
errors.NewInvalid("Invalid2", "invalidation", validation.ValidationErrorList{validation.NewFieldInvalid("Cause", "multi1", "details"), validation.NewFieldInvalid("Cause", "multi2", "details")}), errors.NewInvalid("Invalid2", "invalidation", validation.ErrorList{validation.NewFieldInvalid("Cause", "multi1", "details"), validation.NewFieldInvalid("Cause", "multi2", "details")}),
`Error from server: Invalid2 "invalidation" is invalid: [Cause: invalid value 'multi1', Details: details, Cause: invalid value 'multi2', Details: details]`, `Error from server: Invalid2 "invalidation" is invalid: [Cause: invalid value 'multi1', Details: details, Cause: invalid value 'multi2', Details: details]`,
}, },
{ {
errors.NewInvalid("Invalid3", "invalidation", validation.ValidationErrorList{}), errors.NewInvalid("Invalid3", "invalidation", validation.ErrorList{}),
`Error from server: Invalid3 "invalidation" is invalid: <nil>`, `Error from server: Invalid3 "invalidation" is invalid: <nil>`,
}, },
} }

View File

@ -76,7 +76,7 @@ func (rcStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new replication controller. // Validate validates a new replication controller.
func (rcStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (rcStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
controller := obj.(*api.ReplicationController) controller := obj.(*api.ReplicationController)
return validation.ValidateReplicationController(controller) return validation.ValidateReplicationController(controller)
} }
@ -92,7 +92,7 @@ func (rcStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (rcStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (rcStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
validationErrorList := validation.ValidateReplicationController(obj.(*api.ReplicationController)) validationErrorList := validation.ValidateReplicationController(obj.(*api.ReplicationController))
updateErrorList := validation.ValidateReplicationControllerUpdate(obj.(*api.ReplicationController), old.(*api.ReplicationController)) updateErrorList := validation.ValidateReplicationControllerUpdate(obj.(*api.ReplicationController), old.(*api.ReplicationController))
return append(validationErrorList, updateErrorList...) return append(validationErrorList, updateErrorList...)
@ -141,6 +141,6 @@ func (rcStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newRc.Spec = oldRc.Spec newRc.Spec = oldRc.Spec
} }
func (rcStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (rcStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateReplicationControllerStatusUpdate(obj.(*api.ReplicationController), old.(*api.ReplicationController)) return validation.ValidateReplicationControllerStatusUpdate(obj.(*api.ReplicationController), old.(*api.ReplicationController))
} }

View File

@ -77,7 +77,7 @@ func (daemonSetStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new daemon set. // Validate validates a new daemon set.
func (daemonSetStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (daemonSetStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
daemonSet := obj.(*extensions.DaemonSet) daemonSet := obj.(*extensions.DaemonSet)
return validation.ValidateDaemonSet(daemonSet) return validation.ValidateDaemonSet(daemonSet)
} }
@ -93,7 +93,7 @@ func (daemonSetStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (daemonSetStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (daemonSetStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
validationErrorList := validation.ValidateDaemonSet(obj.(*extensions.DaemonSet)) validationErrorList := validation.ValidateDaemonSet(obj.(*extensions.DaemonSet))
updateErrorList := validation.ValidateDaemonSetUpdate(obj.(*extensions.DaemonSet), old.(*extensions.DaemonSet)) updateErrorList := validation.ValidateDaemonSetUpdate(obj.(*extensions.DaemonSet), old.(*extensions.DaemonSet))
return append(validationErrorList, updateErrorList...) return append(validationErrorList, updateErrorList...)
@ -138,6 +138,6 @@ func (daemonSetStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newDaemonSet.Spec = oldDaemonSet.Spec newDaemonSet.Spec = oldDaemonSet.Spec
} }
func (daemonSetStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (daemonSetStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateDaemonSetStatusUpdate(obj.(*extensions.DaemonSet), old.(*extensions.DaemonSet)) return validation.ValidateDaemonSetStatusUpdate(obj.(*extensions.DaemonSet), old.(*extensions.DaemonSet))
} }

View File

@ -51,7 +51,7 @@ func (deploymentStrategy) PrepareForCreate(obj runtime.Object) {
} }
// Validate validates a new deployment. // Validate validates a new deployment.
func (deploymentStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (deploymentStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
deployment := obj.(*extensions.Deployment) deployment := obj.(*extensions.Deployment)
return validation.ValidateDeployment(deployment) return validation.ValidateDeployment(deployment)
} }
@ -73,7 +73,7 @@ func (deploymentStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (deploymentStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (deploymentStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateDeploymentUpdate(obj.(*extensions.Deployment), old.(*extensions.Deployment)) return validation.ValidateDeploymentUpdate(obj.(*extensions.Deployment), old.(*extensions.Deployment))
} }
@ -95,7 +95,7 @@ func (deploymentStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// ValidateUpdate is the default update validation for an end user updating status // ValidateUpdate is the default update validation for an end user updating status
func (deploymentStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (deploymentStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateDeploymentUpdate(obj.(*extensions.Deployment), old.(*extensions.Deployment)) return validation.ValidateDeploymentUpdate(obj.(*extensions.Deployment), old.(*extensions.Deployment))
} }

View File

@ -53,7 +53,7 @@ func (endpointsStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new endpoints. // Validate validates a new endpoints.
func (endpointsStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (endpointsStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
return validation.ValidateEndpoints(obj.(*api.Endpoints)) return validation.ValidateEndpoints(obj.(*api.Endpoints))
} }
@ -69,7 +69,7 @@ func (endpointsStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (endpointsStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (endpointsStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
errorList := validation.ValidateEndpoints(obj.(*api.Endpoints)) errorList := validation.ValidateEndpoints(obj.(*api.Endpoints))
return append(errorList, validation.ValidateEndpointsUpdate(obj.(*api.Endpoints), old.(*api.Endpoints))...) return append(errorList, validation.ValidateEndpointsUpdate(obj.(*api.Endpoints), old.(*api.Endpoints))...)
} }

View File

@ -48,7 +48,7 @@ func (eventStrategy) PrepareForCreate(obj runtime.Object) {
func (eventStrategy) PrepareForUpdate(obj, old runtime.Object) { func (eventStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
func (eventStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (eventStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
event := obj.(*api.Event) event := obj.(*api.Event)
return validation.ValidateEvent(event) return validation.ValidateEvent(event)
} }
@ -61,7 +61,7 @@ func (eventStrategy) AllowCreateOnUpdate() bool {
return true return true
} }
func (eventStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (eventStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
event := obj.(*api.Event) event := obj.(*api.Event)
return validation.ValidateEvent(event) return validation.ValidateEvent(event)
} }

View File

@ -49,10 +49,10 @@ func (t *testRESTStrategy) AllowUnconditionalUpdate() bool { return t.allowUncon
func (t *testRESTStrategy) PrepareForCreate(obj runtime.Object) {} func (t *testRESTStrategy) PrepareForCreate(obj runtime.Object) {}
func (t *testRESTStrategy) PrepareForUpdate(obj, old runtime.Object) {} func (t *testRESTStrategy) PrepareForUpdate(obj, old runtime.Object) {}
func (t *testRESTStrategy) Validate(ctx api.Context, obj runtime.Object) validation.ValidationErrorList { func (t *testRESTStrategy) Validate(ctx api.Context, obj runtime.Object) validation.ErrorList {
return nil return nil
} }
func (t *testRESTStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) validation.ValidationErrorList { func (t *testRESTStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) validation.ErrorList {
return nil return nil
} }
func (t *testRESTStrategy) Canonicalize(obj runtime.Object) {} func (t *testRESTStrategy) Canonicalize(obj runtime.Object) {}

View File

@ -53,7 +53,7 @@ func (autoscalerStrategy) PrepareForCreate(obj runtime.Object) {
} }
// Validate validates a new autoscaler. // Validate validates a new autoscaler.
func (autoscalerStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (autoscalerStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
autoscaler := obj.(*extensions.HorizontalPodAutoscaler) autoscaler := obj.(*extensions.HorizontalPodAutoscaler)
return validation.ValidateHorizontalPodAutoscaler(autoscaler) return validation.ValidateHorizontalPodAutoscaler(autoscaler)
} }
@ -76,7 +76,7 @@ func (autoscalerStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (autoscalerStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (autoscalerStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateHorizontalPodAutoscalerUpdate(obj.(*extensions.HorizontalPodAutoscaler), old.(*extensions.HorizontalPodAutoscaler)) return validation.ValidateHorizontalPodAutoscalerUpdate(obj.(*extensions.HorizontalPodAutoscaler), old.(*extensions.HorizontalPodAutoscaler))
} }
@ -115,6 +115,6 @@ func (autoscalerStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newAutoscaler.Spec = oldAutoscaler.Spec newAutoscaler.Spec = oldAutoscaler.Spec
} }
func (autoscalerStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (autoscalerStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateHorizontalPodAutoscalerStatusUpdate(obj.(*extensions.HorizontalPodAutoscaler), old.(*extensions.HorizontalPodAutoscaler)) return validation.ValidateHorizontalPodAutoscalerStatusUpdate(obj.(*extensions.HorizontalPodAutoscaler), old.(*extensions.HorizontalPodAutoscaler))
} }

View File

@ -70,7 +70,7 @@ func (ingressStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new Ingress. // Validate validates a new Ingress.
func (ingressStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (ingressStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
ingress := obj.(*extensions.Ingress) ingress := obj.(*extensions.Ingress)
err := validation.ValidateIngress(ingress) err := validation.ValidateIngress(ingress)
return err return err
@ -86,7 +86,7 @@ func (ingressStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (ingressStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (ingressStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
validationErrorList := validation.ValidateIngress(obj.(*extensions.Ingress)) validationErrorList := validation.ValidateIngress(obj.(*extensions.Ingress))
updateErrorList := validation.ValidateIngressUpdate(obj.(*extensions.Ingress), old.(*extensions.Ingress)) updateErrorList := validation.ValidateIngressUpdate(obj.(*extensions.Ingress), old.(*extensions.Ingress))
return append(validationErrorList, updateErrorList...) return append(validationErrorList, updateErrorList...)
@ -134,6 +134,6 @@ func (ingressStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// ValidateUpdate is the default update validation for an end user updating status // ValidateUpdate is the default update validation for an end user updating status
func (ingressStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (ingressStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateIngressStatusUpdate(obj.(*extensions.Ingress), old.(*extensions.Ingress)) return validation.ValidateIngressStatusUpdate(obj.(*extensions.Ingress), old.(*extensions.Ingress))
} }

View File

@ -58,7 +58,7 @@ func (jobStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new job. // Validate validates a new job.
func (jobStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (jobStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
job := obj.(*extensions.Job) job := obj.(*extensions.Job)
return validation.ValidateJob(job) return validation.ValidateJob(job)
} }
@ -77,7 +77,7 @@ func (jobStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (jobStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (jobStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
validationErrorList := validation.ValidateJob(obj.(*extensions.Job)) validationErrorList := validation.ValidateJob(obj.(*extensions.Job))
updateErrorList := validation.ValidateJobUpdate(obj.(*extensions.Job), old.(*extensions.Job)) updateErrorList := validation.ValidateJobUpdate(obj.(*extensions.Job), old.(*extensions.Job))
return append(validationErrorList, updateErrorList...) return append(validationErrorList, updateErrorList...)
@ -95,7 +95,7 @@ func (jobStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newJob.Spec = oldJob.Spec newJob.Spec = oldJob.Spec
} }
func (jobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (jobStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateJobUpdateStatus(obj.(*extensions.Job), old.(*extensions.Job)) return validation.ValidateJobUpdateStatus(obj.(*extensions.Job), old.(*extensions.Job))
} }

View File

@ -52,7 +52,7 @@ func (limitrangeStrategy) PrepareForCreate(obj runtime.Object) {
func (limitrangeStrategy) PrepareForUpdate(obj, old runtime.Object) { func (limitrangeStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
func (limitrangeStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (limitrangeStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
limitRange := obj.(*api.LimitRange) limitRange := obj.(*api.LimitRange)
return validation.ValidateLimitRange(limitRange) return validation.ValidateLimitRange(limitRange)
} }
@ -65,7 +65,7 @@ func (limitrangeStrategy) AllowCreateOnUpdate() bool {
return true return true
} }
func (limitrangeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (limitrangeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
limitRange := obj.(*api.LimitRange) limitRange := obj.(*api.LimitRange)
return validation.ValidateLimitRange(limitRange) return validation.ValidateLimitRange(limitRange)
} }

View File

@ -77,7 +77,7 @@ func (namespaceStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new namespace. // Validate validates a new namespace.
func (namespaceStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (namespaceStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
namespace := obj.(*api.Namespace) namespace := obj.(*api.Namespace)
return validation.ValidateNamespace(namespace) return validation.ValidateNamespace(namespace)
} }
@ -92,7 +92,7 @@ func (namespaceStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (namespaceStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (namespaceStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
errorList := validation.ValidateNamespace(obj.(*api.Namespace)) errorList := validation.ValidateNamespace(obj.(*api.Namespace))
return append(errorList, validation.ValidateNamespaceUpdate(obj.(*api.Namespace), old.(*api.Namespace))...) return append(errorList, validation.ValidateNamespaceUpdate(obj.(*api.Namespace), old.(*api.Namespace))...)
} }
@ -113,7 +113,7 @@ func (namespaceStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newNamespace.Spec = oldNamespace.Spec newNamespace.Spec = oldNamespace.Spec
} }
func (namespaceStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (namespaceStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateNamespaceStatusUpdate(obj.(*api.Namespace), old.(*api.Namespace)) return validation.ValidateNamespaceStatusUpdate(obj.(*api.Namespace), old.(*api.Namespace))
} }
@ -123,7 +123,7 @@ type namespaceFinalizeStrategy struct {
var FinalizeStrategy = namespaceFinalizeStrategy{Strategy} var FinalizeStrategy = namespaceFinalizeStrategy{Strategy}
func (namespaceFinalizeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (namespaceFinalizeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateNamespaceFinalizeUpdate(obj.(*api.Namespace), old.(*api.Namespace)) return validation.ValidateNamespaceFinalizeUpdate(obj.(*api.Namespace), old.(*api.Namespace))
} }

View File

@ -71,7 +71,7 @@ func (nodeStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new node. // Validate validates a new node.
func (nodeStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (nodeStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
node := obj.(*api.Node) node := obj.(*api.Node)
return validation.ValidateNode(node) return validation.ValidateNode(node)
} }
@ -81,7 +81,7 @@ func (nodeStrategy) Canonicalize(obj runtime.Object) {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (nodeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (nodeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
errorList := validation.ValidateNode(obj.(*api.Node)) errorList := validation.ValidateNode(obj.(*api.Node))
return append(errorList, validation.ValidateNodeUpdate(obj.(*api.Node), old.(*api.Node))...) return append(errorList, validation.ValidateNodeUpdate(obj.(*api.Node), old.(*api.Node))...)
} }
@ -107,7 +107,7 @@ func (nodeStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newNode.Spec = oldNode.Spec newNode.Spec = oldNode.Spec
} }
func (nodeStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (nodeStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateNodeUpdate(obj.(*api.Node), old.(*api.Node)) return validation.ValidateNodeUpdate(obj.(*api.Node), old.(*api.Node))
} }

View File

@ -48,7 +48,7 @@ func (persistentvolumeStrategy) PrepareForCreate(obj runtime.Object) {
pv.Status = api.PersistentVolumeStatus{} pv.Status = api.PersistentVolumeStatus{}
} }
func (persistentvolumeStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (persistentvolumeStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
persistentvolume := obj.(*api.PersistentVolume) persistentvolume := obj.(*api.PersistentVolume)
return validation.ValidatePersistentVolume(persistentvolume) return validation.ValidatePersistentVolume(persistentvolume)
} }
@ -68,7 +68,7 @@ func (persistentvolumeStrategy) PrepareForUpdate(obj, old runtime.Object) {
newPv.Status = oldPv.Status newPv.Status = oldPv.Status
} }
func (persistentvolumeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (persistentvolumeStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
errorList := validation.ValidatePersistentVolume(obj.(*api.PersistentVolume)) errorList := validation.ValidatePersistentVolume(obj.(*api.PersistentVolume))
return append(errorList, validation.ValidatePersistentVolumeUpdate(obj.(*api.PersistentVolume), old.(*api.PersistentVolume))...) return append(errorList, validation.ValidatePersistentVolumeUpdate(obj.(*api.PersistentVolume), old.(*api.PersistentVolume))...)
} }
@ -90,7 +90,7 @@ func (persistentvolumeStatusStrategy) PrepareForUpdate(obj, old runtime.Object)
newPv.Spec = oldPv.Spec newPv.Spec = oldPv.Spec
} }
func (persistentvolumeStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (persistentvolumeStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidatePersistentVolumeStatusUpdate(obj.(*api.PersistentVolume), old.(*api.PersistentVolume)) return validation.ValidatePersistentVolumeStatusUpdate(obj.(*api.PersistentVolume), old.(*api.PersistentVolume))
} }

View File

@ -48,7 +48,7 @@ func (persistentvolumeclaimStrategy) PrepareForCreate(obj runtime.Object) {
pv.Status = api.PersistentVolumeClaimStatus{} pv.Status = api.PersistentVolumeClaimStatus{}
} }
func (persistentvolumeclaimStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (persistentvolumeclaimStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
pvc := obj.(*api.PersistentVolumeClaim) pvc := obj.(*api.PersistentVolumeClaim)
return validation.ValidatePersistentVolumeClaim(pvc) return validation.ValidatePersistentVolumeClaim(pvc)
} }
@ -68,7 +68,7 @@ func (persistentvolumeclaimStrategy) PrepareForUpdate(obj, old runtime.Object) {
newPvc.Status = oldPvc.Status newPvc.Status = oldPvc.Status
} }
func (persistentvolumeclaimStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (persistentvolumeclaimStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
errorList := validation.ValidatePersistentVolumeClaim(obj.(*api.PersistentVolumeClaim)) errorList := validation.ValidatePersistentVolumeClaim(obj.(*api.PersistentVolumeClaim))
return append(errorList, validation.ValidatePersistentVolumeClaimUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))...) return append(errorList, validation.ValidatePersistentVolumeClaimUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))...)
} }
@ -90,7 +90,7 @@ func (persistentvolumeclaimStatusStrategy) PrepareForUpdate(obj, old runtime.Obj
newPv.Spec = oldPv.Spec newPv.Spec = oldPv.Spec
} }
func (persistentvolumeclaimStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (persistentvolumeclaimStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidatePersistentVolumeClaimStatusUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim)) return validation.ValidatePersistentVolumeClaimStatusUpdate(obj.(*api.PersistentVolumeClaim), old.(*api.PersistentVolumeClaim))
} }

View File

@ -129,10 +129,10 @@ func (r *BindingREST) Create(ctx api.Context, obj runtime.Object) (out runtime.O
binding := obj.(*api.Binding) binding := obj.(*api.Binding)
// TODO: move me to a binding strategy // TODO: move me to a binding strategy
if len(binding.Target.Kind) != 0 && binding.Target.Kind != "Node" { if len(binding.Target.Kind) != 0 && binding.Target.Kind != "Node" {
return nil, errors.NewInvalid("binding", binding.Name, validation.ValidationErrorList{validation.NewFieldInvalid("to.kind", binding.Target.Kind, "must be empty or 'Node'")}) return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewFieldInvalid("to.kind", binding.Target.Kind, "must be empty or 'Node'")})
} }
if len(binding.Target.Name) == 0 { if len(binding.Target.Name) == 0 {
return nil, errors.NewInvalid("binding", binding.Name, validation.ValidationErrorList{validation.NewFieldRequired("to.name")}) return nil, errors.NewInvalid("binding", binding.Name, validation.ErrorList{validation.NewFieldRequired("to.name")})
} }
err = r.assignPod(ctx, binding.Name, binding.Target.Name, binding.Annotations) err = r.assignPod(ctx, binding.Name, binding.Target.Name, binding.Annotations)
out = &unversioned.Status{Status: unversioned.StatusSuccess} out = &unversioned.Status{Status: unversioned.StatusSuccess}

View File

@ -67,7 +67,7 @@ func (podStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new pod. // Validate validates a new pod.
func (podStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (podStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
pod := obj.(*api.Pod) pod := obj.(*api.Pod)
return validation.ValidatePod(pod) return validation.ValidatePod(pod)
} }
@ -82,7 +82,7 @@ func (podStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (podStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (podStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
errorList := validation.ValidatePod(obj.(*api.Pod)) errorList := validation.ValidatePod(obj.(*api.Pod))
return append(errorList, validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod))...) return append(errorList, validation.ValidatePodUpdate(obj.(*api.Pod), old.(*api.Pod))...)
} }
@ -147,7 +147,7 @@ func (podStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newPod.DeletionTimestamp = nil newPod.DeletionTimestamp = nil
} }
func (podStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (podStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
// TODO: merge valid fields after update // TODO: merge valid fields after update
return validation.ValidatePodStatusUpdate(obj.(*api.Pod), old.(*api.Pod)) return validation.ValidatePodStatusUpdate(obj.(*api.Pod), old.(*api.Pod))
} }

View File

@ -49,7 +49,7 @@ func (podTemplateStrategy) PrepareForCreate(obj runtime.Object) {
} }
// Validate validates a new pod template. // Validate validates a new pod template.
func (podTemplateStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (podTemplateStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
pod := obj.(*api.PodTemplate) pod := obj.(*api.PodTemplate)
return validation.ValidatePodTemplate(pod) return validation.ValidatePodTemplate(pod)
} }
@ -69,7 +69,7 @@ func (podTemplateStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (podTemplateStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (podTemplateStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidatePodTemplateUpdate(obj.(*api.PodTemplate), old.(*api.PodTemplate)) return validation.ValidatePodTemplateUpdate(obj.(*api.PodTemplate), old.(*api.PodTemplate))
} }

View File

@ -57,7 +57,7 @@ func (resourcequotaStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new resourcequota. // Validate validates a new resourcequota.
func (resourcequotaStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (resourcequotaStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
resourcequota := obj.(*api.ResourceQuota) resourcequota := obj.(*api.ResourceQuota)
return validation.ValidateResourceQuota(resourcequota) return validation.ValidateResourceQuota(resourcequota)
} }
@ -72,7 +72,7 @@ func (resourcequotaStrategy) AllowCreateOnUpdate() bool {
} }
// ValidateUpdate is the default update validation for an end user. // ValidateUpdate is the default update validation for an end user.
func (resourcequotaStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (resourcequotaStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
errorList := validation.ValidateResourceQuota(obj.(*api.ResourceQuota)) errorList := validation.ValidateResourceQuota(obj.(*api.ResourceQuota))
return append(errorList, validation.ValidateResourceQuotaUpdate(obj.(*api.ResourceQuota), old.(*api.ResourceQuota))...) return append(errorList, validation.ValidateResourceQuotaUpdate(obj.(*api.ResourceQuota), old.(*api.ResourceQuota))...)
} }
@ -93,7 +93,7 @@ func (resourcequotaStatusStrategy) PrepareForUpdate(obj, old runtime.Object) {
newResourcequota.Spec = oldResourcequota.Spec newResourcequota.Spec = oldResourcequota.Spec
} }
func (resourcequotaStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (resourcequotaStatusStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateResourceQuotaStatusUpdate(obj.(*api.ResourceQuota), old.(*api.ResourceQuota)) return validation.ValidateResourceQuotaStatusUpdate(obj.(*api.ResourceQuota), old.(*api.ResourceQuota))
} }

View File

@ -50,7 +50,7 @@ func (strategy) NamespaceScoped() bool {
func (strategy) PrepareForCreate(obj runtime.Object) { func (strategy) PrepareForCreate(obj runtime.Object) {
} }
func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
return validation.ValidateSecret(obj.(*api.Secret)) return validation.ValidateSecret(obj.(*api.Secret))
} }
@ -64,7 +64,7 @@ func (strategy) AllowCreateOnUpdate() bool {
func (strategy) PrepareForUpdate(obj, old runtime.Object) { func (strategy) PrepareForUpdate(obj, old runtime.Object) {
} }
func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateSecretUpdate(obj.(*api.Secret), old.(*api.Secret)) return validation.ValidateSecretUpdate(obj.(*api.Secret), old.(*api.Secret))
} }

View File

@ -84,7 +84,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
// Allocate next available. // Allocate next available.
ip, err := rs.serviceIPs.AllocateNext() ip, err := rs.serviceIPs.AllocateNext()
if err != nil { if err != nil {
el := utilvalidation.ValidationErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())} el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
return nil, errors.NewInvalid("Service", service.Name, el) return nil, errors.NewInvalid("Service", service.Name, el)
} }
service.Spec.ClusterIP = ip.String() service.Spec.ClusterIP = ip.String()
@ -92,7 +92,7 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
} else if api.IsServiceIPSet(service) { } else if api.IsServiceIPSet(service) {
// Try to respect the requested IP. // Try to respect the requested IP.
if err := rs.serviceIPs.Allocate(net.ParseIP(service.Spec.ClusterIP)); err != nil { if err := rs.serviceIPs.Allocate(net.ParseIP(service.Spec.ClusterIP)); err != nil {
el := utilvalidation.ValidationErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())} el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, err.Error())}
return nil, errors.NewInvalid("Service", service.Name, el) return nil, errors.NewInvalid("Service", service.Name, el)
} }
releaseServiceIP = true releaseServiceIP = true
@ -104,13 +104,13 @@ func (rs *REST) Create(ctx api.Context, obj runtime.Object) (runtime.Object, err
if servicePort.NodePort != 0 { if servicePort.NodePort != 0 {
err := nodePortOp.Allocate(servicePort.NodePort) err := nodePortOp.Allocate(servicePort.NodePort)
if err != nil { if err != nil {
el := utilvalidation.ValidationErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports") el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, errors.NewInvalid("Service", service.Name, el) return nil, errors.NewInvalid("Service", service.Name, el)
} }
} else if assignNodePorts { } else if assignNodePorts {
nodePort, err := nodePortOp.AllocateNext() nodePort, err := nodePortOp.AllocateNext()
if err != nil { if err != nil {
el := utilvalidation.ValidationErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports") el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", servicePort.NodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, errors.NewInvalid("Service", service.Name, el) return nil, errors.NewInvalid("Service", service.Name, el)
} }
servicePort.NodePort = nodePort servicePort.NodePort = nodePort
@ -223,14 +223,14 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
if !contains(oldNodePorts, nodePort) { if !contains(oldNodePorts, nodePort) {
err := nodePortOp.Allocate(nodePort) err := nodePortOp.Allocate(nodePort)
if err != nil { if err != nil {
el := utilvalidation.ValidationErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports") el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, false, errors.NewInvalid("Service", service.Name, el) return nil, false, errors.NewInvalid("Service", service.Name, el)
} }
} }
} else { } else {
nodePort, err = nodePortOp.AllocateNext() nodePort, err = nodePortOp.AllocateNext()
if err != nil { if err != nil {
el := utilvalidation.ValidationErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports") el := utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("nodePort", nodePort, err.Error())}.PrefixIndex(i).Prefix("spec.ports")
return nil, false, errors.NewInvalid("Service", service.Name, el) return nil, false, errors.NewInvalid("Service", service.Name, el)
} }
servicePort.NodePort = nodePort servicePort.NodePort = nodePort

View File

@ -58,7 +58,7 @@ func (svcStrategy) PrepareForUpdate(obj, old runtime.Object) {
} }
// Validate validates a new service. // Validate validates a new service.
func (svcStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (svcStrategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
service := obj.(*api.Service) service := obj.(*api.Service)
return validation.ValidateService(service) return validation.ValidateService(service)
} }
@ -71,7 +71,7 @@ func (svcStrategy) AllowCreateOnUpdate() bool {
return true return true
} }
func (svcStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (svcStrategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateServiceUpdate(obj.(*api.Service), old.(*api.Service)) return validation.ValidateServiceUpdate(obj.(*api.Service), old.(*api.Service))
} }

View File

@ -46,7 +46,7 @@ func (strategy) PrepareForCreate(obj runtime.Object) {
cleanSecretReferences(obj.(*api.ServiceAccount)) cleanSecretReferences(obj.(*api.ServiceAccount))
} }
func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
return validation.ValidateServiceAccount(obj.(*api.ServiceAccount)) return validation.ValidateServiceAccount(obj.(*api.ServiceAccount))
} }
@ -68,7 +68,7 @@ func cleanSecretReferences(serviceAccount *api.ServiceAccount) {
} }
} }
func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateServiceAccountUpdate(obj.(*api.ServiceAccount), old.(*api.ServiceAccount)) return validation.ValidateServiceAccountUpdate(obj.(*api.ServiceAccount), old.(*api.ServiceAccount))
} }

View File

@ -51,7 +51,7 @@ func (strategy) NamespaceScoped() bool {
func (strategy) PrepareForCreate(obj runtime.Object) { func (strategy) PrepareForCreate(obj runtime.Object) {
} }
func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
return validation.ValidateThirdPartyResource(obj.(*extensions.ThirdPartyResource)) return validation.ValidateThirdPartyResource(obj.(*extensions.ThirdPartyResource))
} }
@ -66,7 +66,7 @@ func (strategy) AllowCreateOnUpdate() bool {
func (strategy) PrepareForUpdate(obj, old runtime.Object) { func (strategy) PrepareForUpdate(obj, old runtime.Object) {
} }
func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateThirdPartyResourceUpdate(obj.(*extensions.ThirdPartyResource), old.(*extensions.ThirdPartyResource)) return validation.ValidateThirdPartyResourceUpdate(obj.(*extensions.ThirdPartyResource), old.(*extensions.ThirdPartyResource))
} }

View File

@ -51,7 +51,7 @@ func (strategy) NamespaceScoped() bool {
func (strategy) PrepareForCreate(obj runtime.Object) { func (strategy) PrepareForCreate(obj runtime.Object) {
} }
func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ValidationErrorList { func (strategy) Validate(ctx api.Context, obj runtime.Object) utilvalidation.ErrorList {
return validation.ValidateThirdPartyResourceData(obj.(*extensions.ThirdPartyResourceData)) return validation.ValidateThirdPartyResourceData(obj.(*extensions.ThirdPartyResourceData))
} }
@ -66,7 +66,7 @@ func (strategy) AllowCreateOnUpdate() bool {
func (strategy) PrepareForUpdate(obj, old runtime.Object) { func (strategy) PrepareForUpdate(obj, old runtime.Object) {
} }
func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ValidationErrorList { func (strategy) ValidateUpdate(ctx api.Context, obj, old runtime.Object) utilvalidation.ErrorList {
return validation.ValidateThirdPartyResourceDataUpdate(obj.(*extensions.ThirdPartyResourceData), old.(*extensions.ThirdPartyResourceData)) return validation.ValidateThirdPartyResourceDataUpdate(obj.(*extensions.ThirdPartyResourceData), old.(*extensions.ThirdPartyResourceData))
} }

View File

@ -47,8 +47,8 @@ func ParseWatchResourceVersion(resourceVersion, kind string) (uint64, error) {
} }
version, err := strconv.ParseUint(resourceVersion, 10, 64) version, err := strconv.ParseUint(resourceVersion, 10, 64)
if err != nil { if err != nil {
// TODO: Does this need to be a ValidationErrorList? I can't convince myself it does. // TODO: Does this need to be a ErrorList? I can't convince myself it does.
return 0, errors.NewInvalid(kind, "", utilvalidation.ValidationErrorList{utilvalidation.NewFieldInvalid("resourceVersion", resourceVersion, err.Error())}) return 0, errors.NewInvalid(kind, "", utilvalidation.ErrorList{utilvalidation.NewFieldInvalid("resourceVersion", resourceVersion, err.Error())})
} }
return version + 1, nil return version + 1, nil
} }

View File

@ -144,11 +144,11 @@ func NewFieldTooLong(field string, value interface{}, maxLength int) *Error {
return &Error{ErrorTypeTooLong, field, value, fmt.Sprintf("must have at most %d characters", maxLength)} return &Error{ErrorTypeTooLong, field, value, fmt.Sprintf("must have at most %d characters", maxLength)}
} }
type ValidationErrorList []error type ErrorList []error
// Prefix adds a prefix to the Field of every Error in the list. // Prefix adds a prefix to the Field of every Error in the list.
// Returns the list for convenience. // Returns the list for convenience.
func (list ValidationErrorList) Prefix(prefix string) ValidationErrorList { func (list ErrorList) Prefix(prefix string) ErrorList {
for i := range list { for i := range list {
if err, ok := list[i].(*Error); ok { if err, ok := list[i].(*Error); ok {
if strings.HasPrefix(err.Field, "[") { if strings.HasPrefix(err.Field, "[") {
@ -160,7 +160,7 @@ func (list ValidationErrorList) Prefix(prefix string) ValidationErrorList {
} }
list[i] = err list[i] = err
} else { } else {
panic(fmt.Sprintf("Programmer error: ValidationErrorList holds non-Error: %#v", list[i])) panic(fmt.Sprintf("Programmer error: ErrorList holds non-Error: %#v", list[i]))
} }
} }
return list return list
@ -168,7 +168,7 @@ func (list ValidationErrorList) Prefix(prefix string) ValidationErrorList {
// PrefixIndex adds an index to the Field of every Error in the list. // PrefixIndex adds an index to the Field of every Error in the list.
// Returns the list for convenience. // Returns the list for convenience.
func (list ValidationErrorList) PrefixIndex(index int) ValidationErrorList { func (list ErrorList) PrefixIndex(index int) ErrorList {
return list.Prefix(fmt.Sprintf("[%d]", index)) return list.Prefix(fmt.Sprintf("[%d]", index))
} }
@ -195,13 +195,13 @@ func NewValidationErrorFieldPrefixMatcher(prefix string) utilerrors.Matcher {
} }
} }
// Filter removes items from the ValidationErrorList that match the provided fns. // Filter removes items from the ErrorList that match the provided fns.
func (list ValidationErrorList) Filter(fns ...utilerrors.Matcher) ValidationErrorList { func (list ErrorList) Filter(fns ...utilerrors.Matcher) ErrorList {
err := utilerrors.FilterOut(utilerrors.NewAggregate(list), fns...) err := utilerrors.FilterOut(utilerrors.NewAggregate(list), fns...)
if err == nil { if err == nil {
return nil return nil
} }
// FilterOut that takes an Aggregate returns an Aggregate // FilterOut that takes an Aggregate returns an Aggregate
agg := err.(utilerrors.Aggregate) agg := err.(utilerrors.Aggregate)
return ValidationErrorList(agg.Errors()) return ErrorList(agg.Errors())
} }

View File

@ -94,7 +94,7 @@ func TestErrorUsefulMessage(t *testing.T) {
} }
func TestErrListFilter(t *testing.T) { func TestErrListFilter(t *testing.T) {
list := ValidationErrorList{ list := ErrorList{
NewFieldInvalid("test.field", "", ""), NewFieldInvalid("test.field", "", ""),
NewFieldInvalid("field.test", "", ""), NewFieldInvalid("field.test", "", ""),
NewFieldDuplicate("test", "value"), NewFieldDuplicate("test", "value"),
@ -138,7 +138,7 @@ func TestErrListPrefix(t *testing.T) {
}, },
} }
for _, testCase := range testCases { for _, testCase := range testCases {
errList := ValidationErrorList{testCase.Err} errList := ErrorList{testCase.Err}
prefix := errList.Prefix("foo") prefix := errList.Prefix("foo")
if prefix == nil || len(prefix) != len(errList) { if prefix == nil || len(prefix) != len(errList) {
t.Errorf("Prefix should return self") t.Errorf("Prefix should return self")
@ -168,7 +168,7 @@ func TestErrListPrefixIndex(t *testing.T) {
}, },
} }
for _, testCase := range testCases { for _, testCase := range testCases {
errList := ValidationErrorList{testCase.Err} errList := ErrorList{testCase.Err}
prefix := errList.PrefixIndex(1) prefix := errList.PrefixIndex(1)
if prefix == nil || len(prefix) != len(errList) { if prefix == nil || len(prefix) != len(errList) {
t.Errorf("PrefixIndex should return self") t.Errorf("PrefixIndex should return self")