@@ -346,32 +346,9 @@ var _ = framework.KubeDescribe("Cluster size autoscaling [Slow]", func() {
346
346
})
347
347
348
348
simpleScaleDownTest := func (unready int ) {
349
- // This is a temporary fix to allow CA to migrate some kube-system pods
350
- // TODO: Remove this when the PDB is added for those components
351
- By ("Create PodDisruptionBudgets for kube-system components, so they can be migrated if required" )
352
- pdbsToAdd := []string {"kube-dns-autoscaler" , "kube-dns" }
353
- for _ , pdbLabel := range pdbsToAdd {
354
- By (fmt .Sprintf ("Create PodDisruptionBudget for %v" , pdbLabel ))
355
- labelMap := map [string ]string {"k8s-app" : pdbLabel }
356
- pdbName := fmt .Sprintf ("test-pdb-for-%v" , pdbLabel )
357
- minAvailable := intstr .FromInt (1 )
358
- pdb := & policy.PodDisruptionBudget {
359
- ObjectMeta : metav1.ObjectMeta {
360
- Name : pdbName ,
361
- Namespace : "kube-system" ,
362
- },
363
- Spec : policy.PodDisruptionBudgetSpec {
364
- Selector : & metav1.LabelSelector {MatchLabels : labelMap },
365
- MinAvailable : & minAvailable ,
366
- },
367
- }
368
- _ , err := f .StagingClient .Policy ().PodDisruptionBudgets ("kube-system" ).Create (pdb )
369
-
370
- defer func () {
371
- f .StagingClient .Policy ().PodDisruptionBudgets ("kube-system" ).Delete (pdbName , & metav1.DeleteOptions {})
372
- }()
373
- framework .ExpectNoError (err )
374
- }
349
+ cleanup , err := addKubeSystemPdbs (f )
350
+ defer cleanup ()
351
+ framework .ExpectNoError (err )
375
352
376
353
By ("Manually increase cluster size" )
377
354
increasedSize := 0
@@ -1088,3 +1065,49 @@ func waitForScaleUpStatus(c clientset.Interface, expected string, timeout time.D
1088
1065
}
1089
1066
return nil , fmt .Errorf ("ScaleUp status did not reach expected value: %v" , expected )
1090
1067
}
1068
+
1069
+ // This is a temporary fix to allow CA to migrate some kube-system pods
1070
+ // TODO: Remove this when the PDB is added for those components
1071
+ func addKubeSystemPdbs (f * framework.Framework ) (func (), error ) {
1072
+ By ("Create PodDisruptionBudgets for kube-system components, so they can be migrated if required" )
1073
+
1074
+ newPdbs := make ([]string , 0 )
1075
+ cleanup := func () {
1076
+ for _ , newPdbName := range newPdbs {
1077
+ f .StagingClient .Policy ().PodDisruptionBudgets ("kube-system" ).Delete (newPdbName , & metav1.DeleteOptions {})
1078
+ }
1079
+ }
1080
+
1081
+ type pdbInfo struct {
1082
+ label string
1083
+ min_available int
1084
+ }
1085
+ pdbsToAdd := []pdbInfo {
1086
+ {label : "kube-dns-autoscaler" , min_available : 1 },
1087
+ {label : "kube-dns" , min_available : 1 },
1088
+ {label : "event-exporter" , min_available : 0 },
1089
+ }
1090
+ for _ , pdbData := range pdbsToAdd {
1091
+ By (fmt .Sprintf ("Create PodDisruptionBudget for %v" , pdbData .label ))
1092
+ labelMap := map [string ]string {"k8s-app" : pdbData .label }
1093
+ pdbName := fmt .Sprintf ("test-pdb-for-%v" , pdbData .label )
1094
+ minAvailable := intstr .FromInt (pdbData .min_available )
1095
+ pdb := & policy.PodDisruptionBudget {
1096
+ ObjectMeta : metav1.ObjectMeta {
1097
+ Name : pdbName ,
1098
+ Namespace : "kube-system" ,
1099
+ },
1100
+ Spec : policy.PodDisruptionBudgetSpec {
1101
+ Selector : & metav1.LabelSelector {MatchLabels : labelMap },
1102
+ MinAvailable : & minAvailable ,
1103
+ },
1104
+ }
1105
+ _ , err := f .StagingClient .Policy ().PodDisruptionBudgets ("kube-system" ).Create (pdb )
1106
+ newPdbs = append (newPdbs , pdbName )
1107
+
1108
+ if err != nil {
1109
+ return cleanup , err
1110
+ }
1111
+ }
1112
+ return cleanup , nil
1113
+ }
0 commit comments