@@ -20,8 +20,6 @@ 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"
25
23
"math/rand"
26
24
"net"
27
25
"strconv"
@@ -30,26 +28,27 @@ import (
30
28
"time"
31
29
32
30
"github.com/onsi/ginkgo/v2"
31
+ appsv1 "k8s.io/api/apps/v1"
33
32
v1 "k8s.io/api/core/v1"
34
33
discoveryv1 "k8s.io/api/discovery/v1"
35
34
policyv1 "k8s.io/api/policy/v1"
36
35
apierrors "k8s.io/apimachinery/pkg/api/errors"
37
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
38
- "k8s.io/apimachinery/pkg/labels"
39
37
"k8s.io/apimachinery/pkg/util/intstr"
40
38
utilnet "k8s.io/apimachinery/pkg/util/net"
41
39
"k8s.io/apimachinery/pkg/util/sets"
42
40
"k8s.io/apimachinery/pkg/util/uuid"
43
41
"k8s.io/apimachinery/pkg/util/wait"
44
42
clientset "k8s.io/client-go/kubernetes"
45
43
"k8s.io/kubernetes/test/e2e/framework"
44
+ e2edeployment "k8s.io/kubernetes/test/e2e/framework/deployment"
46
45
e2enode "k8s.io/kubernetes/test/e2e/framework/node"
47
- e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
48
46
e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
49
47
e2erc "k8s.io/kubernetes/test/e2e/framework/rc"
50
48
testutils "k8s.io/kubernetes/test/utils"
51
49
imageutils "k8s.io/kubernetes/test/utils/image"
52
50
netutils "k8s.io/utils/net"
51
+ "k8s.io/utils/ptr"
53
52
)
54
53
55
54
// NodePortRange should match whatever the default/configured range is
@@ -782,26 +781,20 @@ func (j *TestJig) Run(ctx context.Context, tweak func(rc *appsv1.Deployment)) (*
782
781
}
783
782
784
783
// Scale scales pods to the given replicas
785
- func (j * TestJig ) Scale (ctx context.Context , replicas int ) error {
786
- rc := j .Name
787
- scale , err := j .Client .CoreV1 ().ReplicationControllers (j .Namespace ).GetScale (ctx , rc , metav1.GetOptions {})
784
+ func (j * TestJig ) Scale (replicas int ) error {
785
+ deployment , err := e2edeployment .UpdateDeploymentWithRetries (j .Client , j .Namespace , j .Name , func (deployment * appsv1.Deployment ) {
786
+ deployment .Spec .Replicas = ptr .To (int32 (replicas ))
787
+ })
788
788
if err != nil {
789
- return fmt .Errorf ("failed to get scale for RC %q: %w" , rc , err )
789
+ return fmt .Errorf ("failed to scale Deployment %q: %w" , j . Name , err )
790
790
}
791
791
792
- scale .ResourceVersion = "" // indicate the scale update should be unconditional
793
- scale .Spec .Replicas = int32 (replicas )
794
- _ , err = j .Client .CoreV1 ().ReplicationControllers (j .Namespace ).UpdateScale (ctx , rc , scale , metav1.UpdateOptions {})
795
- if err != nil {
796
- return fmt .Errorf ("failed to scale RC %q: %w" , rc , err )
797
- }
798
- pods , err := j .waitForPodsCreated (ctx , replicas )
792
+ err = e2edeployment .WaitForDeploymentComplete (j .Client , deployment )
793
+
799
794
if err != nil {
800
- return fmt .Errorf ("failed waiting for pods: %w" , err )
801
- }
802
- if err := j .waitForPodsReady (ctx , pods ); err != nil {
803
- return fmt .Errorf ("failed waiting for pods to be running: %w" , err )
795
+ return fmt .Errorf ("failed waiting for Deployment %q: %w" , j .Name , err )
804
796
}
797
+
805
798
return nil
806
799
}
807
800
@@ -820,43 +813,6 @@ func (j *TestJig) waitForPdbReady(ctx context.Context) error {
820
813
return fmt .Errorf ("timeout waiting for PDB %q to be ready" , j .Name )
821
814
}
822
815
823
- func (j * TestJig ) waitForPodsCreated (ctx context.Context , replicas int ) ([]string , error ) {
824
- // TODO (pohly): replace with gomega.Eventually
825
- timeout := 2 * time .Minute
826
- // List the pods, making sure we observe all the replicas.
827
- label := labels .SelectorFromSet (labels .Set (j .Labels ))
828
- framework .Logf ("Waiting up to %v for %d pods to be created" , timeout , replicas )
829
- for start := time .Now (); time .Since (start ) < timeout && ctx .Err () == nil ; time .Sleep (2 * time .Second ) {
830
- options := metav1.ListOptions {LabelSelector : label .String ()}
831
- pods , err := j .Client .CoreV1 ().Pods (j .Namespace ).List (ctx , options )
832
- if err != nil {
833
- return nil , err
834
- }
835
-
836
- found := []string {}
837
- for _ , pod := range pods .Items {
838
- if pod .DeletionTimestamp != nil {
839
- continue
840
- }
841
- found = append (found , pod .Name )
842
- }
843
- if len (found ) == replicas {
844
- framework .Logf ("Found all %d pods" , replicas )
845
- return found , nil
846
- }
847
- framework .Logf ("Found %d/%d pods - will retry" , len (found ), replicas )
848
- }
849
- return nil , fmt .Errorf ("timeout waiting for %d pods to be created" , replicas )
850
- }
851
-
852
- func (j * TestJig ) waitForPodsReady (ctx context.Context , pods []string ) error {
853
- timeout := 2 * time .Minute
854
- if ! e2epod .CheckPodsRunningReady (ctx , j .Client , j .Namespace , pods , timeout ) {
855
- return fmt .Errorf ("timeout waiting for %d pods to be ready" , len (pods ))
856
- }
857
- return nil
858
- }
859
-
860
816
func testReachabilityOverServiceName (ctx context.Context , serviceName string , sp v1.ServicePort , execPod * v1.Pod ) error {
861
817
return testEndpointReachability (ctx , serviceName , sp .Port , sp .Protocol , execPod )
862
818
}
0 commit comments