Skip to content

Commit

Permalink
Set experiment names at a max of 40 characters. If len(algorithm) + l…
Browse files Browse the repository at this point in the history
…en(experiment-name) > 63, then the suggestion service cannot start.

Signed-off-by: Aydan Pirani <aydanpirani@gmail.com>
  • Loading branch information
AydanPirani committed Dec 21, 2024
1 parent 3363964 commit 5aa332d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/webhook/v1beta1/experiment/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ func (g *DefaultValidator) ValidateExperiment(instance, oldInst *experimentsv1be
var allErrs field.ErrorList

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

allErrs = append(allErrs, field.Invalid(field.NewPath("metadata").Child("name"), instance.Name, msg))
}
Expand Down
11 changes: 11 additions & 0 deletions pkg/webhook/v1beta1/experiment/validator/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ func TestValidateExperiment(t *testing.T) {
},
testDescription: "Name is invalid",
},
{
instance: func() *experimentsv1beta1.Experiment {
i := newFakeInstance()
i.Name = "test-manymanymanyextracharactersthatgobeyondlimit"
return i
}(),
wantErr: field.ErrorList{
field.Invalid(field.NewPath("metadata").Child("name"), "", ""),
},
testDescription: "Name is invalid",
},
// Objective
{
instance: func() *experimentsv1beta1.Experiment {
Expand Down

0 comments on commit 5aa332d

Please sign in to comment.