...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package status
17
18 import (
19 "time"
20
21 corev1 "k8s.io/api/core/v1"
22
23 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
24 "github.com/chaos-mesh/chaos-mesh/controllers/utils/controller"
25 )
26
27 type ChaosStatus string
28
29 const (
30 Injecting ChaosStatus = "injecting"
31 Running ChaosStatus = "running"
32 Finished ChaosStatus = "finished"
33 Paused ChaosStatus = "paused"
34 )
35
36 type AllChaosStatus struct {
37 Injecting int `json:"injecting"`
38 Running int `json:"running"`
39 Finished int `json:"finished"`
40 Paused int `json:"paused"`
41 }
42
43 type ScheduleStatus string
44
45 const (
46 ScheduleRunning ScheduleStatus = "running"
47 SchedulePaused ScheduleStatus = "paused"
48 )
49
50 func GetChaosStatus(obj v1alpha1.InnerObject) ChaosStatus {
51 selected := false
52 allInjected := false
53 for _, c := range obj.GetStatus().Conditions {
54 if c.Status == corev1.ConditionTrue {
55 switch c.Type {
56 case v1alpha1.ConditionPaused:
57 return Paused
58 case v1alpha1.ConditionSelected:
59 selected = true
60 case v1alpha1.ConditionAllInjected:
61 allInjected = true
62 }
63 }
64 }
65
66 if controller.IsChaosFinished(obj, time.Now()) {
67 return Finished
68 }
69
70 if selected && allInjected {
71 return Running
72 }
73
74 return Injecting
75 }
76
77 func GetScheduleStatus(sch v1alpha1.Schedule) ScheduleStatus {
78 if sch.IsPaused() {
79 return SchedulePaused
80 }
81
82 return ScheduleRunning
83 }
84