@@ -30,9 +30,6 @@ import (
3030// validateServiceClassName is the validation function for ServiceClass names.
3131var validateServiceClassName = apivalidation .NameIsDNSSubdomain
3232
33- // validateServicePlanName is the validation function for ServicePlan names.
34- var validateServicePlanName = apivalidation .NameIsDNSLabel
35-
3633// validateOSBGuid is the validation function for OSB GUIDs. We generate
3734// GUIDs for Instances and Bindings, but for ServiceClass and ServicePlan,
3835// they are part of the payload returned from the Broker.
@@ -96,7 +93,7 @@ func ValidateServiceClass(serviceclass *sc.ServiceClass) field.ErrorList {
9693func validateServicePlan (plan sc.ServicePlan , fldPath * field.Path ) field.ErrorList {
9794 allErrs := field.ErrorList {}
9895
99- for _ , msg := range validateServicePlanName (plan .Name , false /* prefix */ ) {
96+ for _ , msg := range validateServicePlanName (plan .Name ) {
10097 allErrs = append (allErrs , field .Invalid (fldPath .Child ("name" ), plan .Name , msg ))
10198 }
10299
@@ -111,6 +108,24 @@ func validateServicePlan(plan sc.ServicePlan, fldPath *field.Path) field.ErrorLi
111108 return allErrs
112109}
113110
111+ const servicePlanNameFmt string = `[-_a-z0-9]+`
112+ const servicePlanNameMaxLength int = 63
113+
114+ var servicePlanNameRegexp = regexp .MustCompile ("^" + servicePlanNameFmt + "$" )
115+
116+ // validateServicePlanName is the validation function for ServicePlan names.
117+ func validateServicePlanName (value string ) []string {
118+ var errs []string
119+ if len (value ) > servicePlanNameMaxLength {
120+ errs = append (errs , utilvalidation .MaxLenError (servicePlanNameMaxLength ))
121+ }
122+ if ! servicePlanNameRegexp .MatchString (value ) {
123+ errs = append (errs , utilvalidation .RegexError (servicePlanNameFmt , "plan-name" , "plan_name" ))
124+ }
125+
126+ return errs
127+ }
128+
114129// ValidateServiceClassUpdate checks that when changing from an older
115130// ServiceClass to a newer ServiceClass is okay.
116131func ValidateServiceClassUpdate (new * sc.ServiceClass , old * sc.ServiceClass ) field.ErrorList {
0 commit comments