1
1
package deployments
2
2
3
3
import (
4
+ //"errors"
4
5
"fmt"
5
6
"math/rand"
6
7
"strings"
@@ -9,11 +10,11 @@ import (
9
10
g "github.com/onsi/ginkgo"
10
11
o "github.com/onsi/gomega"
11
12
12
- "k8s.io/apimachinery/pkg/api/errors"
13
+ kerrors "k8s.io/apimachinery/pkg/api/errors"
13
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
14
- "k8s.io/apimachinery/pkg/labels"
15
15
"k8s.io/apimachinery/pkg/types"
16
16
"k8s.io/apimachinery/pkg/util/wait"
17
+ "k8s.io/apimachinery/pkg/watch"
17
18
kapiv1 "k8s.io/kubernetes/pkg/api/v1"
18
19
kcontroller "k8s.io/kubernetes/pkg/controller"
19
20
e2e "k8s.io/kubernetes/test/e2e/framework"
@@ -382,7 +383,7 @@ var _ = g.Describe("deploymentconfigs", func() {
382
383
var istag * imageapi.ImageStreamTag
383
384
pollErr := wait .PollImmediate (100 * time .Millisecond , 1 * time .Minute , func () (bool , error ) {
384
385
istag , err = oc .Client ().ImageStreamTags (oc .Namespace ()).Get ("sample-stream" , "deployed" )
385
- if errors .IsNotFound (err ) {
386
+ if kerrors .IsNotFound (err ) {
386
387
return false , nil
387
388
}
388
389
if err != nil {
@@ -882,53 +883,85 @@ var _ = g.Describe("deploymentconfigs", func() {
882
883
})
883
884
884
885
g .Describe ("with minimum ready seconds set [Conformance]" , func () {
886
+ dc := readDCFixtureOrDie (minReadySecondsFixture )
887
+ rcName := func (i int ) string { return fmt .Sprintf ("%s-%d" , dc .Name , i ) }
885
888
g .AfterEach (func () {
886
- failureTrap (oc , "minreadytest" , g .CurrentGinkgoTestDescription ().Failed )
889
+ failureTrap (oc , dc . Name , g .CurrentGinkgoTestDescription ().Failed )
887
890
})
888
891
889
892
g .It ("should not transition the deployment to Complete before satisfied" , func () {
890
- _ , name , err := createFixture (oc , minReadySecondsFixture )
893
+ namespace := oc .Namespace ()
894
+ watcher , err := oc .KubeClient ().CoreV1 ().ReplicationControllers (namespace ).Watch (metav1 .SingleObject (metav1.ObjectMeta {Name : rcName (1 ), ResourceVersion : "" }))
891
895
o .Expect (err ).NotTo (o .HaveOccurred ())
892
896
893
- g .By ("verifying the deployment is marked running" )
894
- o .Expect (waitForLatestCondition (oc , name , deploymentRunTimeout , deploymentRunning )).NotTo (o .HaveOccurred ())
897
+ o .Expect (dc .Spec .Triggers ).To (o .BeNil ())
898
+ // FIXME: remove when tests are migrated to the new client
899
+ // (the old one incorrectly translates nil into an empty array)
900
+ dc .Spec .Triggers = append (dc .Spec .Triggers , deployapi.DeploymentTriggerPolicy {Type : deployapi .DeploymentTriggerOnConfigChange })
901
+ dc , err = oc .Client ().DeploymentConfigs (namespace ).Create (dc )
902
+
903
+ g .By ("verifying the deployment is created" )
904
+ rcEvent , err := watch .Until (deploymentChangeTimeout , watcher , func (event watch.Event ) (bool , error ) {
905
+ if event .Type == watch .Added {
906
+ return true , nil
907
+ }
908
+ return false , fmt .Errorf ("different kind of event appeared while waiting for Added event: %#v" , event )
909
+ })
910
+ o .Expect (err ).NotTo (o .HaveOccurred ())
911
+ rc1 := rcEvent .Object .(* kapiv1.ReplicationController )
895
912
896
913
g .By ("verifying that all pods are ready" )
897
- config , err := oc .Client ().DeploymentConfigs (oc .Namespace ()).Get (name , metav1.GetOptions {})
914
+ rc1 , err = waitForRCModification (oc , namespace , rc1 .Name , deploymentRunTimeout ,
915
+ rc1 .GetResourceVersion (), func (rc * kapiv1.ReplicationController ) (bool , error ) {
916
+ return rc .Status .ReadyReplicas == dc .Spec .Replicas , nil
917
+ })
898
918
o .Expect (err ).NotTo (o .HaveOccurred ())
919
+ o .Expect (rc1 .Status .AvailableReplicas ).To (o .BeZero ())
899
920
900
- selector := labels .Set (config .Spec .Selector ).AsSelector ()
901
- opts := metav1.ListOptions {LabelSelector : selector .String ()}
902
- ready := 0
903
- if err := wait .PollImmediate (500 * time .Millisecond , 3 * time .Minute , func () (bool , error ) {
904
- pods , err := oc .KubeClient ().CoreV1 ().Pods (oc .Namespace ()).List (opts )
905
- if err != nil {
906
- return false , nil
907
- }
921
+ g .By ("verifying that the deployment is still running" )
922
+ o .Expect (err ).NotTo (o .HaveOccurred ())
923
+ if deployutil .IsTerminatedDeployment (rc1 ) {
924
+ o .Expect (fmt .Errorf ("expected deployment %q not to have terminated" , rc1 .Name )).NotTo (o .HaveOccurred ())
925
+ }
908
926
909
- ready = 0
910
- for i := range pods .Items {
911
- pod := pods .Items [i ]
912
- if kapiv1 .IsPodReady (& pod ) {
913
- ready ++
927
+ g .By ("waiting for the deployment to finish" )
928
+ rc1 , err = waitForRCModification (oc , namespace , rc1 .Name ,
929
+ deploymentChangeTimeout + time .Duration (dc .Spec .MinReadySeconds )* 10 * time .Second ,
930
+ rc1 .GetResourceVersion (), func (rc * kapiv1.ReplicationController ) (bool , error ) {
931
+ if rc .Status .AvailableReplicas == dc .Spec .Replicas {
932
+ return true , nil
914
933
}
915
- }
916
-
917
- return len (pods .Items ) == ready , nil
918
- }); err != nil {
919
- o .Expect (fmt .Errorf ("deployment config %q never became ready (ready: %d, desired: %d)" ,
920
- config .Name , ready , config .Spec .Replicas )).NotTo (o .HaveOccurred ())
921
- }
922
934
923
- g .By ("verifying that the deployment is still running" )
924
- latestName := deployutil .DeploymentNameForConfigVersion (name , config .Status .LatestVersion )
925
- latest , err := oc .InternalKubeClient ().Core ().ReplicationControllers (oc .Namespace ()).Get (latestName , metav1.GetOptions {})
935
+ // FIXME: There is a race between deployer pod updating phase and RC updating AvailableReplicas
936
+ // FIXME: Enable this when we switch pod acceptors to use RC AvailableReplicas with MinReadySecondsSet
937
+ //if deployutil.DeploymentStatusFor(rc) == deployapi.DeploymentStatusComplete {
938
+ // e2e.Logf("Failed RC: %#v", rc)
939
+ // return false, errors.New("deployment shouldn't be completed before ReadyReplicas become AvailableReplicas")
940
+ //}
941
+ return false , nil
942
+ })
926
943
o .Expect (err ).NotTo (o .HaveOccurred ())
927
-
928
- if deployutil .IsTerminatedDeployment (latest ) {
929
- o .Expect (fmt .Errorf ("expected deployment %q not to have terminated" , latest .Name )).NotTo (o .HaveOccurred ())
944
+ o .Expect (rc1 .Status .AvailableReplicas ).To (o .Equal (dc .Spec .Replicas ))
945
+ // FIXME: There is a race between deployer pod updating phase and RC updating AvailableReplicas
946
+ // FIXME: Enable this when we switch pod acceptors to use RC AvailableReplicas with MinReadySecondsSet
947
+ //// Deployment status can't be updated yet but should be right after
948
+ //o.Expect(deployutil.DeploymentStatusFor(rc1)).To(o.Equal(deployapi.DeploymentStatusRunning))
949
+ // It should finish right after
950
+ // FIXME: remove this condition when the above is fixed
951
+ if deployutil .DeploymentStatusFor (rc1 ) != deployapi .DeploymentStatusComplete {
952
+ // FIXME: remove this assertion when the above is fixed
953
+ o .Expect (deployutil .DeploymentStatusFor (rc1 )).To (o .Equal (deployapi .DeploymentStatusRunning ))
954
+ rc1 , err = waitForRCModification (oc , namespace , rc1 .Name , deploymentChangeTimeout ,
955
+ rc1 .GetResourceVersion (), func (rc * kapiv1.ReplicationController ) (bool , error ) {
956
+ return deployutil .DeploymentStatusFor (rc ) == deployapi .DeploymentStatusComplete , nil
957
+ })
958
+ o .Expect (err ).NotTo (o .HaveOccurred ())
930
959
}
931
- o .Expect (waitForLatestCondition (oc , name , deploymentRunTimeout , deploymentRunning )).NotTo (o .HaveOccurred ())
960
+
961
+ // We might check that minReadySecond passed between pods becoming ready
962
+ // and available but I don't think there is a way to get a timestamp from events
963
+ // and other ways are just flaky.
964
+ // But since we are reusing MinReadySeconds and AvailableReplicas from RC it should be tested there
932
965
})
933
966
})
934
967
0 commit comments