From 7cadd624215e53f4c53ca94782f82a25abbfac7e Mon Sep 17 00:00:00 2001 From: Andrey Velichkevich Date: Thu, 9 May 2019 16:17:59 -0700 Subject: [PATCH] Update util for experiment in v1alpha2 (#485) * Update util for experiment * Change GetLastConditionType func * Add empty condition check --- .../operators/apis/experiment/v1alpha2/util.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/api/operators/apis/experiment/v1alpha2/util.go b/pkg/api/operators/apis/experiment/v1alpha2/util.go index bc9a1440a09..573cc2ba823 100644 --- a/pkg/api/operators/apis/experiment/v1alpha2/util.go +++ b/pkg/api/operators/apis/experiment/v1alpha2/util.go @@ -16,6 +16,8 @@ limitations under the License. package v1alpha2 import ( + "errors" + v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -73,10 +75,25 @@ func (exp *Experiment) IsFailed() bool { return hasCondition(exp, ExperimentFailed) } +func (exp *Experiment) IsRunning() bool { + return hasCondition(exp, ExperimentRunning) +} + +func (exp *Experiment) IsRestarting() bool { + return hasCondition(exp, ExperimentRestarting) +} + func (exp *Experiment) IsCompleted() bool { return exp.IsSucceeded() || exp.IsFailed() } +func (exp *Experiment) GetLastConditionType() (ExperimentConditionType, error) { + if len(exp.Status.Conditions) > 0 { + return exp.Status.Conditions[len(exp.Status.Conditions)-1].Type, nil + } + return "", errors.New("Experiment doesn't have any condition") +} + func (exp *Experiment) setCondition(conditionType ExperimentConditionType, status v1.ConditionStatus, reason, message string) { newCond := newCondition(conditionType, status, reason, message)