Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkg/apis/serving/v1alpha1/revision_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ func (rs *RevisionStatus) MarkProgressDeadlineExceeded(message string) {
revCondSet.Manage(rs).MarkFalse(RevisionConditionResourcesAvailable, "ProgressDeadlineExceeded", message)
}

// MarkNoDeployment changes the "ResourcesAvailable" condition to false to reflect that the
// deployment has already been created, and replica is failed to be created
func (rs *RevisionStatus) MarkNoDeployment(message string) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Golint comments: exported method RevisionStatus.MarkNoDeployment should have comment or be unexported. More info.

revCondSet.Manage(rs).MarkFalse(RevisionConditionResourcesAvailable, "NoDeployment", message)
}

func (rs *RevisionStatus) MarkContainerHealthy() {
revCondSet.Manage(rs).MarkTrue(RevisionConditionContainerHealthy)
}
Expand Down
27 changes: 23 additions & 4 deletions pkg/apis/serving/v1alpha1/revision_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ import (

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
apitest "knative.dev/pkg/apis/testing"
net "github.com/knative/serving/pkg/apis/networking"
"github.com/knative/serving/pkg/apis/serving"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/pkg/apis"
"knative.dev/pkg/apis/duck"
duckv1beta1 "knative.dev/pkg/apis/duck/v1beta1"
apitest "knative.dev/pkg/apis/testing"
)

func TestRevisionDuckTypes(t *testing.T) {
Expand Down Expand Up @@ -380,6 +380,25 @@ func TestRevisionResourcesUnavailable(t *testing.T) {
}
}

func TestRevisionNoDeployment(t *testing.T) {
r := &RevisionStatus{}
r.InitializeConditions()
apitest.CheckConditionOngoing(r.duck(), RevisionConditionResourcesAvailable, t)
apitest.CheckConditionOngoing(r.duck(), RevisionConditionContainerHealthy, t)
apitest.CheckConditionOngoing(r.duck(), RevisionConditionReady, t)

const want = "the error message"
r.MarkNoDeployment(want)
apitest.CheckConditionFailed(r.duck(), RevisionConditionResourcesAvailable, t)
apitest.CheckConditionFailed(r.duck(), RevisionConditionReady, t)
if got := r.GetCondition(RevisionConditionResourcesAvailable); got == nil || got.Message != want {
t.Errorf("MarkNoDeployment = %v, want %v", got, want)
}
if got := r.GetCondition(RevisionConditionReady); got == nil || got.Message != want {
t.Errorf("MarkNoDeployment = %v, want %v", got, want)
}
}

func TestRevisionGetGroupVersionKind(t *testing.T) {
r := &Revision{}
want := schema.GroupVersionKind{
Expand Down
17 changes: 17 additions & 0 deletions pkg/reconciler/revision/reconcile_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ func (c *Reconciler) reconcileDeployment(ctx context.Context, rev *v1alpha1.Revi
}
}

if hasDeploymentReplicaFailure(deployment) && !rev.Status.IsActivationRequired() {
rev.Status.MarkNoDeployment(fmt.Sprintf(
"The controller could not create a deployment named %s.", deployment.Name))
c.Recorder.Eventf(rev, corev1.EventTypeNormal, "NoDeployment",
"Revision %s not ready because replica is failed to be created", rev.Name)
}

// Now that we have a Deployment, determine whether there is any relevant
// status to surface in the Revision.
if hasDeploymentTimedOut(deployment) && !rev.Status.IsActivationRequired() {
Expand Down Expand Up @@ -196,6 +203,16 @@ func (c *Reconciler) reconcilePA(ctx context.Context, rev *v1alpha1.Revision) er
return nil
}

func hasDeploymentReplicaFailure(deployment *appsv1.Deployment) bool {
for _, cond := range deployment.Status.Conditions {
// with Type ReplicaFailure and Reason FailedCreate
if cond.Type == appsv1.DeploymentReplicaFailure && cond.Reason == "FailedCreate" {
return true
}
}
return false
}

func hasDeploymentTimedOut(deployment *appsv1.Deployment) bool {
// as per https://kubernetes.io/docs/concepts/workloads/controllers/deployment
for _, cond := range deployment.Status.Conditions {
Expand Down
29 changes: 29 additions & 0 deletions pkg/reconciler/revision/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,26 @@ func TestReconcile(t *testing.T) {
"deploy-timeout"),
},
Key: "foo/deploy-timeout",
}, {
Name: "surface deployment replica failure",
// Test the propagation of replica failure from Deployment.
Objects: []runtime.Object{
rev("foo", "deploy-replica-failure",
withK8sServiceName("the-taxman"), WithLogURL, MarkActive),
kpa("foo", "deploy-replica-failure"),
replicaFailureDeploy(deploy("foo", "deploy-replica-failure")),
image("foo", "deploy-replica-failure"),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: rev("foo", "deploy-replica-failure",
WithLogURL, AllUnknownConditions,
MarkNoDeployment("The controller could not create a deployment named deploy-replica-failure-deployment.")),
}},
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "NoDeployment", "Revision %s not ready because replica is failed to be created",
"deploy-replica-failure"),
},
Key: "foo/deploy-replica-failure",
}, {
Name: "surface ImagePullBackoff",
// Test the propagation of ImagePullBackoff from user container.
Expand Down Expand Up @@ -545,6 +565,15 @@ func TestReconcile(t *testing.T) {
}))
}

func replicaFailureDeploy(deploy *appsv1.Deployment) *appsv1.Deployment {
deploy.Status.Conditions = []appsv1.DeploymentCondition{{
Type: appsv1.DeploymentReplicaFailure,
Status: corev1.ConditionTrue,
Reason: "FailedCreate",
}}
return deploy
}

func timeoutDeploy(deploy *appsv1.Deployment) *appsv1.Deployment {
deploy.Status.Conditions = []appsv1.DeploymentCondition{{
Type: appsv1.DeploymentProgressing,
Expand Down
7 changes: 7 additions & 0 deletions pkg/testing/v1alpha1/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ func MarkContainerExiting(exitCode int32, message string) RevisionOption {
}
}

// MarkNoDeployment calls .Status.MarkNoDeployment on the Revision
func MarkNoDeployment(message string) RevisionOption {
return func(r *v1alpha1.Revision) {
r.Status.MarkNoDeployment(message)
}
}

// MarkResourcesUnavailable calls .Status.MarkResourcesUnavailable on the Revision.
func MarkResourcesUnavailable(reason, message string) RevisionOption {
return func(r *v1alpha1.Revision) {
Expand Down