/
run_state.go
49 lines (43 loc) · 978 Bytes
/
run_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package pipelinerun
import (
corev1 "k8s.io/api/core/v1"
"knative.dev/pkg/apis"
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1alpha1"
)
// State represents the state of a Pipeline.
type State int
const (
Pending State = iota
Failed
Successful
Error
)
func (s State) String() string {
names := [...]string{
"Pending",
"Failed",
"Successful",
"Error"}
return names[s]
}
// getPipelineRunState returns whether or not a PipelineRun was successful or
// not.
//
// It can return a Pending result if the task has not yet completed.
// TODO: will likely need to work out if a task was killed OOM.
func getPipelineRunState(p *pipelinev1.PipelineRun) State {
for _, c := range p.Status.Conditions {
if c.Type == apis.ConditionSucceeded {
switch c.Status {
case
corev1.ConditionFalse:
return Failed
case corev1.ConditionTrue:
return Successful
case corev1.ConditionUnknown:
return Pending
}
}
}
return Pending
}