diff --git a/pkg/webhook/v1beta1/experiment/validator/validator.go b/pkg/webhook/v1beta1/experiment/validator/validator.go index 5b3553ee01a..aeaf911904a 100644 --- a/pkg/webhook/v1beta1/experiment/validator/validator.go +++ b/pkg/webhook/v1beta1/experiment/validator/validator.go @@ -74,22 +74,23 @@ func (g *DefaultValidator) ValidateExperiment(instance, oldInst *experimentsv1be return fmt.Errorf(msg) } - if instance.Spec.MaxFailedTrialCount != nil { - if *instance.Spec.MaxFailedTrialCount < 0 { - return fmt.Errorf("spec.maxFailedTrialCount should not be less than 0") - } - if instance.Spec.MaxTrialCount != nil && *instance.Spec.MaxFailedTrialCount > *instance.Spec.MaxTrialCount { - return fmt.Errorf("spec.maxFailedTrialCount should be less than or equal to spec.maxTrialCount") - } + if instance.Spec.MaxFailedTrialCount != nil && *instance.Spec.MaxFailedTrialCount < 0 { + return fmt.Errorf("spec.maxFailedTrialCount should not be less than 0") } if instance.Spec.MaxTrialCount != nil && *instance.Spec.MaxTrialCount <= 0 { return fmt.Errorf("spec.maxTrialCount must be greater than 0") } - if instance.Spec.ParallelTrialCount != nil { - if *instance.Spec.ParallelTrialCount <= 0 { - return fmt.Errorf("spec.parallelTrialCount must be greater than 0") + if instance.Spec.ParallelTrialCount != nil && *instance.Spec.ParallelTrialCount <= 0 { + return fmt.Errorf("spec.parallelTrialCount must be greater than 0") + } + + if instance.Spec.MaxFailedTrialCount != nil && instance.Spec.MaxTrialCount != nil { + if *instance.Spec.MaxFailedTrialCount > *instance.Spec.MaxTrialCount { + return fmt.Errorf("spec.maxFailedTrialCount should be less than or equal to spec.maxTrialCount") } - if instance.Spec.MaxTrialCount != nil && *instance.Spec.ParallelTrialCount > *instance.Spec.MaxTrialCount { + } + if instance.Spec.ParallelTrialCount != nil && instance.Spec.MaxTrialCount != nil { + if *instance.Spec.ParallelTrialCount > *instance.Spec.MaxTrialCount { return fmt.Errorf("spec.paralelTrialCount should be less than or equal to spec.maxTrialCount") } }