@@ -14,8 +14,10 @@ import (
14
14
corev1 "k8s.io/api/core/v1"
15
15
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
16
16
apixv1beta1clientfake "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/fake"
17
+ policyv1beta1 "k8s.io/api/policy/v1beta1"
17
18
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
19
"k8s.io/apimachinery/pkg/runtime"
20
+ "k8s.io/apimachinery/pkg/util/intstr"
19
21
kubefake "k8s.io/client-go/kubernetes/fake"
20
22
"k8s.io/klog"
21
23
@@ -171,6 +173,57 @@ func TestGatherClusterPruner(t *testing.T) {
171
173
}
172
174
}
173
175
176
+ func TestGatherPodDisruptionBudgets (t * testing.T ){
177
+ coreClient := kubefake .NewSimpleClientset ()
178
+
179
+ fakeNamespace := "fake-namespace"
180
+
181
+ // name -> MinAvailabel
182
+ fakePDBs := map [string ]string {
183
+ "pdb-four" : "4" ,
184
+ "pdb-eight" : "8" ,
185
+ "pdb-ten" : "10" ,
186
+ }
187
+ for name , minAvailable := range fakePDBs {
188
+ _ , err := coreClient .PolicyV1beta1 ().
189
+ PodDisruptionBudgets (fakeNamespace ).
190
+ Create (& policyv1beta1.PodDisruptionBudget {
191
+ ObjectMeta : metav1.ObjectMeta {
192
+ Namespace : fakeNamespace ,
193
+ Name : name ,
194
+ },
195
+ Spec : policyv1beta1.PodDisruptionBudgetSpec {
196
+ MinAvailable : & intstr.IntOrString {StrVal : minAvailable },
197
+ },
198
+ })
199
+ if err != nil {
200
+ t .Fatalf ("unable to create fake pdbs: %v" , err )
201
+ }
202
+ }
203
+
204
+ gatherer := & Gatherer {policyClient : coreClient .PolicyV1beta1 ()}
205
+
206
+ records , errs := GatherPodDisruptionBudgets (gatherer )()
207
+ if len (errs ) > 0 {
208
+ t .Errorf ("unexpected errors: %#v" , errs )
209
+ return
210
+ }
211
+ if len (records ) != len (fakePDBs ) {
212
+ t .Fatalf ("unexpected number of records gathered: %d (expected %d)" , len (records ), len (fakePDBs ))
213
+ }
214
+ for _ , rec := range records {
215
+ pdba , ok := rec .Item .(PodDisruptionBudgetsAnonymizer )
216
+ if ! ok {
217
+ t .Fatal ("pdb item has invalid type" )
218
+ }
219
+ name := pdba .PodDisruptionBudget .ObjectMeta .Name
220
+ minAvailable := pdba .PodDisruptionBudget .Spec .MinAvailable .StrVal
221
+ if pdba .PodDisruptionBudget .Spec .MinAvailable .StrVal != fakePDBs [name ] {
222
+ t .Fatalf ("pdb item has mismatched MinAvailable value, %q != %q" , fakePDBs [name ], minAvailable )
223
+ }
224
+ }
225
+ }
226
+
174
227
func TestGatherClusterImageRegistry (t * testing.T ) {
175
228
tests := []struct {
176
229
name string
@@ -337,7 +390,6 @@ func TestGatherContainerImages(t *testing.T) {
337
390
}
338
391
339
392
coreClient := kubefake .NewSimpleClientset ()
340
-
341
393
for index , containerImage := range mockContainers {
342
394
_ , err := coreClient .CoreV1 ().
343
395
Pods (fakeNamespace ).
0 commit comments