Skip to content

Commit

Permalink
Set trial completion status only after metric collection
Browse files Browse the repository at this point in the history
  • Loading branch information
johnugeorge committed May 31, 2019
1 parent 7a2ffe1 commit 4e342cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
19 changes: 15 additions & 4 deletions pkg/controller/v1alpha2/trial/trial_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
return err
}

// Watch for changes to Cronjob
err = c.Watch(&source.Kind{Type: &batchv1beta.CronJob{}}, &handler.EnqueueRequestForObject{})
if err != nil {
log.Error(err, "CronJob watch error")
return err
}

for _, gvk := range commonv1alpha2.GetSupportedJobList() {
unstructuredJob := &unstructured.Unstructured{}
unstructuredJob.SetGroupVersionKind(gvk)
Expand Down Expand Up @@ -215,14 +222,18 @@ func (r *ReconcileTrial) reconcileTrial(instance *trialsv1alpha2.Trial) error {
//Job already exists
//TODO Can desired Spec differ from deployedSpec?
if deployedJob != nil {
if err = r.UpdateTrialStatusCondition(instance, deployedJob); err != nil {
logger.Error(err, "Update trial status condition error")
return err
}
if err = r.UpdateTrialStatusObservation(instance, deployedJob); err != nil {
logger.Error(err, "Update trial status observation error")
return err
}
// Update Trial job status only if observation field is available.
// This will ensure that trial is set to be complete only if metric is collected atleast once
if isTrialObservationAvailable(instance) {
if err = r.UpdateTrialStatusCondition(instance, deployedJob); err != nil {
logger.Error(err, "Update trial status condition error")
return err
}
}
}
return nil
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/controller/v1alpha2/trial/trial_controller_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ func (r *ReconcileTrial) UpdateTrialStatusObservation(instance *trialsv1alpha2.T
return nil
}

func isTrialObservationAvailable(instance *trialsv1alpha2.Trial) bool {
objectiveMetricName := instance.Spec.Objective.ObjectiveMetricName
if instance.Status.Observation != nil && instance.Status.Observation.Metrics != nil {
for _, metric := range instance.Status.Observation.Metrics {
if metric.Name == objectiveMetricName {
return true
}
}
}
return false
}

func getBestObjectiveMetricValue(metricLogs []*api_pb.MetricLog, objectiveType commonv1alpha2.ObjectiveType) *float64 {
metricLogSize := len(metricLogs)
if metricLogSize == 0 {
Expand Down

0 comments on commit 4e342cc

Please sign in to comment.