Skip to content

Commit 4d2a230

Browse files
authored
Set experiment names at a max of 40 characters. (#2468)
Signed-off-by: Aydan Pirani <[email protected]>
1 parent 3e736dc commit 4d2a230

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/webhook/v1beta1/experiment/validator/validator.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ func (g *DefaultValidator) ValidateExperiment(instance, oldInst *experimentsv1be
8282
var allErrs field.ErrorList
8383

8484
namingConvention, _ := regexp.Compile("^[a-z]([-a-z0-9]*[a-z0-9])?")
85-
if !namingConvention.MatchString(instance.Name) {
85+
if !namingConvention.MatchString(instance.Name) || len(instance.Name) > 40 {
8686
msg := "name must consist of lower case alphanumeric characters or '-'," +
8787
" start with an alphabetic character, and end with an alphanumeric character" +
88-
" (e.g. 'my-name', or 'abc-123', regex used for validation is '^[a-z]([-a-z0-9]*[a-z0-9])?)'"
88+
" (e.g. 'my-name', or 'abc-123', regex used for validation is '^[a-z]([-a-z0-9]*[a-z0-9])?)'" +
89+
" and may not be larger than 40 characters. "
8990

9091
allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), instance.Name, msg))
9192
}

pkg/webhook/v1beta1/experiment/validator/validator_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@ func TestValidateExperiment(t *testing.T) {
8686
},
8787
testDescription: "Name is invalid",
8888
},
89+
{
90+
instance: func() *experimentsv1beta1.Experiment {
91+
i := newFakeInstance()
92+
i.Name = "test-manymanymanyextracharactersthatgobeyondlimit"
93+
return i
94+
}(),
95+
wantErr: field.ErrorList{
96+
field.Invalid(field.NewPath("metadata").Child("name"), "", ""),
97+
},
98+
testDescription: "Name is invalid",
99+
},
89100
// Objective
90101
{
91102
instance: func() *experimentsv1beta1.Experiment {

0 commit comments

Comments
 (0)