...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package controller
17
18 import (
19 "time"
20
21 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
22 )
23
24 func IsChaosFinished(obj v1alpha1.InnerObject, now time.Time) bool {
25 finished, _ := IsChaosFinishedWithUntilStop(obj, now)
26 return finished
27 }
28
29 func IsChaosFinishedWithUntilStop(obj v1alpha1.InnerObject, now time.Time) (bool, time.Duration) {
30 status := obj.GetStatus()
31 if obj.IsOneShot() {
32 finished := true
33 if len(status.Experiment.Records) == 0 {
34 finished = false
35 } else {
36 for _, record := range status.Experiment.Records {
37 if record.Phase != v1alpha1.Injected {
38 finished = false
39 }
40 }
41 }
42
43 return finished, time.Duration(time.Second)
44 }
45
46 finished := true
47
48 if status.Experiment.DesiredPhase == v1alpha1.RunningPhase {
49 finished = false
50 } else {
51
52 for _, record := range status.Experiment.Records {
53 if record.Phase != v1alpha1.NotInjected {
54 finished = false
55 }
56 }
57 }
58
59 durationExceeded, untilStop, err := obj.DurationExceeded(now)
60 if err != nil {
61 return finished, untilStop
62 }
63 if durationExceeded {
64 return finished, untilStop
65 }
66
67 return false, untilStop
68 }
69