@@ -41,6 +41,7 @@ import (
41
41
tracingconfig "knative.dev/pkg/tracing/config"
42
42
autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1"
43
43
defaultconfig "knative.dev/serving/pkg/apis/config"
44
+ "knative.dev/serving/pkg/apis/serving"
44
45
v1 "knative.dev/serving/pkg/apis/serving/v1"
45
46
"knative.dev/serving/pkg/autoscaler/config/autoscalerconfig"
46
47
servingclient "knative.dev/serving/pkg/client/injection/client"
@@ -544,7 +545,7 @@ func TestReconcile(t *testing.T) {
544
545
WithRoutingState (v1 .RoutingStateActive , fc ),
545
546
),
546
547
pa ("foo" , "pull-backoff" , WithReachabilityReachable ), // pa can't be ready since deployment times out.
547
- pod (t , "foo" , "pull-backoff" , WithWaitingContainer ("pull-backoff" , "ImagePullBackoff" , "can't pull it" )),
548
+ pod (t , "foo" , "pull-backoff" , WithPodCondition ( corev1 . PodReady , corev1 . ConditionFalse , "ContainersNotReady" ), WithWaitingContainer ("pull-backoff" , "ImagePullBackoff" , "can't pull it" )),
548
549
timeoutDeploy (deploy (t , "foo" , "pull-backoff" ), "Timed out!" ),
549
550
image ("foo" , "pull-backoff" ),
550
551
},
@@ -570,7 +571,7 @@ func TestReconcile(t *testing.T) {
570
571
WithRoutingState (v1 .RoutingStateActive , fc ),
571
572
WithLogURL , allUnknownConditions , MarkActive ),
572
573
pa ("foo" , "pod-error" , WithReachabilityReachable ), // PA can't be ready, since no traffic.
573
- pod (t , "foo" , "pod-error" , WithFailingContainer ("pod-error" , 5 , "I failed man!" )),
574
+ pod (t , "foo" , "pod-error" , WithPodCondition ( corev1 . PodReady , corev1 . ConditionFalse , "ContainersNotReady" ), WithFailingContainer ("pod-error" , 5 , "I failed man!" )),
574
575
deploy (t , "foo" , "pod-error" ),
575
576
image ("foo" , "pod-error" ),
576
577
},
@@ -742,6 +743,60 @@ func TestReconcile(t *testing.T) {
742
743
PodSpecPersistentVolumeClaim : defaultconfig .Enabled ,
743
744
PodSpecPersistentVolumeWrite : defaultconfig .Enabled ,
744
745
}}),
746
+ }, {
747
+ Name : "revision's ContainerHealthy turns back to True if the deployment is healthy" ,
748
+ Objects : []runtime.Object {
749
+ Revision ("foo" , "container-unhealthy" ,
750
+ WithLogURL ,
751
+ MarkRevisionReady ,
752
+ withDefaultContainerStatuses (),
753
+ WithRevisionLabel (serving .RoutingStateLabelKey , "active" ),
754
+ MarkContainerHealthyFalse ("ExitCode137" ),
755
+ ),
756
+ pa ("foo" , "container-unhealthy" ,
757
+ WithPASKSReady ,
758
+ WithScaleTargetInitialized ,
759
+ WithTraffic ,
760
+ WithReachabilityReachable ,
761
+ WithPAStatusService ("something" ),
762
+ ),
763
+ readyDeploy (deploy (t , "foo" , "container-unhealthy" , withReplicas (1 ))),
764
+ image ("foo" , "container-unhealthy" ),
765
+ },
766
+ Key : "foo/container-unhealthy" ,
767
+ WantStatusUpdates : []clientgotesting.UpdateActionImpl {{
768
+ Object : Revision ("foo" , "container-unhealthy" ,
769
+ WithLogURL ,
770
+ MarkRevisionReady ,
771
+ withDefaultContainerStatuses (),
772
+ WithRevisionLabel (serving .RoutingStateLabelKey , "active" ),
773
+ ),
774
+ }},
775
+ WantEvents : []string {
776
+ Eventf (corev1 .EventTypeNormal , "RevisionReady" , "Revision becomes ready upon all resources being ready" ),
777
+ },
778
+ }, {
779
+ Name : "revision's ContainerHealthy stays True even if the last Pod with restarts terminates" ,
780
+ Objects : []runtime.Object {
781
+ Revision ("foo" , "container-healthy" ,
782
+ WithLogURL ,
783
+ MarkRevisionReady ,
784
+ withDefaultContainerStatuses (),
785
+ WithRevisionLabel (serving .RoutingStateLabelKey , "active" ),
786
+ MarkContainerHealthyTrue (),
787
+ ),
788
+ pa ("foo" , "container-healthy" ,
789
+ WithPASKSReady ,
790
+ WithScaleTargetInitialized ,
791
+ WithTraffic ,
792
+ WithReachabilityReachable ,
793
+ WithPAStatusService ("something" ),
794
+ ),
795
+ WithDeletionTimestamp (pod (t , "foo" , "container-healthy" , WithPodCondition (corev1 .PodReady , corev1 .ConditionFalse , "ContainersNotReady" ), WithFailingContainer ("crashed-at-some-point" , 128 , "OOMKilled" ))),
796
+ readyDeploy (deploy (t , "foo" , "container-healthy" , withReplicas (0 ))),
797
+ image ("foo" , "container-healthy" ),
798
+ },
799
+ Key : "foo/container-healthy" ,
745
800
}}
746
801
747
802
table .Test (t , MakeFactory (func (ctx context.Context , listers * Listers , _ configmap.Watcher ) controller.Reconciler {
@@ -851,6 +906,19 @@ func allUnknownConditions(r *v1.Revision) {
851
906
852
907
type configOption func (* config.Config )
853
908
909
+ type deploymentOption func (* appsv1.Deployment )
910
+
911
+ // withReplicas configures the number of replicas on the Deployment
912
+ func withReplicas (replicas int32 ) deploymentOption {
913
+ return func (d * appsv1.Deployment ) {
914
+ d .Spec .Replicas = & replicas
915
+ d .Status .AvailableReplicas = replicas
916
+ d .Status .ReadyReplicas = replicas
917
+ d .Status .Replicas = replicas
918
+ d .Status .UpdatedReplicas = replicas
919
+ }
920
+ }
921
+
854
922
func deploy (t * testing.T , namespace , name string , opts ... interface {}) * appsv1.Deployment {
855
923
t .Helper ()
856
924
cfg := reconcilerTestConfig ()
@@ -876,6 +944,13 @@ func deploy(t *testing.T, namespace, name string, opts ...interface{}) *appsv1.D
876
944
if err != nil {
877
945
t .Fatal ("failed to create deployment" )
878
946
}
947
+
948
+ for _ , opt := range opts {
949
+ if deploymentOpt , ok := opt .(deploymentOption ); ok {
950
+ deploymentOpt (deployment )
951
+ }
952
+ }
953
+
879
954
return deployment
880
955
}
881
956
0 commit comments