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