@@ -42,6 +42,7 @@ func (suite *Suite) TestNew() {
42
42
labelSelector , _ = labels .Parse ("foo=bar" )
43
43
annotations , _ = labels .Parse ("baz=waldo" )
44
44
namespaces , _ = labels .Parse ("qux" )
45
+ namespaceLabels , _ = labels .Parse ("taz=wubble" )
45
46
includedPodNames = regexp .MustCompile ("foo" )
46
47
excludedPodNames = regexp .MustCompile ("bar" )
47
48
excludedWeekdays = []time.Weekday {time .Friday }
@@ -57,6 +58,7 @@ func (suite *Suite) TestNew() {
57
58
labelSelector ,
58
59
annotations ,
59
60
namespaces ,
61
+ namespaceLabels ,
60
62
includedPodNames ,
61
63
excludedPodNames ,
62
64
excludedWeekdays ,
@@ -74,6 +76,7 @@ func (suite *Suite) TestNew() {
74
76
suite .Equal ("foo=bar" , chaoskube .Labels .String ())
75
77
suite .Equal ("baz=waldo" , chaoskube .Annotations .String ())
76
78
suite .Equal ("qux" , chaoskube .Namespaces .String ())
79
+ suite .Equal ("taz=wubble" , chaoskube .NamespaceLabels .String ())
77
80
suite .Equal ("foo" , chaoskube .IncludedPodNames .String ())
78
81
suite .Equal ("bar" , chaoskube .ExcludedPodNames .String ())
79
82
suite .Equal (excludedWeekdays , chaoskube .ExcludedWeekdays )
@@ -92,6 +95,7 @@ func (suite *Suite) TestRunContextCanceled() {
92
95
labels .Everything (),
93
96
labels .Everything (),
94
97
labels .Everything (),
98
+ labels .Everything (),
95
99
& regexp.Regexp {},
96
100
& regexp.Regexp {},
97
101
[]time.Weekday {},
@@ -145,6 +149,51 @@ func (suite *Suite) TestCandidates() {
145
149
labelSelector ,
146
150
annotationSelector ,
147
151
namespaceSelector ,
152
+ labels .Everything (),
153
+ nil ,
154
+ nil ,
155
+ []time.Weekday {},
156
+ []util.TimePeriod {},
157
+ []time.Time {},
158
+ time .UTC ,
159
+ time .Duration (0 ),
160
+ false ,
161
+ 10 ,
162
+ )
163
+
164
+ suite .assertCandidates (chaoskube , tt .pods )
165
+ }
166
+ }
167
+
168
+ // TestCandidatesNamespaceLabels tests that the label selector for namespaces works correctly.
169
+ func (suite * Suite ) TestCandidatesNamespaceLabels () {
170
+ foo := map [string ]string {"namespace" : "default" , "name" : "foo" }
171
+ bar := map [string ]string {"namespace" : "testing" , "name" : "bar" }
172
+
173
+ for _ , tt := range []struct {
174
+ labels string
175
+ pods []map [string ]string
176
+ }{
177
+ {"" , []map [string ]string {foo , bar }},
178
+ {"env" , []map [string ]string {foo , bar }},
179
+ {"!env" , []map [string ]string {}},
180
+ {"env=default" , []map [string ]string {foo }},
181
+ {"env=testing" , []map [string ]string {bar }},
182
+ {"env!=default" , []map [string ]string {bar }},
183
+ {"env!=testing" , []map [string ]string {foo }},
184
+ {"env!=default,env!=testing" , []map [string ]string {}},
185
+ {"env=default,env!=testing" , []map [string ]string {foo }},
186
+ {"env=default,env!=default" , []map [string ]string {}},
187
+ {"nomatch" , []map [string ]string {}},
188
+ } {
189
+ namespaceLabels , err := labels .Parse (tt .labels )
190
+ suite .Require ().NoError (err )
191
+
192
+ chaoskube := suite .setupWithPods (
193
+ labels .Everything (),
194
+ labels .Everything (),
195
+ labels .Everything (),
196
+ namespaceLabels ,
148
197
nil ,
149
198
nil ,
150
199
[]time.Weekday {},
@@ -186,6 +235,7 @@ func (suite *Suite) TestCandidatesPodNameRegexp() {
186
235
labels .Everything (),
187
236
labels .Everything (),
188
237
labels .Everything (),
238
+ labels .Everything (),
189
239
tt .includedPodNames ,
190
240
tt .excludedPodNames ,
191
241
[]time.Weekday {},
@@ -224,6 +274,7 @@ func (suite *Suite) TestVictim() {
224
274
labelSelector ,
225
275
labels .Everything (),
226
276
labels .Everything (),
277
+ labels .Everything (),
227
278
& regexp.Regexp {},
228
279
& regexp.Regexp {},
229
280
[]time.Weekday {},
@@ -245,6 +296,7 @@ func (suite *Suite) TestNoVictimReturnsError() {
245
296
labels .Everything (),
246
297
labels .Everything (),
247
298
labels .Everything (),
299
+ labels .Everything (),
248
300
& regexp.Regexp {},
249
301
& regexp.Regexp {},
250
302
[]time.Weekday {},
@@ -277,6 +329,7 @@ func (suite *Suite) TestDeletePod() {
277
329
labels .Everything (),
278
330
labels .Everything (),
279
331
labels .Everything (),
332
+ labels .Everything (),
280
333
& regexp.Regexp {},
281
334
& regexp.Regexp {},
282
335
[]time.Weekday {},
@@ -304,6 +357,7 @@ func (suite *Suite) TestDeletePodNotFound() {
304
357
labels .Everything (),
305
358
labels .Everything (),
306
359
labels .Everything (),
360
+ labels .Everything (),
307
361
& regexp.Regexp {},
308
362
& regexp.Regexp {},
309
363
[]time.Weekday {},
@@ -533,6 +587,7 @@ func (suite *Suite) TestTerminateVictim() {
533
587
labels .Everything (),
534
588
labels .Everything (),
535
589
labels .Everything (),
590
+ labels .Everything (),
536
591
& regexp.Regexp {},
537
592
& regexp.Regexp {},
538
593
tt .excludedWeekdays ,
@@ -561,6 +616,7 @@ func (suite *Suite) TestTerminateNoVictimLogsInfo() {
561
616
labels .Everything (),
562
617
labels .Everything (),
563
618
labels .Everything (),
619
+ labels .Everything (),
564
620
& regexp.Regexp {},
565
621
& regexp.Regexp {},
566
622
[]time.Weekday {},
@@ -594,11 +650,12 @@ func (suite *Suite) assertVictim(chaoskube *Chaoskube, expected map[string]strin
594
650
suite .AssertPod (victim , expected )
595
651
}
596
652
597
- func (suite * Suite ) setupWithPods (labelSelector labels.Selector , annotations labels.Selector , namespaces 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 {
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 {
598
654
chaoskube := suite .setup (
599
655
labelSelector ,
600
656
annotations ,
601
657
namespaces ,
658
+ namespaceLabels ,
602
659
includedPodNames ,
603
660
excludedPodNames ,
604
661
excludedWeekdays ,
@@ -610,6 +667,14 @@ func (suite *Suite) setupWithPods(labelSelector labels.Selector, annotations lab
610
667
gracePeriod ,
611
668
)
612
669
670
+ for _ , namespace := range []v1.Namespace {
671
+ util .NewNamespace ("default" ),
672
+ util .NewNamespace ("testing" ),
673
+ } {
674
+ _ , err := chaoskube .Client .CoreV1 ().Namespaces ().Create (& namespace )
675
+ suite .Require ().NoError (err )
676
+ }
677
+
613
678
pods := []v1.Pod {
614
679
util .NewPod ("default" , "foo" , v1 .PodRunning ),
615
680
util .NewPod ("testing" , "bar" , v1 .PodRunning ),
@@ -624,7 +689,7 @@ func (suite *Suite) setupWithPods(labelSelector labels.Selector, annotations lab
624
689
return chaoskube
625
690
}
626
691
627
- func (suite * Suite ) setup (labelSelector labels.Selector , annotations labels.Selector , namespaces 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 {
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 {
628
693
logOutput .Reset ()
629
694
630
695
client := fake .NewSimpleClientset ()
@@ -635,6 +700,7 @@ func (suite *Suite) setup(labelSelector labels.Selector, annotations labels.Sele
635
700
labelSelector ,
636
701
annotations ,
637
702
namespaces ,
703
+ namespaceLabels ,
638
704
includedPodNames ,
639
705
excludedPodNames ,
640
706
excludedWeekdays ,
@@ -738,6 +804,7 @@ func (suite *Suite) TestMinimumAge() {
738
804
labels .Everything (),
739
805
labels .Everything (),
740
806
labels .Everything (),
807
+ labels .Everything (),
741
808
& regexp.Regexp {},
742
809
& regexp.Regexp {},
743
810
[]time.Weekday {},
0 commit comments