Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit 086bcb2

Browse files
pmoriearschles
authored andcommitted
Allow underscores in plan names (#610)
1 parent cd9d573 commit 086bcb2

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

pkg/apis/servicecatalog/validation/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func validateInstanceSpec(spec *sc.InstanceSpec, fldPath *field.Path, create boo
5555
allErrs = append(allErrs, field.Required(fldPath.Child("planName"), "planName is required"))
5656
}
5757

58-
for _, msg := range validateServicePlanName(spec.PlanName, false /* prefix */) {
58+
for _, msg := range validateServicePlanName(spec.PlanName) {
5959
allErrs = append(allErrs, field.Invalid(fldPath.Child("planName"), spec.PlanName, msg))
6060
}
6161

pkg/apis/servicecatalog/validation/serviceclass.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ import (
3030
// validateServiceClassName is the validation function for ServiceClass names.
3131
var 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 {
9693
func 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.
116131
func ValidateServiceClassUpdate(new *sc.ServiceClass, old *sc.ServiceClass) field.ErrorList {

pkg/apis/servicecatalog/validation/serviceclass_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ func TestValidateServiceClass(t *testing.T) {
4848
},
4949
valid: true,
5050
},
51+
{
52+
name: "valid serviceClass - plan with underscore in name",
53+
serviceClass: &servicecatalog.ServiceClass{
54+
ObjectMeta: kapi.ObjectMeta{
55+
Name: "test-serviceclass",
56+
},
57+
Bindable: true,
58+
BrokerName: "test-broker",
59+
OSBGUID: "1234-4354a-49b",
60+
Plans: []servicecatalog.ServicePlan{
61+
{
62+
Name: "test_plan",
63+
OSBGUID: "40d-0983-1b89",
64+
},
65+
},
66+
},
67+
valid: true,
68+
},
5169
{
5270
name: "valid serviceClass - uppercase in GUID",
5371
serviceClass: &servicecatalog.ServiceClass{

0 commit comments

Comments
 (0)