...
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 Deleting ChaosStatus = "deleting"
35 )
36
37 type AllChaosStatus struct {
38 Injecting int `json:"injecting"`
39 Running int `json:"running"`
40 Finished int `json:"finished"`
41 Paused int `json:"paused"`
42 Deleting int `json:"deleting"`
43 }
44
45 type ScheduleStatus string
46
47 const (
48 ScheduleRunning ScheduleStatus = "running"
49 SchedulePaused ScheduleStatus = "paused"
50 )
51
52
53 func GetChaosStatus(obj v1alpha1.InnerObject) ChaosStatus {
54 if obj.IsDeleted() {
55 return Deleting
56 }
57
58 selected := false
59 allInjected := false
60 for _, c := range obj.GetStatus().Conditions {
61 if c.Status == corev1.ConditionTrue {
62 switch c.Type {
63
64 case v1alpha1.ConditionPaused:
65 return Paused
66 case v1alpha1.ConditionSelected:
67 selected = true
68 case v1alpha1.ConditionAllInjected:
69 allInjected = true
70 }
71 }
72 }
73
74 if controller.IsChaosFinished(obj, time.Now()) {
75 return Finished
76 }
77
78
79
80 if selected && allInjected {
81 return Running
82 }
83
84 return Injecting
85 }
86
87 func GetScheduleStatus(sch v1alpha1.Schedule) ScheduleStatus {
88 if sch.IsPaused() {
89 return SchedulePaused
90 }
91
92 return ScheduleRunning
93 }
94