@@ -3,6 +3,7 @@ package chaoskube
3
3
import (
4
4
"context"
5
5
"math/rand"
6
+ "net/url"
6
7
"regexp"
7
8
"testing"
8
9
"time"
@@ -46,13 +47,14 @@ func (suite *Suite) TestNew() {
46
47
includedPodNames = regexp .MustCompile ("foo" )
47
48
excludedPodNames = regexp .MustCompile ("bar" )
48
49
excludedWeekdays = []time.Weekday {time .Friday }
49
- excludedTimesOfDay = []util.TimePeriod {util. TimePeriod {}}
50
+ excludedTimesOfDay = []util.TimePeriod {{}}
50
51
excludedDaysOfYear = []time.Time {time .Now ()}
51
52
minimumAge = time .Duration (42 )
52
53
dryRun = true
53
54
terminator = terminator .NewDeletePodTerminator (client , logger , 10 * time .Second )
54
55
)
55
56
57
+ webhook , _ := url .Parse ("" )
56
58
chaoskube := New (
57
59
client ,
58
60
labelSelector ,
@@ -69,6 +71,7 @@ func (suite *Suite) TestNew() {
69
71
logger ,
70
72
dryRun ,
71
73
terminator ,
74
+ * webhook ,
72
75
)
73
76
suite .Require ().NotNil (chaoskube )
74
77
@@ -105,6 +108,7 @@ func (suite *Suite) TestRunContextCanceled() {
105
108
time .Duration (0 ),
106
109
false ,
107
110
10 ,
111
+ url.URL {},
108
112
)
109
113
110
114
ctx , cancel := context .WithCancel (context .Background ())
@@ -122,19 +126,24 @@ func (suite *Suite) TestCandidates() {
122
126
labelSelector string
123
127
annotationSelector string
124
128
namespaceSelector string
129
+ webhook string
125
130
pods []map [string ]string
126
131
}{
127
- {"" , "" , "" , []map [string ]string {foo , bar }},
128
- {"app=foo" , "" , "" , []map [string ]string {foo }},
129
- {"app!=foo" , "" , "" , []map [string ]string {bar }},
130
- {"" , "chaos=foo" , "" , []map [string ]string {foo }},
131
- {"" , "chaos!=foo" , "" , []map [string ]string {bar }},
132
- {"" , "" , "default" , []map [string ]string {foo }},
133
- {"" , "" , "default,testing" , []map [string ]string {foo , bar }},
134
- {"" , "" , "!testing" , []map [string ]string {foo }},
135
- {"" , "" , "!default,!testing" , []map [string ]string {}},
136
- {"" , "" , "default,!testing" , []map [string ]string {foo }},
137
- {"" , "" , "default,!default" , []map [string ]string {}},
132
+ {"" , "" , "" , "" , []map [string ]string {foo , bar }},
133
+ {"app=foo" , "" , "" , "" , []map [string ]string {foo }},
134
+ {"app!=foo" , "" , "" , "" , []map [string ]string {bar }},
135
+ {"" , "chaos=foo" , "" , "" , []map [string ]string {foo }},
136
+ {"" , "chaos!=foo" , "" , "" , []map [string ]string {bar }},
137
+ {"" , "" , "default" , "" , []map [string ]string {foo }},
138
+ {"" , "" , "default,testing" , "" , []map [string ]string {foo , bar }},
139
+ {"" , "" , "!testing" , "" , []map [string ]string {foo }},
140
+ {"" , "" , "!default,!testing" , "" , []map [string ]string {}},
141
+ {"" , "" , "default,!testing" , "" , []map [string ]string {foo }},
142
+ {"" , "" , "default,!default" , "" , []map [string ]string {}},
143
+ {"" , "" , "" , "https://httpbin.org/status/404" , []map [string ]string {}},
144
+ {"" , "" , "" , "https://httpbin.org/get" , []map [string ]string {}},
145
+ {"" , "" , "" , "https://httpbin.org/status/200" , []map [string ]string {foo , bar }},
146
+ {"" , "" , "" , "https://httpbin.org/post" , []map [string ]string {foo , bar }},
138
147
} {
139
148
labelSelector , err := labels .Parse (tt .labelSelector )
140
149
suite .Require ().NoError (err )
@@ -145,6 +154,9 @@ func (suite *Suite) TestCandidates() {
145
154
namespaceSelector , err := labels .Parse (tt .namespaceSelector )
146
155
suite .Require ().NoError (err )
147
156
157
+ webhook , err := url .Parse (tt .webhook )
158
+ suite .Require ().NoError (err )
159
+
148
160
chaoskube := suite .setupWithPods (
149
161
labelSelector ,
150
162
annotationSelector ,
@@ -159,6 +171,7 @@ func (suite *Suite) TestCandidates() {
159
171
time .Duration (0 ),
160
172
false ,
161
173
10 ,
174
+ * webhook ,
162
175
)
163
176
164
177
suite .assertCandidates (chaoskube , tt .pods )
@@ -203,6 +216,7 @@ func (suite *Suite) TestCandidatesNamespaceLabels() {
203
216
time .Duration (0 ),
204
217
false ,
205
218
10 ,
219
+ url.URL {},
206
220
)
207
221
208
222
suite .assertCandidates (chaoskube , tt .pods )
@@ -245,6 +259,7 @@ func (suite *Suite) TestCandidatesPodNameRegexp() {
245
259
time .Duration (0 ),
246
260
false ,
247
261
10 ,
262
+ url.URL {},
248
263
)
249
264
250
265
suite .assertCandidates (chaoskube , tt .pods )
@@ -284,6 +299,7 @@ func (suite *Suite) TestVictim() {
284
299
time .Duration (0 ),
285
300
false ,
286
301
10 ,
302
+ url.URL {},
287
303
)
288
304
289
305
suite .assertVictim (chaoskube , tt .victim )
@@ -306,6 +322,7 @@ func (suite *Suite) TestNoVictimReturnsError() {
306
322
time .Duration (0 ),
307
323
false ,
308
324
10 ,
325
+ url.URL {},
309
326
)
310
327
311
328
_ , err := chaoskube .Victim ()
@@ -339,6 +356,7 @@ func (suite *Suite) TestDeletePod() {
339
356
time .Duration (0 ),
340
357
tt .dryRun ,
341
358
10 ,
359
+ url.URL {},
342
360
)
343
361
344
362
victim := util .NewPod ("default" , "foo" , v1 .PodRunning )
@@ -367,6 +385,7 @@ func (suite *Suite) TestDeletePodNotFound() {
367
385
time .Duration (0 ),
368
386
false ,
369
387
10 ,
388
+ url.URL {},
370
389
)
371
390
372
391
victim := util .NewPod ("default" , "foo" , v1 .PodRunning )
@@ -597,6 +616,7 @@ func (suite *Suite) TestTerminateVictim() {
597
616
time .Duration (0 ),
598
617
false ,
599
618
10 ,
619
+ url.URL {},
600
620
)
601
621
chaoskube .Now = tt .now
602
622
@@ -626,6 +646,7 @@ func (suite *Suite) TestTerminateNoVictimLogsInfo() {
626
646
time .Duration (0 ),
627
647
false ,
628
648
10 ,
649
+ url.URL {},
629
650
)
630
651
631
652
err := chaoskube .TerminateVictim ()
@@ -650,7 +671,7 @@ func (suite *Suite) assertVictim(chaoskube *Chaoskube, expected map[string]strin
650
671
suite .AssertPod (victim , expected )
651
672
}
652
673
653
- func (suite * Suite ) setupWithPods (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration ) * Chaoskube {
674
+ func (suite * Suite ) setupWithPods (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration , webhook url. URL ) * Chaoskube {
654
675
chaoskube := suite .setup (
655
676
labelSelector ,
656
677
annotations ,
@@ -665,6 +686,7 @@ func (suite *Suite) setupWithPods(labelSelector labels.Selector, annotations lab
665
686
minimumAge ,
666
687
dryRun ,
667
688
gracePeriod ,
689
+ webhook ,
668
690
)
669
691
670
692
for _ , namespace := range []v1.Namespace {
@@ -689,7 +711,7 @@ func (suite *Suite) setupWithPods(labelSelector labels.Selector, annotations lab
689
711
return chaoskube
690
712
}
691
713
692
- func (suite * Suite ) setup (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration ) * Chaoskube {
714
+ func (suite * Suite ) setup (labelSelector labels.Selector , annotations labels.Selector , namespaces labels.Selector , namespaceLabels labels.Selector , includedPodNames * regexp.Regexp , excludedPodNames * regexp.Regexp , excludedWeekdays []time.Weekday , excludedTimesOfDay []util.TimePeriod , excludedDaysOfYear []time.Time , timezone * time.Location , minimumAge time.Duration , dryRun bool , gracePeriod time.Duration , webhook url. URL ) * Chaoskube {
693
715
logOutput .Reset ()
694
716
695
717
client := fake .NewSimpleClientset ()
@@ -711,6 +733,7 @@ func (suite *Suite) setup(labelSelector labels.Selector, annotations labels.Sele
711
733
logger ,
712
734
dryRun ,
713
735
terminator .NewDeletePodTerminator (client , nullLogger , gracePeriod ),
736
+ webhook ,
714
737
)
715
738
}
716
739
@@ -814,6 +837,7 @@ func (suite *Suite) TestMinimumAge() {
814
837
tt .minimumAge ,
815
838
false ,
816
839
10 ,
840
+ url.URL {},
817
841
)
818
842
chaoskube .Now = tt .now
819
843
0 commit comments