@@ -20,6 +20,8 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
+ appsv1 "k8s.io/api/apps/v1"
24
+ e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
23
25
"math/rand"
24
26
"net"
25
27
"strconv"
@@ -655,23 +657,25 @@ func (j *TestJig) waitForCondition(ctx context.Context, timeout time.Duration, m
655
657
return service , nil
656
658
}
657
659
658
- // newRCTemplate returns the default v1.ReplicationController object for
659
- // this j, but does not actually create the RC. The default RC has the same
660
+ // newDeploymentTemplate returns the default appsv1.Deployment object for
661
+ // this j, but does not actually create the Deployment. The default Deployment has the same
660
662
// name as the j and runs the "netexec" container.
661
- func (j * TestJig ) newRCTemplate () * v1. ReplicationController {
663
+ func (j * TestJig ) newDeploymentTemplate () * appsv1. Deployment {
662
664
var replicas int32 = 1
663
665
var grace int64 = 3 // so we don't race with kube-proxy when scaling up/down
664
666
665
- rc := & v1. ReplicationController {
667
+ deployment := & appsv1. Deployment {
666
668
ObjectMeta : metav1.ObjectMeta {
667
669
Namespace : j .Namespace ,
668
670
Name : j .Name ,
669
671
Labels : j .Labels ,
670
672
},
671
- Spec : v1. ReplicationControllerSpec {
673
+ Spec : appsv1. DeploymentSpec {
672
674
Replicas : & replicas ,
673
- Selector : j .Labels ,
674
- Template : & v1.PodTemplateSpec {
675
+ Selector : & metav1.LabelSelector {
676
+ MatchLabels : j .Labels ,
677
+ },
678
+ Template : v1.PodTemplateSpec {
675
679
ObjectMeta : metav1.ObjectMeta {
676
680
Labels : j .Labels ,
677
681
},
@@ -697,32 +701,32 @@ func (j *TestJig) newRCTemplate() *v1.ReplicationController {
697
701
},
698
702
},
699
703
}
700
- return rc
704
+ return deployment
701
705
}
702
706
703
- // AddRCAntiAffinity adds AntiAffinity to the given ReplicationController .
704
- func (j * TestJig ) AddRCAntiAffinity ( rc * v1. ReplicationController ) {
707
+ // AddDeploymentAntiAffinity adds AntiAffinity to the given Deployment .
708
+ func (j * TestJig ) AddDeploymentAntiAffinity ( deployment * appsv1. Deployment ) {
705
709
var replicas int32 = 2
706
710
707
- rc .Spec .Replicas = & replicas
708
- if rc .Spec .Template .Spec .Affinity == nil {
709
- rc .Spec .Template .Spec .Affinity = & v1.Affinity {}
711
+ deployment .Spec .Replicas = & replicas
712
+ if deployment .Spec .Template .Spec .Affinity == nil {
713
+ deployment .Spec .Template .Spec .Affinity = & v1.Affinity {}
710
714
}
711
- if rc .Spec .Template .Spec .Affinity .PodAntiAffinity == nil {
712
- rc .Spec .Template .Spec .Affinity .PodAntiAffinity = & v1.PodAntiAffinity {}
715
+ if deployment .Spec .Template .Spec .Affinity .PodAntiAffinity == nil {
716
+ deployment .Spec .Template .Spec .Affinity .PodAntiAffinity = & v1.PodAntiAffinity {}
713
717
}
714
- rc .Spec .Template .Spec .Affinity .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution = append (
715
- rc .Spec .Template .Spec .Affinity .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution ,
718
+ deployment .Spec .Template .Spec .Affinity .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution = append (
719
+ deployment .Spec .Template .Spec .Affinity .PodAntiAffinity .RequiredDuringSchedulingIgnoredDuringExecution ,
716
720
v1.PodAffinityTerm {
717
721
LabelSelector : & metav1.LabelSelector {MatchLabels : j .Labels },
718
722
Namespaces : nil ,
719
723
TopologyKey : "kubernetes.io/hostname" ,
720
724
})
721
725
}
722
726
723
- // CreatePDB returns a PodDisruptionBudget for the given ReplicationController , or returns an error if a PodDisruptionBudget isn't ready
724
- func (j * TestJig ) CreatePDB (ctx context.Context , rc * v1. ReplicationController ) (* policyv1.PodDisruptionBudget , error ) {
725
- pdb := j .newPDBTemplate (rc )
727
+ // CreatePDB returns a PodDisruptionBudget for the given Deployment , or returns an error if a PodDisruptionBudget isn't ready
728
+ func (j * TestJig ) CreatePDB (ctx context.Context , deployment * appsv1. Deployment ) (* policyv1.PodDisruptionBudget , error ) {
729
+ pdb := j .newPDBTemplate (deployment )
726
730
newPdb , err := j .Client .PolicyV1 ().PodDisruptionBudgets (j .Namespace ).Create (ctx , pdb , metav1.CreateOptions {})
727
731
if err != nil {
728
732
return nil , fmt .Errorf ("failed to create PDB %q %v" , pdb .Name , err )
@@ -736,8 +740,8 @@ func (j *TestJig) CreatePDB(ctx context.Context, rc *v1.ReplicationController) (
736
740
737
741
// newPDBTemplate returns the default policyv1.PodDisruptionBudget object for
738
742
// this j, but does not actually create the PDB. The default PDB specifies a
739
- // MinAvailable of N-1 and matches the pods created by the RC .
740
- func (j * TestJig ) newPDBTemplate (rc * v1. ReplicationController ) * policyv1.PodDisruptionBudget {
743
+ // MinAvailable of N-1 and matches the pods created by the Deployment .
744
+ func (j * TestJig ) newPDBTemplate (rc * appsv1. Deployment ) * policyv1.PodDisruptionBudget {
741
745
minAvailable := intstr .FromInt32 (* rc .Spec .Replicas - 1 )
742
746
743
747
pdb := & policyv1.PodDisruptionBudget {
@@ -755,25 +759,25 @@ func (j *TestJig) newPDBTemplate(rc *v1.ReplicationController) *policyv1.PodDisr
755
759
return pdb
756
760
}
757
761
758
- // Run creates a ReplicationController and Pod(s) and waits for the
759
- // Pod(s) to be running. Callers can provide a function to tweak the RC object
762
+ // Run creates a Deployment and Pod(s) and waits for the
763
+ // Pod(s) to be running. Callers can provide a function to tweak the Deployment object
760
764
// before it is created.
761
- func (j * TestJig ) Run (ctx context.Context , tweak func (rc * v1. ReplicationController )) (* v1. ReplicationController , error ) {
762
- rc := j .newRCTemplate ()
765
+ func (j * TestJig ) Run (ctx context.Context , tweak func (rc * appsv1. Deployment )) (* appsv1. Deployment , error ) {
766
+ deployment := j .newDeploymentTemplate ()
763
767
if tweak != nil {
764
- tweak (rc )
768
+ tweak (deployment )
765
769
}
766
- result , err := j .Client .CoreV1 ().ReplicationControllers (j .Namespace ).Create (ctx , rc , metav1.CreateOptions {})
770
+
771
+ result , err := j .Client .AppsV1 ().Deployments (j .Namespace ).Create (ctx , deployment , metav1.CreateOptions {})
767
772
if err != nil {
768
- return nil , fmt .Errorf ("failed to create RC %q: %w" , rc .Name , err )
773
+ return nil , fmt .Errorf ("failed to create Deployment %q: %w" , deployment .Name , err )
769
774
}
770
- pods , err := j .waitForPodsCreated (ctx , int (* (rc .Spec .Replicas )))
775
+
776
+ err = e2edeployment .WaitForDeploymentComplete (j .Client , result )
771
777
if err != nil {
772
- return nil , fmt .Errorf ("failed to create pods: %w" , err )
773
- }
774
- if err := j .waitForPodsReady (ctx , pods ); err != nil {
775
- return nil , fmt .Errorf ("failed waiting for pods to be running: %w" , err )
778
+ return nil , fmt .Errorf ("failed waiting for Deployment %q: %w" , deployment .Name , err )
776
779
}
780
+
777
781
return result , nil
778
782
}
779
783
0 commit comments