Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set experiment names at a max of 40 characters. #2468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. "
Comment on lines +88 to +89
Copy link
Member

@Electronic-Waste Electronic-Waste Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" (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. "
" (e.g. 'my-name', or 'abc-123', regex used for validation is '^[a-z]([-a-z0-9]*[a-z0-9])?)')," +
" and may not be longer 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