Skip to content

Commit

Permalink
[review] simplify validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
tenzen-y committed Aug 21, 2022
1 parent 4d59b1f commit 6398e6f
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions pkg/webhook/v1beta1/experiment/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down

0 comments on commit 6398e6f

Please sign in to comment.