From b6be9b9684bcce5220da5548f63cf6af86d46ae8 Mon Sep 17 00:00:00 2001 From: mqliang Date: Mon, 12 Oct 2015 11:26:17 +0800 Subject: [PATCH] use string constant instead of duplicating --- pkg/api/validation/validation.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/pkg/api/validation/validation.go b/pkg/api/validation/validation.go index e6e8759ddd5..c778d85f3eb 100644 --- a/pkg/api/validation/validation.go +++ b/pkg/api/validation/validation.go @@ -45,6 +45,7 @@ var RepairMalformedUpdates bool = true const cIdentifierErrorMsg string = `must be a C identifier (matching regex ` + validation.CIdentifierFmt + `): e.g. "my_name" or "MyName"` const isNegativeErrorMsg string = `must be non-negative` const isNotIntegerErrorMsg string = `must be an integer` +const fieldImmutableErrorMsg string = `field is immutable` func intervalErrorMsg(lo, hi int) string { return fmt.Sprintf(`must be greater than %d and less than %d`, lo, hi) @@ -315,16 +316,16 @@ func ValidateObjectMetaUpdate(new, old *api.ObjectMeta) errs.ValidationErrorList } if old.Name != new.Name { - allErrs = append(allErrs, errs.NewFieldInvalid("name", new.Name, "field is immutable")) + allErrs = append(allErrs, errs.NewFieldInvalid("name", new.Name, fieldImmutableErrorMsg)) } if old.Namespace != new.Namespace { - allErrs = append(allErrs, errs.NewFieldInvalid("namespace", new.Namespace, "field is immutable")) + allErrs = append(allErrs, errs.NewFieldInvalid("namespace", new.Namespace, fieldImmutableErrorMsg)) } if old.UID != new.UID { - allErrs = append(allErrs, errs.NewFieldInvalid("uid", new.UID, "field is immutable")) + allErrs = append(allErrs, errs.NewFieldInvalid("uid", new.UID, fieldImmutableErrorMsg)) } if old.CreationTimestamp != new.CreationTimestamp { - allErrs = append(allErrs, errs.NewFieldInvalid("creationTimestamp", new.CreationTimestamp, "field is immutable")) + allErrs = append(allErrs, errs.NewFieldInvalid("creationTimestamp", new.CreationTimestamp, fieldImmutableErrorMsg)) } allErrs = append(allErrs, ValidateLabels(new.Labels, "labels")...) @@ -1344,7 +1345,7 @@ func ValidateServiceUpdate(oldService, service *api.Service) errs.ValidationErro allErrs = append(allErrs, ValidateObjectMetaUpdate(&service.ObjectMeta, &oldService.ObjectMeta).Prefix("metadata")...) if api.IsServiceIPSet(oldService) && service.Spec.ClusterIP != oldService.Spec.ClusterIP { - allErrs = append(allErrs, errs.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, "field is immutable")) + allErrs = append(allErrs, errs.NewFieldInvalid("spec.clusterIP", service.Spec.ClusterIP, fieldImmutableErrorMsg)) } allErrs = append(allErrs, ValidateService(service)...) @@ -1710,7 +1711,7 @@ func ValidateSecretUpdate(oldSecret, newSecret *api.Secret) errs.ValidationError newSecret.Type = oldSecret.Type } if newSecret.Type != oldSecret.Type { - allErrs = append(allErrs, errs.NewFieldInvalid("type", newSecret.Type, "field is immutable")) + allErrs = append(allErrs, errs.NewFieldInvalid("type", newSecret.Type, fieldImmutableErrorMsg)) } allErrs = append(allErrs, ValidateSecret(newSecret)...)