Skip to content

Commit

Permalink
fix: First check failed condition (#1015)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <gaoce@caicloud.io>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Jan 15, 2020
1 parent 866b363 commit b323afc
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pkg/controller.v1alpha3/experiment/util/status_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func getObjectiveMetricValue(trial trialsv1alpha3.Trial, objectiveMetricName str
return nil
}

// UpdateExperimentStatusCondition updates the experiment status.
func UpdateExperimentStatusCondition(collector *ExperimentsCollector, instance *experimentsv1alpha3.Experiment, isObjectiveGoalReached bool, getSuggestionDone bool) {

completedTrialsCount := instance.Status.TrialsSucceeded + instance.Status.TrialsFailed + instance.Status.TrialsKilled
Expand All @@ -153,6 +154,16 @@ func UpdateExperimentStatusCondition(collector *ExperimentsCollector, instance *
return
}

// First check if MaxFailedTrialCount is reached.
if (instance.Spec.MaxFailedTrialCount != nil) && (failedTrialsCount > *instance.Spec.MaxFailedTrialCount) {
msg := "Experiment has failed because max failed count has reached"
instance.MarkExperimentStatusFailed(ExperimentFailedReason, msg)
instance.Status.CompletionTime = &now
collector.IncreaseExperimentsFailedCount(instance.Namespace)
return
}

// Then Check if MaxTrialCount is reached.
if (instance.Spec.MaxTrialCount != nil) && (completedTrialsCount >= *instance.Spec.MaxTrialCount) {
msg := "Experiment has succeeded because max trial count has reached"
instance.MarkExperimentStatusSucceeded(ExperimentMaxTrialsReachedReason, msg)
Expand All @@ -169,14 +180,6 @@ func UpdateExperimentStatusCondition(collector *ExperimentsCollector, instance *
return
}

if (instance.Spec.MaxFailedTrialCount != nil) && (failedTrialsCount > *instance.Spec.MaxFailedTrialCount) {
msg := "Experiment has failed because max failed count has reached"
instance.MarkExperimentStatusFailed(ExperimentFailedReason, msg)
instance.Status.CompletionTime = &now
collector.IncreaseExperimentsFailedCount(instance.Namespace)
return
}

msg := "Experiment is running"
instance.MarkExperimentStatusRunning(ExperimentRunningReason, msg)
}
Expand Down

0 comments on commit b323afc

Please sign in to comment.