forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
deployments.go
686 lines (571 loc) · 28.7 KB
/
deployments.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
package deployments
import (
"fmt"
"math/rand"
"strings"
"time"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
kapi "k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/labels"
"k8s.io/kubernetes/pkg/util/wait"
e2e "k8s.io/kubernetes/test/e2e/framework"
"github.com/openshift/origin/pkg/client"
deployapi "github.com/openshift/origin/pkg/deploy/api"
deployutil "github.com/openshift/origin/pkg/deploy/util"
exutil "github.com/openshift/origin/test/extended/util"
)
const deploymentRunTimeout = 5 * time.Minute
var _ = g.Describe("deploymentconfigs", func() {
defer g.GinkgoRecover()
var (
oc = exutil.NewCLI("cli-deployment", exutil.KubeConfigPath())
deploymentFixture = exutil.FixturePath("testdata", "test-deployment-test.yaml")
simpleDeploymentFixture = exutil.FixturePath("testdata", "deployment-simple.yaml")
customDeploymentFixture = exutil.FixturePath("testdata", "custom-deployment.yaml")
generationFixture = exutil.FixturePath("testdata", "generation-test.yaml")
pausedDeploymentFixture = exutil.FixturePath("testdata", "paused-deployment.yaml")
failedHookFixture = exutil.FixturePath("testdata", "failing-pre-hook.yaml")
brokenDeploymentFixture = exutil.FixturePath("testdata", "test-deployment-broken.yaml")
historyLimitedDeploymentFixture = exutil.FixturePath("testdata", "deployment-history-limit.yaml")
minReadySecondsFixture = exutil.FixturePath("testdata", "deployment-min-ready-seconds.yaml")
multipleICTFixture = exutil.FixturePath("testdata", "deployment-example.yaml")
tagImagesFixture = exutil.FixturePath("testdata", "tag-images-deployment.yaml")
)
g.Describe("when run iteratively", func() {
g.AfterEach(func() {
failureTrap(oc, "deployment-simple", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should only deploy the last deployment [Conformance]", func() {
_, err := oc.Run("create").Args("-f", simpleDeploymentFixture).Output()
o.Expect(err).NotTo(o.HaveOccurred())
iterations := 15
for i := 0; i < iterations; i++ {
if rand.Float32() < 0.2 {
time.Sleep(time.Duration(rand.Float32() * rand.Float32() * float32(time.Second)))
}
switch n := rand.Float32(); {
case n < 0.4:
// trigger a new deployment
e2e.Logf("%02d: triggering a new deployment with config change", i)
out, err := oc.Run("set", "env").Args("dc/deployment-simple", fmt.Sprintf("A=%d", i)).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("updated"))
case n < 0.7:
// cancel any running deployment
e2e.Logf("%02d: cancelling deployment", i)
if out, err := oc.Run("deploy").Args("dc/deployment-simple", "--cancel").Output(); err != nil {
// TODO: we should fix this
if !strings.Contains(out, "the object has been modified") {
o.Expect(err).NotTo(o.HaveOccurred())
}
e2e.Logf("--cancel deployment failed due to conflict: %v", err)
}
case n < 0.0:
// delete the deployer pod - disabled because it forces the system to wait for the sync loop
e2e.Logf("%02d: deleting one or more deployer pods", i)
_, rcs, pods, err := deploymentInfo(oc, "deployment-simple")
if err != nil {
e2e.Logf("%02d: unable to get deployment info: %v", i, err)
continue
}
all, err := deploymentPods(pods)
if err != nil {
e2e.Logf("%02d: unable to get deployment pods: %v", i, err)
continue
}
if len(all) == 0 {
e2e.Logf("%02d: no deployer pods", i)
continue
}
top := len(rcs) - 1
for j := top; i >= top-1 && j >= 0; j-- {
pods, ok := all[rcs[j].Name]
if !ok {
e2e.Logf("%02d: no deployer pod for rc %q", i, rcs[j].Name)
continue
}
for _, pod := range pods {
e2e.Logf("%02d: deleting deployer pod %s", i, pod.Name)
options := kapi.NewDeleteOptions(0)
if rand.Float32() < 0.5 {
options = nil
}
if err := oc.KubeREST().Pods(oc.Namespace()).Delete(pod.Name, options); err != nil {
e2e.Logf("%02d: unable to delete deployer pod %q: %v", i, pod.Name, err)
}
}
}
e2e.Logf("%02d: triggering a new deployment with config change", i)
out, err := oc.Run("set", "env").Args("dc/deployment-simple", fmt.Sprintf("A=%d", i)).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("updated"))
default:
// wait for the deployment to be running
e2e.Logf("%02d: waiting for current deployment to start running", i)
o.Expect(waitForLatestCondition(oc, "deployment-simple", deploymentRunTimeout, deploymentRunning)).NotTo(o.HaveOccurred())
}
}
// trigger one more deployment, just in case we cancelled the latest output
out, err := oc.Run("set", "env").Args("dc/deployment-simple", fmt.Sprintf("A=%d", iterations)).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("updated"))
g.By("verifying all but terminal deployment is marked complete")
o.Expect(waitForLatestCondition(oc, "deployment-simple", deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
})
g.It("should immediately start a new deployment [Conformance]", func() {
resource, name, err := createFixture(oc, simpleDeploymentFixture)
o.Expect(err).NotTo(o.HaveOccurred())
_, err = oc.Run("set", "env").Args(resource, "TRY=ONCE").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("by checking that the deployment config has the correct version"))
err = wait.PollImmediate(500*time.Millisecond, 5*time.Second, func() (bool, error) {
dc, _, _, err := deploymentInfo(oc, name)
if err != nil {
return false, nil
}
return dc.Status.LatestVersion == 2, nil
})
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("by checking that the second deployment exists"))
err = wait.PollImmediate(500*time.Millisecond, 30*time.Second, func() (bool, error) {
_, rcs, _, err := deploymentInfo(oc, name)
if err != nil {
return false, nil
}
secondDeploymentExists := false
for _, rc := range rcs {
if rc.Name == deployutil.DeploymentNameForConfigVersion(name, 2) {
secondDeploymentExists = true
break
}
}
return secondDeploymentExists, nil
})
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("by checking that the first deployer was deleted and the second deployer exists"))
err = wait.PollImmediate(500*time.Millisecond, 10*time.Second, func() (bool, error) {
_, _, pods, err := deploymentInfo(oc, name)
if err != nil {
return false, nil
}
deploymentNamesToDeployers, err := deploymentPods(pods)
if err != nil {
return false, nil
}
firstDeploymentName := deployutil.DeploymentNameForConfigVersion(name, 1)
firstDeployerRemoved := len(deploymentNamesToDeployers[firstDeploymentName]) == 0
secondDeploymentName := deployutil.DeploymentNameForConfigVersion(name, 2)
secondDeployerExists := len(deploymentNamesToDeployers[secondDeploymentName]) == 1
return firstDeployerRemoved && secondDeployerExists, nil
})
o.Expect(err).NotTo(o.HaveOccurred())
})
})
g.Describe("with test deployments", func() {
g.AfterEach(func() {
failureTrap(oc, "deployment-test", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should run a deployment to completion and then scale to zero [Conformance]", func() {
out, err := oc.Run("create").Args("-f", deploymentFixture).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, "deployment-test", deploymentRunTimeout, deploymentRunning)).NotTo(o.HaveOccurred())
out, err = oc.Run("logs").Args("-f", "dc/deployment-test").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the logs for substrings\n%s", out))
o.Expect(out).To(o.ContainSubstring("deployment-test-1 to 2"))
o.Expect(out).To(o.ContainSubstring("--> pre: Success"))
o.Expect(out).To(o.ContainSubstring("--> Success"))
g.By("verifying the deployment is marked complete and scaled to zero")
o.Expect(waitForLatestCondition(oc, "deployment-test", deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
g.By("verifying that scaling does not result in new pods")
out, err = oc.Run("scale").Args("dc/deployment-test", "--replicas=1").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("ensuring no scale up of the deployment happens")
wait.Poll(100*time.Millisecond, 10*time.Second, func() (bool, error) {
rc, err := oc.KubeREST().ReplicationControllers(oc.Namespace()).Get("deployment-test-1")
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(rc.Spec.Replicas).Should(o.BeEquivalentTo(0))
o.Expect(rc.Status.Replicas).Should(o.BeEquivalentTo(0))
return false, nil
})
g.By("verifying the scale is updated on the deployment config")
config, err := oc.REST().DeploymentConfigs(oc.Namespace()).Get("deployment-test")
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(config.Spec.Replicas).Should(o.BeEquivalentTo(1))
o.Expect(config.Spec.Test).Should(o.BeTrue())
g.By("deploying a few more times")
for i := 0; i < 3; i++ {
out, err = oc.Run("deploy").Args("--latest", "--follow", "deployment-test").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying the deployment is marked complete and scaled to zero")
o.Expect(waitForLatestCondition(oc, "deployment-test", deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the logs for substrings\n%s", out))
o.Expect(out).To(o.ContainSubstring(fmt.Sprintf("deployment-test-%d up to 1", i+2)))
o.Expect(out).To(o.ContainSubstring("--> pre: Success"))
o.Expect(out).To(o.ContainSubstring("test pre hook executed"))
o.Expect(out).To(o.ContainSubstring("--> Success"))
}
})
})
g.Describe("when tagging images", func() {
g.AfterEach(func() {
failureTrap(oc, "tag-images", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should successfully tag the deployed image [Conformance]", func() {
_, name, err := createFixture(oc, tagImagesFixture)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying the deployment is marked complete")
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
g.By("verifying the post deployment action happened: tag is set")
var out string
pollErr := wait.PollImmediate(100*time.Millisecond, 10*time.Second, func() (bool, error) {
out, err = oc.Run("get").Args("istag/sample-stream:deployed").Output()
if errors.IsNotFound(err) {
return false, nil
}
if err != nil {
return false, err
}
return true, nil
})
if pollErr == wait.ErrWaitTimeout {
pollErr = err
}
o.Expect(pollErr).NotTo(o.HaveOccurred())
if !strings.Contains(out, "origin-pod") {
err = fmt.Errorf("expected %q to be part of the image reference in %q", "origin-pod", out)
o.Expect(err).NotTo(o.HaveOccurred())
}
})
})
g.Describe("with multiple image change triggers", func() {
g.AfterEach(func() {
failureTrap(oc, "example", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should run a successful deployment [Conformance]", func() {
_, name, err := createFixture(oc, multipleICTFixture)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying the deployment is marked complete")
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
})
})
g.Describe("with enhanced status", func() {
g.AfterEach(func() {
failureTrap(oc, "deployment-simple", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should include various info in status [Conformance]", func() {
resource, name, err := createFixture(oc, simpleDeploymentFixture)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying the deployment is marked complete")
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
g.By("verifying that status.replicas is set")
replicas, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.replicas}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(replicas).To(o.ContainSubstring("2"))
g.By("verifying that status.updatedReplicas is set")
updatedReplicas, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.updatedReplicas}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(updatedReplicas).To(o.ContainSubstring("2"))
g.By("verifying that status.availableReplicas is set")
availableReplicas, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.availableReplicas}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(availableReplicas).To(o.ContainSubstring("2"))
g.By("verifying that status.unavailableReplicas is set")
unavailableReplicas, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.unavailableReplicas}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(unavailableReplicas).To(o.ContainSubstring("0"))
})
})
g.Describe("with custom deployments", func() {
g.AfterEach(func() {
failureTrap(oc, "custom-deployment", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should run the custom deployment steps [Conformance]", func() {
out, err := oc.Run("create").Args("-f", customDeploymentFixture).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, "custom-deployment", deploymentRunTimeout, deploymentRunning)).NotTo(o.HaveOccurred())
out, err = oc.Run("deploy").Args("--follow", "dc/custom-deployment").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying the deployment is marked complete")
o.Expect(waitForLatestCondition(oc, "custom-deployment", deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the logs for substrings\n%s", out))
o.Expect(out).To(o.ContainSubstring("--> pre: Running hook pod ..."))
o.Expect(out).To(o.ContainSubstring("test pre hook executed"))
o.Expect(out).To(o.ContainSubstring("--> Scaling custom-deployment-1 to 2"))
o.Expect(out).To(o.ContainSubstring("--> Reached 50%"))
o.Expect(out).To(o.ContainSubstring("Halfway"))
o.Expect(out).To(o.ContainSubstring("Finished"))
o.Expect(out).To(o.ContainSubstring("--> Success"))
})
})
g.Describe("viewing rollout history", func() {
g.AfterEach(func() {
failureTrap(oc, "deployment-simple", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should print the rollout history [Conformance]", func() {
resource, name, err := createFixture(oc, simpleDeploymentFixture)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
_, err = oc.REST().DeploymentConfigs(oc.Namespace()).Get(name)
o.Expect(err).NotTo(o.HaveOccurred())
_, err = client.UpdateConfigWithRetries(oc.REST(), oc.Namespace(), name, func(dc *deployapi.DeploymentConfig) {
one := int64(1)
dc.Spec.Template.Spec.TerminationGracePeriodSeconds = &one
})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
out, err := oc.Run("rollout").Args("history", resource).Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the history for substrings\n%s", out))
o.Expect(out).To(o.ContainSubstring("deploymentconfigs \"deployment-simple\" history viewed"))
o.Expect(out).To(o.ContainSubstring("REVISION STATUS CAUSE"))
o.Expect(out).To(o.ContainSubstring("1 Complete caused by a config change"))
o.Expect(out).To(o.ContainSubstring("2 Complete caused by a config change"))
})
})
g.Describe("generation", func() {
g.AfterEach(func() {
failureTrap(oc, "generation-test", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should deploy based on a status version bump [Conformance]", func() {
resource, name, err := createFixture(oc, generationFixture)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying that both latestVersion and generation are updated")
version, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
version = strings.Trim(version, "\"")
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the latest version for %s: %s", resource, version))
o.Expect(version).To(o.ContainSubstring("1"))
generation, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
o.Expect(generation).To(o.ContainSubstring("1"))
g.By("verifying the deployment is marked complete")
err = wait.Poll(100*time.Millisecond, 1*time.Minute, func() (bool, error) {
rc, err := oc.KubeREST().ReplicationControllers(oc.Namespace()).Get(name + "-" + version)
o.Expect(err).NotTo(o.HaveOccurred())
return deployutil.IsTerminatedDeployment(rc), nil
})
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying that scaling updates the generation")
_, err = oc.Run("scale").Args(resource, "--replicas=2").Output()
o.Expect(err).NotTo(o.HaveOccurred())
generation, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
o.Expect(generation).To(o.ContainSubstring("2"))
g.By("deploying a second time [new client]")
_, err = oc.Run("deploy").Args("--latest", name).Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying that both latestVersion and generation are updated")
version, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
version = strings.Trim(version, "\"")
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the latest version for %s: %s", resource, version))
o.Expect(version).To(o.ContainSubstring("2"))
generation, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.metadata.generation}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the generation for %s: %s", resource, generation))
o.Expect(generation).To(o.ContainSubstring("3"))
g.By("verifying that observedGeneration equals generation")
err = wait.Poll(1*time.Second, 1*time.Minute, func() (bool, error) {
dc, _, _, err := deploymentInfo(oc, name)
o.Expect(err).NotTo(o.HaveOccurred())
return deployutil.HasSynced(dc), nil
})
})
})
g.Describe("paused", func() {
g.AfterEach(func() {
failureTrap(oc, "paused", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should disable actions on deployments [Conformance]", func() {
resource, name, err := createFixture(oc, pausedDeploymentFixture)
o.Expect(err).NotTo(o.HaveOccurred())
_, rcs, _, err := deploymentInfo(oc, name)
o.Expect(err).NotTo(o.HaveOccurred())
if len(rcs) != 0 {
o.Expect(fmt.Errorf("expected no deployment, found %#v", rcs[0])).NotTo(o.HaveOccurred())
}
g.By("verifying that we cannot start a new deployment")
out, err := oc.Run("deploy").Args(resource, "--latest").Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("cannot deploy a paused deployment config"))
g.By("verifying that we cannot cancel a deployment")
out, err = oc.Run("deploy").Args(resource, "--cancel").Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("cannot cancel a paused deployment config"))
g.By("verifying that we cannot retry a deployment")
out, err = oc.Run("deploy").Args(resource, "--retry").Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("cannot retry a paused deployment config"))
g.By("verifying that we cannot rollback a deployment")
out, err = oc.Run("rollback").Args(resource, "--to-version", "1").Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("cannot rollback a paused deployment config"))
_, rcs, _, err = deploymentInfo(oc, name)
o.Expect(err).NotTo(o.HaveOccurred())
if len(rcs) != 0 {
o.Expect(fmt.Errorf("expected no deployment, found %#v", rcs[0])).NotTo(o.HaveOccurred())
}
_, err = client.UpdateConfigWithRetries(oc.REST(), oc.Namespace(), name, func(dc *deployapi.DeploymentConfig) {
// TODO: oc rollout pause should patch instead of making a full update
dc.Spec.Paused = false
})
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
})
})
g.Describe("with failing hook", func() {
g.AfterEach(func() {
failureTrap(oc, "hook", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should get all logs from retried hooks [Conformance]", func() {
resource, name, err := createFixture(oc, failedHookFixture)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentPreHookRetried)).NotTo(o.HaveOccurred())
out, err := oc.Run("logs").Args(resource).Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By(fmt.Sprintf("checking the logs for substrings\n%s", out))
o.Expect(out).To(o.ContainSubstring("--> pre: Running hook pod ..."))
o.Expect(out).To(o.ContainSubstring("no such file or directory"))
o.Expect(out).To(o.ContainSubstring("--> pre: Retrying hook pod (retry #1)"))
})
})
g.Describe("rolled back", func() {
g.AfterEach(func() {
failureTrap(oc, "deployment-simple", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should rollback to an older deployment [Conformance]", func() {
resource, name, err := createFixture(oc, simpleDeploymentFixture)
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
_, err = oc.Run("deploy").Args(name, "--latest").Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
g.By("verifying that we are on the second version")
version, err := oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
version = strings.Trim(version, "\"")
o.Expect(version).To(o.ContainSubstring("2"))
g.By("verifying that we can rollback")
_, err = oc.Run("rollout").Args("undo", resource).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred())
g.By("verifying that we are on the third version")
version, err = oc.Run("get").Args(resource, "--output=jsonpath=\"{.status.latestVersion}\"").Output()
o.Expect(err).NotTo(o.HaveOccurred())
version = strings.Trim(version, "\"")
o.Expect(version).To(o.ContainSubstring("3"))
})
})
g.Describe("reaper", func() {
g.AfterEach(func() {
failureTrap(oc, "brokendeployment", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should delete all failed deployer pods and hook pods [Conformance]", func() {
resource, name, err := createFixture(oc, brokenDeploymentFixture)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("waiting for the deployment to complete")
err = waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentReachedCompletion)
o.Expect(err).To(o.HaveOccurred())
g.By("fetching the deployer pod")
out, err := oc.Run("get").Args("pod", fmt.Sprintf("%s-1-deploy", name)).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("Error"))
g.By("fetching the pre-hook pod")
out, err = oc.Run("get").Args("pod", fmt.Sprintf("%s-1-hook-pre", name)).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("Error"))
g.By("deleting the deployment config")
out, err = oc.Run("delete").Args(resource).Output()
o.Expect(err).NotTo(o.HaveOccurred())
g.By("fetching the deployer pod")
out, err = oc.Run("get").Args("pod", fmt.Sprintf("%s-1-deploy", name)).Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("not found"))
g.By("fetching the pre-hook pod")
out, err = oc.Run("get").Args("pod", fmt.Sprintf("%s-1-hook-pre", name)).Output()
o.Expect(err).To(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("not found"))
})
})
g.Describe("with revision history limits", func() {
g.AfterEach(func() {
failureTrap(oc, "history-limit", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should never persist more old deployments than acceptable after being observed by the controller [Conformance]", func() {
revisionHistoryLimit := 3 // as specified in the fixture
_, err := oc.Run("create").Args("-f", historyLimitedDeploymentFixture).Output()
o.Expect(err).NotTo(o.HaveOccurred())
iterations := 10
for i := 0; i < iterations; i++ {
o.Expect(waitForLatestCondition(oc, "history-limit", deploymentRunTimeout, deploymentReachedCompletion)).NotTo(o.HaveOccurred(),
"the current deployment needs to have finished before attempting to trigger a new deployment through configuration change")
e2e.Logf("%02d: triggering a new deployment with config change", i)
out, err := oc.Run("set", "env").Args("dc/history-limit", fmt.Sprintf("A=%d", i)).Output()
o.Expect(err).NotTo(o.HaveOccurred())
o.Expect(out).To(o.ContainSubstring("updated"))
}
o.Expect(waitForLatestCondition(oc, "history-limit", deploymentRunTimeout, checkDeploymentConfigHasSynced)).NotTo(o.HaveOccurred(),
"the controller needs to have synced with the updated deployment configuration before checking that the revision history limits are being adhered to")
deploymentConfig, deployments, _, err := deploymentInfo(oc, "history-limit")
o.Expect(err).NotTo(o.HaveOccurred())
// sanity check to ensure that the following asertion on the amount of old deployments is valid
o.Expect(*deploymentConfig.Spec.RevisionHistoryLimit).To(o.Equal(int32(revisionHistoryLimit)))
// we need to filter out any deployments that we don't care about,
// namely the active deployment and any newer deployments
oldDeployments := deployutil.DeploymentsForCleanup(deploymentConfig, deployments)
// we should not have more deployments than acceptable
o.Expect(len(oldDeployments)).To(o.BeNumerically("==", revisionHistoryLimit))
// the deployments we continue to keep should be the latest ones
for _, deployment := range oldDeployments {
o.Expect(deployutil.DeploymentVersionFor(&deployment)).To(o.BeNumerically(">=", iterations-revisionHistoryLimit))
}
})
})
g.Describe("with minimum ready seconds set", func() {
g.AfterEach(func() {
failureTrap(oc, "minreadytest", g.CurrentGinkgoTestDescription().Failed)
})
g.It("should not transition the deployment to Complete before satisfied [Conformance]", func() {
_, name, err := createFixture(oc, minReadySecondsFixture)
o.Expect(err).NotTo(o.HaveOccurred())
g.By("verifying the deployment is marked running")
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentRunning)).NotTo(o.HaveOccurred())
g.By("verifying that all pods are ready")
config, err := oc.REST().DeploymentConfigs(oc.Namespace()).Get(name)
o.Expect(err).NotTo(o.HaveOccurred())
selector := labels.Set(config.Spec.Selector).AsSelector()
opts := kapi.ListOptions{LabelSelector: selector}
ready := 0
if err := wait.PollImmediate(500*time.Millisecond, 1*time.Minute, func() (bool, error) {
pods, err := oc.KubeREST().Pods(oc.Namespace()).List(opts)
if err != nil {
return false, nil
}
ready = 0
for i := range pods.Items {
pod := pods.Items[i]
if kapi.IsPodReady(&pod) {
ready++
}
}
return len(pods.Items) == ready, nil
}); err != nil {
o.Expect(fmt.Errorf("deployment config %q never became ready (ready: %d, desired: %d)",
config.Name, ready, config.Spec.Replicas)).NotTo(o.HaveOccurred())
}
g.By("verifying that the deployment is still running")
latestName := deployutil.DeploymentNameForConfigVersion(name, config.Status.LatestVersion)
latest, err := oc.KubeREST().ReplicationControllers(oc.Namespace()).Get(latestName)
o.Expect(err).NotTo(o.HaveOccurred())
if deployutil.IsTerminatedDeployment(latest) {
o.Expect(fmt.Errorf("expected deployment %q not to have terminated", latest.Name)).NotTo(o.HaveOccurred())
}
o.Expect(waitForLatestCondition(oc, name, deploymentRunTimeout, deploymentRunning)).NotTo(o.HaveOccurred())
})
})
})