Skip to content

Commit

Permalink
fix: only validate Kubernetes Job
Browse files Browse the repository at this point in the history
  • Loading branch information
zhixian82 committed Nov 21, 2022
1 parent a5ef2db commit 89f0ab7
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions pkg/webhook/v1beta1/experiment/validator/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,26 +376,22 @@ func (g *DefaultValidator) validateTrialTemplate(instance *experimentsv1beta1.Ex
func (g *DefaultValidator) validateTrialJob(runSpec *unstructured.Unstructured) error {
gvk := runSpec.GroupVersionKind()

// Validate only Job
switch gvk.Kind {
case consts.JobKindJob:
batchJob := batchv1.Job{}

// Validate that RunSpec can be converted to Batch Job
err := runtime.DefaultUnstructuredConverter.FromUnstructured(runSpec.Object, &batchJob)
if err != nil {
return fmt.Errorf("unable to convert spec.TrialTemplate: %v to %v: %v", runSpec.Object, gvk.Kind, err)
}
// Validate only Kuernetes Job
if gvk.GroupVersion() != batchv1.SchemeGroupVersion {
return nil
}

// Try to patch runSpec to Batch Job
// TODO (andreyvelich): Do we want to remove it completely ?
err = validatePatchJob(runSpec, batchJob, gvk.Kind)
if err != nil {
return err
}
batchJob := batchv1.Job{}

// Validate that RunSpec can be converted to Batch Job
err := runtime.DefaultUnstructuredConverter.FromUnstructured(runSpec.Object, &batchJob)
if err != nil {
return fmt.Errorf("unable to convert spec.TrialTemplate: %v to %v: %v", runSpec.Object, gvk.Kind, err)
}

return nil
// Try to patch runSpec to Batch Job
// TODO (andreyvelich): Do we want to remove it completely ?
return validatePatchJob(runSpec, batchJob, gvk.Kind)
}

func validatePatchJob(runSpec *unstructured.Unstructured, job interface{}, jobType string) error {
Expand Down

0 comments on commit 89f0ab7

Please sign in to comment.