Skip to content

Commit

Permalink
Ensure ContainerHealthy condition is set back to True
Browse files Browse the repository at this point in the history
Co-authored-by: Matthias Diester <[email protected]>
  • Loading branch information
SaschaSchwarze0 and HeavyWombat committed Sep 9, 2024
1 parent 0824bd4 commit 1e89b8d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/reconciler/revision/reconcile_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ func (c *Reconciler) reconcileDeployment(ctx context.Context, rev *v1.Revision)
}
}

if *deployment.Spec.Replicas > 0 && *deployment.Spec.Replicas == deployment.Status.ReadyReplicas {
rev.Status.MarkContainerHealthyTrue()
}

return nil
}

Expand Down
53 changes: 53 additions & 0 deletions pkg/reconciler/revision/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
tracingconfig "knative.dev/pkg/tracing/config"
autoscalingv1alpha1 "knative.dev/serving/pkg/apis/autoscaling/v1alpha1"
defaultconfig "knative.dev/serving/pkg/apis/config"
"knative.dev/serving/pkg/apis/serving"
v1 "knative.dev/serving/pkg/apis/serving/v1"
"knative.dev/serving/pkg/autoscaler/config/autoscalerconfig"
servingclient "knative.dev/serving/pkg/client/injection/client"
Expand Down Expand Up @@ -742,6 +743,38 @@ func TestReconcile(t *testing.T) {
PodSpecPersistentVolumeClaim: defaultconfig.Enabled,
PodSpecPersistentVolumeWrite: defaultconfig.Enabled,
}}),
}, {
Name: "revision's ContainerHealthy turns back to True if the deployment is healthy",
Objects: []runtime.Object{
Revision("foo", "container-unhealthy",
WithLogURL,
MarkRevisionReady,
withDefaultContainerStatuses(),
WithRevisionLabel(serving.RoutingStateLabelKey, "active"),
MarkContainerHealthyFalse("ExitCode137"),
),
pa("foo", "container-unhealthy",
WithPASKSReady,
WithScaleTargetInitialized,
WithTraffic,
WithReachabilityReachable,
WithPAStatusService("something"),
),
readyDeploy(deploy(t, "foo", "container-unhealthy", withReplicas(1))),
image("foo", "container-unhealthy"),
},
Key: "foo/container-unhealthy",
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: Revision("foo", "container-unhealthy",
WithLogURL,
MarkRevisionReady,
withDefaultContainerStatuses(),
WithRevisionLabel(serving.RoutingStateLabelKey, "active"),
),
}},
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "RevisionReady", "Revision becomes ready upon all resources being ready"),
},
}}

table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, _ configmap.Watcher) controller.Reconciler {
Expand Down Expand Up @@ -851,6 +884,19 @@ func allUnknownConditions(r *v1.Revision) {

type configOption func(*config.Config)

type deploymentOption func(*appsv1.Deployment)

// withReplicas configures the number of replicas on the Deployment
func withReplicas(replicas int32) deploymentOption {
return func(d *appsv1.Deployment) {
d.Spec.Replicas = &replicas
d.Status.AvailableReplicas = replicas
d.Status.ReadyReplicas = replicas
d.Status.Replicas = replicas
d.Status.UpdatedReplicas = replicas
}
}

func deploy(t *testing.T, namespace, name string, opts ...interface{}) *appsv1.Deployment {
t.Helper()
cfg := reconcilerTestConfig()
Expand All @@ -876,6 +922,13 @@ func deploy(t *testing.T, namespace, name string, opts ...interface{}) *appsv1.D
if err != nil {
t.Fatal("failed to create deployment")
}

for _, opt := range opts {
if deploymentOpt, ok := opt.(deploymentOption); ok {
deploymentOpt(deployment)
}
}

return deployment
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/testing/v1/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ func MarkContainerHealthyUnknown(reason string) RevisionOption {
}
}

func MarkContainerHealthyFalse(reason string) RevisionOption {
return func(r *v1.Revision) {
r.Status.MarkContainerHealthyFalse(reason, "")
}
}

// MarkProgressDeadlineExceeded calls the method of the same name on the Revision
// with the message we expect the Revision Reconciler to pass.
func MarkProgressDeadlineExceeded(message string) RevisionOption {
Expand Down

0 comments on commit 1e89b8d

Please sign in to comment.