@@ -28,6 +28,11 @@ const (
2828 nestedWorkName = "maestro-e2e-upgrade-test-work"
2929)
3030
31+ const (
32+ timeout = 2 * time .Minute
33+ polling = 10 * time .Second
34+ )
35+
3136var _ = Describe ("Upgrade Test" , Ordered , Label ("e2e-tests-upgrade" ), func () {
3237
3338 var deployWorkName string
@@ -38,62 +43,85 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
3843 deployClient := kubeClientSet .AppsV1 ().Deployments (namespace )
3944
4045 By ("create a deployment for readonly work" , func () {
41- _ , err := deployClient .Get (ctx , deployReadonlyName , metav1.GetOptions {})
42- if errors .IsNotFound (err ) {
43- deploy := utils .NewDeployment (namespace , deployReadonlyName , 0 )
44- _ , newErr := deployClient .Create (ctx , deploy , metav1.CreateOptions {})
45- Expect (newErr ).ShouldNot (HaveOccurred ())
46- } else {
47- Expect (err ).ShouldNot (HaveOccurred ())
48- }
46+ Eventually (func () error {
47+ _ , err := deployClient .Get (ctx , deployReadonlyName , metav1.GetOptions {})
48+ if errors .IsNotFound (err ) {
49+ deploy := utils .NewDeployment (namespace , deployReadonlyName , 0 )
50+ _ , newErr := deployClient .Create (ctx , deploy , metav1.CreateOptions {})
51+ return newErr
52+ }
53+ if err != nil {
54+ return err
55+ }
56+ return nil
57+ }).WithTimeout (timeout ).WithPolling (polling ).ShouldNot (HaveOccurred ())
4958 })
5059
5160 By ("create a work to apply a deployment" , func () {
5261 deploy := utils .NewDeployment (namespace , deployName , 0 )
5362 deployWorkName = utils .WorkName (utils .DeploymentGVK , deploy )
54- _ , err := workServerClient .Get (ctx , deployWorkName )
55- if errors .IsNotFound (err ) {
56- work , newErr := utils .NewManifestWork (utils .DeploymentGVK , utils .DeploymentGVR , deploy )
57- Expect (newErr ).ShouldNot (HaveOccurred ())
58-
59- work .Labels ["maestro.e2e.test.name" ] = "upgrade"
60- _ , newErr = workServerClient .Create (ctx , work )
61- Expect (newErr ).ShouldNot (HaveOccurred ())
62- } else {
63- Expect (err ).ShouldNot (HaveOccurred ())
64- }
63+
64+ Eventually (func () error {
65+ _ , err := workServerClient .Get (ctx , deployWorkName )
66+ if errors .IsNotFound (err ) {
67+ work , newErr := utils .NewManifestWork (utils .DeploymentGVK , utils .DeploymentGVR , deploy )
68+ if newErr != nil {
69+ return newErr
70+ }
71+
72+ work .Labels ["maestro.e2e.test.name" ] = "upgrade"
73+ _ , newErr = workServerClient .Create (ctx , work )
74+ return newErr
75+ }
76+ if err != nil {
77+ return err
78+ }
79+ return nil
80+ }).WithTimeout (timeout ).WithPolling (polling ).ShouldNot (HaveOccurred ())
6581 })
6682
6783 By ("create a readonly work to retrieve a deployment status" , func () {
6884 deployReadonly := utils .NewDeploymentReadonly (namespace , deployReadonlyName )
6985 deployReadonlyWorkName = utils .WorkName (utils .DeploymentGVK , deployReadonly )
70- _ , err := workServerClient .Get (ctx , deployReadonlyWorkName )
71- if errors .IsNotFound (err ) {
72- work , newErr := utils .NewManifestWork (utils .DeploymentGVK , utils .DeploymentGVR , deployReadonly )
73- Expect (newErr ).ShouldNot (HaveOccurred ())
74-
75- work .Labels ["maestro.e2e.test.name" ] = "upgrade"
76- _ , newErr = workServerClient .Create (ctx , work )
77- Expect (newErr ).ShouldNot (HaveOccurred ())
78- } else {
79- Expect (err ).ShouldNot (HaveOccurred ())
80- }
86+ Eventually (func () error {
87+ _ , err := workServerClient .Get (ctx , deployReadonlyWorkName )
88+ if errors .IsNotFound (err ) {
89+ work , newErr := utils .NewManifestWork (utils .DeploymentGVK , utils .DeploymentGVR , deployReadonly )
90+ if newErr != nil {
91+ return newErr
92+ }
93+
94+ work .Labels ["maestro.e2e.test.name" ] = "upgrade"
95+ _ , newErr = workServerClient .Create (ctx , work )
96+ return newErr
97+ }
98+ if err != nil {
99+ return err
100+ }
101+ return nil
102+ }).WithTimeout (timeout ).WithPolling (polling ).ShouldNot (HaveOccurred ())
81103 })
82104
83105 By ("create a work to apply a nested manifestwork" , func () {
84106 nestedWork := utils .NewDeploymentManifestWork (namespace , nestedWorkName )
85107 nestedWorkWorkName = utils .WorkName (utils .ManifestWorkGVK , nestedWork )
86- _ , err := workServerClient .Get (ctx , nestedWorkWorkName )
87- if errors .IsNotFound (err ) {
88- work , newErr := utils .NewManifestWork (utils .ManifestWorkGVK , utils .ManifestWorkGVR , nestedWork )
89- Expect (newErr ).ShouldNot (HaveOccurred ())
90-
91- work .Labels ["maestro.e2e.test.name" ] = "upgrade"
92- _ , newErr = workServerClient .Create (ctx , work )
93- Expect (newErr ).ShouldNot (HaveOccurred ())
94- } else {
95- Expect (err ).ShouldNot (HaveOccurred ())
96- }
108+ Eventually (func () error {
109+ _ , err := workServerClient .Get (ctx , nestedWorkWorkName )
110+ if errors .IsNotFound (err ) {
111+ work , newErr := utils .NewManifestWork (utils .ManifestWorkGVK , utils .ManifestWorkGVR , nestedWork )
112+ if newErr != nil {
113+ return newErr
114+ }
115+
116+ work .Labels ["maestro.e2e.test.name" ] = "upgrade"
117+ _ , newErr = workServerClient .Create (ctx , work )
118+ return newErr
119+ }
120+ if err != nil {
121+ return err
122+ }
123+ return nil
124+ }).WithTimeout (timeout ).WithPolling (polling ).ShouldNot (HaveOccurred ())
97125 })
98126 })
99127
@@ -114,7 +142,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
114142 lastGeneration = deploy .Generation
115143 lastReplicas = * deploy .Spec .Replicas
116144 return nil
117- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
145+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
118146 })
119147
120148 expectedReplicas = utils .UpdateReplicas (lastReplicas )
@@ -144,7 +172,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
144172 }
145173
146174 return nil
147- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
175+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
148176 })
149177
150178 By ("ensure the deployment is updated" , func () {
@@ -154,16 +182,16 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
154182 return err
155183 }
156184
157- if deploy .Generation != lastGeneration + 1 {
158- return fmt .Errorf ("expected generation %d , but got %d " , lastGeneration + 1 , deploy . Generation )
185+ if deploy .Generation == lastGeneration {
186+ return fmt .Errorf ("expected deployment %s updated , but failed " , deployName )
159187 }
160188
161189 if * deploy .Spec .Replicas != expectedReplicas {
162190 return fmt .Errorf ("expected replicas %d, but got %d" , expectedReplicas , * deploy .Spec .Replicas )
163191 }
164192
165193 return nil
166- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
194+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
167195 })
168196
169197 By ("ensure the deployment new status is watched" , func () {
@@ -173,7 +201,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
173201 return err
174202 }
175203 return AssertReplicas (watchedWork , expectedReplicas )
176- }, 5 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
204+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
177205 })
178206 })
179207
@@ -187,7 +215,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
187215 return err
188216 }
189217 return AssertStatusFeedbackSynced (watchedWork )
190- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
218+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
191219 })
192220
193221 By ("update the deployment" , func () {
@@ -208,7 +236,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
208236 }
209237
210238 return nil
211- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
239+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
212240
213241 })
214242
@@ -219,7 +247,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
219247 return err
220248 }
221249 return AssertReplicas (watchedWork , expectedReplicas )
222- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
250+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
223251 })
224252 })
225253
@@ -230,7 +258,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
230258 Eventually (func () error {
231259 _ , err := workClient .Get (ctx , nestedWorkName , metav1.GetOptions {})
232260 return err
233- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
261+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
234262 })
235263
236264 By ("update the nested work via work" , func () {
@@ -259,7 +287,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
259287 }
260288
261289 return nil
262- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
290+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
263291 })
264292
265293 By ("ensure the manifestwork new status is watched" , func () {
@@ -273,7 +301,7 @@ var _ = Describe("Upgrade Test", Ordered, Label("e2e-tests-upgrade"), func() {
273301 return err
274302 }
275303 return AssertNestedWorkAvailable (watchedWork )
276- }, 1 * time . Minute , 1 * time . Second ).ShouldNot (HaveOccurred ())
304+ }). WithTimeout ( timeout ). WithPolling ( polling ).ShouldNot (HaveOccurred ())
277305 })
278306 })
279307})
0 commit comments