...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package v1alpha1
17
18 import (
19 "time"
20
21 corev1 "k8s.io/api/core/v1"
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 ctrl "sigs.k8s.io/controller-runtime"
24 "sigs.k8s.io/controller-runtime/pkg/webhook"
25 )
26
27 const (
28
29 PauseAnnotationKey = "experiment.chaos-mesh.org/pause"
30 LabelManagedBy = "managed-by"
31 )
32
33 type ChaosStatus struct {
34
35
36 Conditions []ChaosCondition `json:"conditions,omitempty"`
37
38
39 Experiment ExperimentStatus `json:"experiment"`
40 }
41
42 type ChaosConditionType string
43
44 const (
45 ConditionSelected ChaosConditionType = "Selected"
46 ConditionAllInjected ChaosConditionType = "AllInjected"
47 ConditionAllRecovered ChaosConditionType = "AllRecovered"
48 ConditionPaused ChaosConditionType = "Paused"
49 )
50
51 type ChaosCondition struct {
52 Type ChaosConditionType `json:"type"`
53 Status corev1.ConditionStatus `json:"status"`
54
55 Reason string `json:"reason,omitempty"`
56 }
57
58 type DesiredPhase string
59
60 const (
61
62 RunningPhase DesiredPhase = "Run"
63
64 StoppedPhase DesiredPhase = "Stop"
65 )
66
67 type ExperimentStatus struct {
68
69 DesiredPhase `json:"desiredPhase,omitempty"`
70
71
72 Records []*Record `json:"containerRecords,omitempty"`
73 }
74
75 type Record struct {
76 Id string `json:"id"`
77 SelectorKey string `json:"selectorKey"`
78 Phase Phase `json:"phase"`
79
80 InjectedCount int `json:"injectedCount"`
81
82 RecoveredCount int `json:"recoveredCount"`
83
84 Events []RecordEvent `json:"events,omitempty"`
85 }
86
87 type Phase string
88
89 const (
90
91 NotInjected Phase = "Not Injected"
92
93 Injected Phase = "Injected"
94 )
95
96 type RecordEvent struct {
97
98 Type RecordEventType `json:"type"`
99
100 Operation RecordEventOperation `json:"operation"`
101
102 Message string `json:"message,omitempty"`
103
104 Timestamp *metav1.Time `json:"timestamp"`
105 }
106
107 type RecordEventType string
108
109 const (
110
111 TypeSucceeded RecordEventType = "Succeeded"
112
113 TypeFailed RecordEventType = "Failed"
114 )
115
116 type RecordEventOperation string
117
118 const (
119
120
121 Apply RecordEventOperation = "Apply"
122
123
124 Recover RecordEventOperation = "Recover"
125 )
126
127
128 func NewRecordEvent(eventType RecordEventType, eventStage RecordEventOperation,
129 msg string, time metav1.Time) *RecordEvent {
130 return &RecordEvent{
131 Type: eventType,
132 Operation: eventStage,
133 Message: msg,
134 Timestamp: &time,
135 }
136 }
137
138 var log = ctrl.Log.WithName("api")
139
140
141
142
143 type InnerObject interface {
144 StatefulObject
145 IsDeleted() bool
146 IsPaused() bool
147 DurationExceeded(time.Time) (bool, time.Duration, error)
148 IsOneShot() bool
149 }
150
151
152
153
154 type StatefulObject interface {
155 GenericChaos
156 GetStatus() *ChaosStatus
157 }
158
159
160 type InnerObjectWithCustomStatus interface {
161 InnerObject
162
163 GetCustomStatus() interface{}
164 }
165
166
167 type InnerObjectWithSelector interface {
168 InnerObject
169
170 GetSelectorSpecs() map[string]interface{}
171 }
172
173
174
175
176 type WebhookObject interface {
177 webhook.Validator
178 webhook.Defaulter
179 }
180
181
182 type RemoteObject interface {
183 StatefulObject
184 GetRemoteCluster() string
185 }
186