@@ -41,6 +41,7 @@ import (
4141 tracingconfig "knative.dev/pkg/tracing/config"
4242 autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1"
4343 defaultconfig "knative.dev/serving/pkg/apis/config"
44+ "knative.dev/serving/pkg/apis/serving"
4445 v1 "knative.dev/serving/pkg/apis/serving/v1"
4546 "knative.dev/serving/pkg/autoscaler/config/autoscalerconfig"
4647 servingclient "knative.dev/serving/pkg/client/injection/client"
@@ -544,7 +545,7 @@ func TestReconcile(t *testing.T) {
544545 WithRoutingState (v1 .RoutingStateActive , fc ),
545546 ),
546547 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" )),
548549 timeoutDeploy (deploy (t , "foo" , "pull-backoff" ), "Timed out!" ),
549550 image ("foo" , "pull-backoff" ),
550551 },
@@ -570,7 +571,7 @@ func TestReconcile(t *testing.T) {
570571 WithRoutingState (v1 .RoutingStateActive , fc ),
571572 WithLogURL , allUnknownConditions , MarkActive ),
572573 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!" )),
574575 deploy (t , "foo" , "pod-error" ),
575576 image ("foo" , "pod-error" ),
576577 },
@@ -742,6 +743,60 @@ func TestReconcile(t *testing.T) {
742743 PodSpecPersistentVolumeClaim : defaultconfig .Enabled ,
743744 PodSpecPersistentVolumeWrite : defaultconfig .Enabled ,
744745 }}),
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" ,
745800 }}
746801
747802 table .Test (t , MakeFactory (func (ctx context.Context , listers * Listers , _ configmap.Watcher ) controller.Reconciler {
@@ -851,6 +906,19 @@ func allUnknownConditions(r *v1.Revision) {
851906
852907type configOption func (* config.Config )
853908
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+
854922func deploy (t * testing.T , namespace , name string , opts ... interface {}) * appsv1.Deployment {
855923 t .Helper ()
856924 cfg := reconcilerTestConfig ()
@@ -876,6 +944,13 @@ func deploy(t *testing.T, namespace, name string, opts ...interface{}) *appsv1.D
876944 if err != nil {
877945 t .Fatal ("failed to create deployment" )
878946 }
947+
948+ for _ , opt := range opts {
949+ if deploymentOpt , ok := opt .(deploymentOption ); ok {
950+ deploymentOpt (deployment )
951+ }
952+ }
953+
879954 return deployment
880955}
881956
0 commit comments