@@ -24,7 +24,6 @@ import (
24
24
"math/rand"
25
25
"net/http"
26
26
"net/url"
27
- "os"
28
27
"strings"
29
28
"sync"
30
29
"time"
@@ -35,17 +34,15 @@ import (
35
34
36
35
// pkgfi "github.com/KusionStack/controller-mesh/circuitbreaker"
37
36
38
- "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/constants"
39
37
ctrlmeshproto "github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto"
40
38
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
41
39
)
42
40
43
41
const timeLayout = "15:04:05"
44
42
45
43
var (
46
- logger = logf .Log .WithName ("fault-injection-manager" )
47
- randNum = rand .New (rand .NewSource (time .Now ().UnixNano ()))
48
- enableRestFaultInjection = os .Getenv (constants .EnvEnableRestFaultInjection ) == "true"
44
+ logger = logf .Log .WithName ("fault-injection-manager" )
45
+ randNum = rand .New (rand .NewSource (time .Now ().UnixNano ()))
49
46
)
50
47
51
48
type ManagerInterface interface {
@@ -166,7 +163,7 @@ func (m *manager) FaultInjectionRest(URL string, method string) (result *FaultIn
166
163
result = m .doFaultInjection (faultInjections , states )
167
164
return result
168
165
}
169
- result = & FaultInjectionResult {Abort : true , Reason : "No rule match" }
166
+ result = & FaultInjectionResult {Abort : false , Reason : "No rule match" }
170
167
return result
171
168
}
172
169
@@ -204,7 +201,7 @@ func (m *manager) FaultInjectionResource(namespace, apiGroup, resource, verb str
204
201
result = m .doFaultInjection (faultInjections , states )
205
202
return result
206
203
}
207
- result = & FaultInjectionResult {Abort : true , Reason : "No rule match" }
204
+ result = & FaultInjectionResult {Abort : false , Reason : "No rule match" }
208
205
return result
209
206
}
210
207
@@ -251,7 +248,7 @@ func withFaultInjection(injector FaultInjector, handler http.Handler) http.Handl
251
248
}
252
249
result := injector .FaultInjectionResource (requestInfo .Namespace , requestInfo .APIGroup , requestInfo .Resource , requestInfo .Verb )
253
250
254
- if ! result .Abort {
251
+ if result .Abort {
255
252
apiErr := httpToAPIError (int (result .ErrCode ), result .Message )
256
253
if apiErr .Code != http .StatusOK {
257
254
w .Header ().Set ("Content-Type" , "application/json" )
@@ -268,7 +265,7 @@ func withFaultInjection(injector FaultInjector, handler http.Handler) http.Handl
268
265
269
266
func (m * manager ) doFaultInjection (faultInjections []* ctrlmeshproto.HTTPFaultInjection , states []* state ) * FaultInjectionResult {
270
267
result := & FaultInjectionResult {
271
- Abort : true ,
268
+ Abort : false ,
272
269
Reason : "Default allow" ,
273
270
}
274
271
for idx := range faultInjections {
@@ -288,14 +285,13 @@ func (m *manager) doFaultInjection(faultInjections []*ctrlmeshproto.HTTPFaultInj
288
285
}
289
286
if faultInjections [idx ].Abort != nil {
290
287
if isInpercentRange (faultInjections [idx ].Abort .Percent ) {
291
- result .Abort = false
288
+ result .Abort = true
292
289
result .Reason = "FaultInjectionTriggered"
293
290
result .Message = fmt .Sprintf ("the fault injection is triggered. Limiting rule name: %s" , faultInjections [idx ].Name )
294
291
result .ErrCode = faultInjections [idx ].Abort .GetHttpStatus ()
295
292
}
296
293
297
294
}
298
- states [idx ].triggerFaultInjection ()
299
295
}
300
296
return result
301
297
}
0 commit comments