@@ -15,18 +15,21 @@ package e2e
15
15
16
16
import (
17
17
"context"
18
+ "fmt"
18
19
"testing"
19
20
"time"
20
21
22
+ "github.com/google/go-cmp/cmp/cmpopts"
21
23
"github.com/onsi/ginkgo/v2"
22
24
"github.com/onsi/gomega"
25
+ appsv1 "k8s.io/api/apps/v1"
26
+ corev1 "k8s.io/api/core/v1"
23
27
"k8s.io/apimachinery/pkg/types"
24
28
"k8s.io/client-go/kubernetes/scheme"
25
29
"sigs.k8s.io/controller-runtime/pkg/client"
26
30
"sigs.k8s.io/controller-runtime/pkg/client/config"
27
31
28
32
jobset "sigs.k8s.io/jobset/api/jobset/v1alpha2"
29
- testutils "sigs.k8s.io/jobset/pkg/util/testing"
30
33
//+kubebuilder:scaffold:imports
31
34
)
32
35
@@ -59,27 +62,34 @@ var _ = ginkgo.BeforeSuite(func() {
59
62
gomega .Expect (err ).NotTo (gomega .HaveOccurred ())
60
63
gomega .Expect (k8sClient ).NotTo (gomega .BeNil ())
61
64
62
- JobSetReadyForTesting (k8sClient )
65
+ jobSetReadyForTesting (k8sClient )
63
66
})
64
67
65
- func JobSetReadyForTesting ( client client.Client ) {
68
+ func jobSetReadyForTesting ( k8sClient client.Client ) {
66
69
ginkgo .By ("waiting for resources to be ready for testing" )
67
- // To verify that webhooks are ready, let's create a simple jobset.
68
- js := testutils .MakeJobSet ("js" , "default" ).
69
- ReplicatedJob (testutils .MakeReplicatedJob ("rjob" ).
70
- Job (testutils .MakeJobTemplate ("job" , "default" ).
71
- PodSpec (testutils .TestPodSpec ).Obj ()).
72
- Obj ()).Obj ()
73
-
74
- // Once the creation succeeds, that means the webhooks are ready
75
- // and we can begin testing.
76
- gomega .Eventually (func () error {
77
- return client .Create (context .Background (), js )
70
+ deploymentKey := types.NamespacedName {Namespace : "jobset-system" , Name : "jobset-controller-manager" }
71
+ deployment := & appsv1.Deployment {}
72
+ pods := & corev1.PodList {}
73
+ gomega .Eventually (func (g gomega.Gomega ) error {
74
+ // Get controller-manager deployment.
75
+ g .Expect (k8sClient .Get (ctx , deploymentKey , deployment )).To (gomega .Succeed ())
76
+ // Get pods matches for controller-manager deployment.
77
+ g .Expect (k8sClient .List (ctx , pods , client .InNamespace (deploymentKey .Namespace ), client .MatchingLabels (deployment .Spec .Selector .MatchLabels ))).To (gomega .Succeed ())
78
+ for _ , pod := range pods .Items {
79
+ for _ , cs := range pod .Status .ContainerStatuses {
80
+ // To make sure that we don't have restarts of controller-manager.
81
+ // If we have that's mean that something went wrong, and there is
82
+ // no needs to continue trying check availability.
83
+ if cs .RestartCount > 0 {
84
+ return gomega .StopTrying (fmt .Sprintf ("%q in %q has restarted %d times" , cs .Name , pod .Name , cs .RestartCount ))
85
+ }
86
+ }
87
+ }
88
+ // To verify that webhooks are ready, checking is deployment have condition Available=True.
89
+ g .Expect (deployment .Status .Conditions ).To (gomega .ContainElement (gomega .BeComparableTo (
90
+ appsv1.DeploymentCondition {Type : appsv1 .DeploymentAvailable , Status : corev1 .ConditionTrue },
91
+ cmpopts .IgnoreFields (appsv1.DeploymentCondition {}, "Reason" , "Message" , "LastUpdateTime" , "LastTransitionTime" )),
92
+ ))
93
+ return nil
78
94
}, timeout , interval ).Should (gomega .Succeed ())
79
-
80
- // Delete this jobset before beginning tests.
81
- gomega .Expect (client .Delete (ctx , js ))
82
- gomega .Eventually (func () error {
83
- return client .Get (ctx , types.NamespacedName {Name : js .Name , Namespace : js .Namespace }, & jobset.JobSet {})
84
- }).ShouldNot (gomega .Succeed ())
85
95
}
0 commit comments