@@ -10,6 +10,7 @@ import (
10
10
"os/exec"
11
11
"os/signal"
12
12
"reflect"
13
+ "regexp"
13
14
"strconv"
14
15
"strings"
15
16
"syscall"
@@ -29,13 +30,17 @@ type ENVDetails struct {
29
30
ENV []apiv1.EnvVar
30
31
}
31
32
32
- //WaitForDuration waits for the given time duration (in seconds)
33
+ // WaitForDuration waits for the given time duration (in seconds)
33
34
func WaitForDuration (duration int ) {
34
35
time .Sleep (time .Duration (duration ) * time .Second )
35
36
}
36
37
37
38
// RandomInterval wait for the random interval lies between lower & upper bounds
38
39
func RandomInterval (interval string ) error {
40
+ re := regexp .MustCompile (`^\d+(-\d+)?$` )
41
+ if re .MatchString (interval ) == false {
42
+ return cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : "could not parse CHAOS_INTERVAL env, bad input" }
43
+ }
39
44
intervals := strings .Split (interval , "-" )
40
45
var lowerBound , upperBound int
41
46
switch len (intervals ) {
@@ -49,6 +54,9 @@ func RandomInterval(interval string) error {
49
54
return cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : "could not parse CHAOS_INTERVAL env, invalid format" }
50
55
}
51
56
rand .Seed (time .Now ().UnixNano ())
57
+ if upperBound < 1 {
58
+ return cerrors.Error {ErrorCode : cerrors .ErrorTypeGeneric , Reason : "invalid CHAOS_INTERVAL env value, value below lower limit" }
59
+ }
52
60
waitTime := lowerBound + rand .Intn (upperBound - lowerBound )
53
61
log .Infof ("[Wait]: Wait for the random chaos interval %vs" , waitTime )
54
62
WaitForDuration (waitTime )
@@ -98,7 +106,7 @@ func AbortWatcherWithoutExit(expname string, clients clients.ClientSets, resultD
98
106
}
99
107
}
100
108
101
- //FilterBasedOnPercentage return the slice of list based on the the provided percentage
109
+ // FilterBasedOnPercentage return the slice of list based on the the provided percentage
102
110
func FilterBasedOnPercentage (percentage int , list []string ) []string {
103
111
104
112
var finalList []string
@@ -175,7 +183,7 @@ func GetStatusMessage(defaultCheck bool, defaultMsg, probeStatus string) string
175
183
return "Probes: " + probeStatus
176
184
}
177
185
178
- //GetRandomSequence will gives a random value for sequence
186
+ // GetRandomSequence will gives a random value for sequence
179
187
func GetRandomSequence (sequence string ) string {
180
188
if strings .ToLower (sequence ) == "random" {
181
189
rand .Seed (time .Now ().UnixNano ())
@@ -186,7 +194,7 @@ func GetRandomSequence(sequence string) string {
186
194
return sequence
187
195
}
188
196
189
- //ValidateRange validates the given range of numbers
197
+ // ValidateRange validates the given range of numbers
190
198
func ValidateRange (a string ) string {
191
199
var lb , ub int
192
200
intervals := strings .Split (a , "-" )
@@ -204,7 +212,7 @@ func ValidateRange(a string) string {
204
212
}
205
213
}
206
214
207
- //getRandomValue gives a random value between two integers
215
+ // getRandomValue gives a random value between two integers
208
216
func getRandomValue (a , b int ) int {
209
217
rand .Seed (time .Now ().Unix ())
210
218
return (a + rand .Intn (b - a + 1 ))
0 commit comments