diff --git a/pkg/webhook/v1beta1/experiment/validator/validator.go b/pkg/webhook/v1beta1/experiment/validator/validator.go index 9f0f1c3ff5b..27ad4e33568 100644 --- a/pkg/webhook/v1beta1/experiment/validator/validator.go +++ b/pkg/webhook/v1beta1/experiment/validator/validator.go @@ -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)) } diff --git a/pkg/webhook/v1beta1/experiment/validator/validator_test.go b/pkg/webhook/v1beta1/experiment/validator/validator_test.go index c815b799d74..b8d51548a61 100644 --- a/pkg/webhook/v1beta1/experiment/validator/validator_test.go +++ b/pkg/webhook/v1beta1/experiment/validator/validator_test.go @@ -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 {