File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
pkg/webhook/v1beta1/experiment/validator Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,15 @@ func (g *DefaultValidator) InjectClient(c client.Client) {
67
67
// ValidateExperiment validates experiment for the given instance.
68
68
// oldInst is specified when experiment is edited.
69
69
func (g * DefaultValidator ) ValidateExperiment (instance , oldInst * experimentsv1beta1.Experiment ) error {
70
+ namingConvention , _ := regexp .Compile ("^[a-z]([-a-z0-9]*[a-z0-9])?" )
71
+ if ! namingConvention .MatchString (instance .Name ) {
72
+ msg := "Name must consist of lower case alphanumeric characters or '-'," +
73
+ " start with an alphabetic character, and end with an alphanumeric character" +
74
+ " (e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')"
75
+
76
+ return fmt .Errorf (msg )
77
+ }
78
+
70
79
if instance .Spec .MaxFailedTrialCount != nil && * instance .Spec .MaxFailedTrialCount < 0 {
71
80
return fmt .Errorf ("spec.maxFailedTrialCount should not be less than 0" )
72
81
}
Original file line number Diff line number Diff line change @@ -68,6 +68,16 @@ func TestValidateExperiment(t *testing.T) {
68
68
oldInstance * experimentsv1beta1.Experiment
69
69
testDescription string
70
70
}{
71
+ // Name
72
+ {
73
+ Instance : func () * experimentsv1beta1.Experiment {
74
+ i := newFakeInstance ()
75
+ i .Name = "1234-test"
76
+ return i
77
+ }(),
78
+ Err : true ,
79
+ testDescription : "Name is invalid" ,
80
+ },
71
81
//Objective
72
82
{
73
83
Instance : func () * experimentsv1beta1.Experiment {
You can’t perform that action at this time.
0 commit comments