Skip to content

Commit 2fc98c9

Browse files
committed
feat: bubble up kcert status message when it's failed
1 parent a1ad60a commit 2fc98c9

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

pkg/apis/serving/v1/route_lifecycle.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ func (rs *RouteStatus) MarkMissingTrafficTarget(kind, name string) {
160160
// MarkCertificateProvisionFailed marks the
161161
// RouteConditionCertificateProvisioned condition to indicate that the
162162
// Certificate provisioning failed.
163-
func (rs *RouteStatus) MarkCertificateProvisionFailed(name string) {
163+
func (rs *RouteStatus) MarkCertificateProvisionFailed(c *v1alpha1.Certificate) {
164+
certificateCondition := c.Status.GetCondition(apis.ConditionReady)
164165
routeCondSet.Manage(rs).MarkFalse(RouteConditionCertificateProvisioned,
165166
"CertificateProvisionFailed",
166-
"Certificate %s fails to be provisioned.", name)
167+
"Certificate %s fails to be provisioned: %s", c.Name, certificateCondition.GetReason())
167168
}
168169

169170
// MarkCertificateReady marks the RouteConditionCertificateProvisioned

pkg/apis/serving/v1/route_lifecycle_test.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ func TestCertificateNotReadyWithBubbledUpMessage(t *testing.T) {
451451
Conditions: duckv1.Conditions{
452452
{
453453
Type: "Ready",
454-
Status: "False",
455-
Reason: "CommonName Too Long",
454+
Status: "Unknown",
455+
Reason: "The ready condition of Cert Manager Certificate does not exist.",
456456
},
457457
},
458458
},
@@ -463,7 +463,7 @@ func TestCertificateNotReadyWithBubbledUpMessage(t *testing.T) {
463463
r.InitializeConditions()
464464
r.MarkCertificateNotReady(cert)
465465

466-
expectedCertMessage := "CommonName Too Long"
466+
expectedCertMessage := "The ready condition of Cert Manager Certificate does not exist."
467467
certMessage := r.Status.GetCondition("Ready").Message
468468
if !strings.Contains(certMessage, expectedCertMessage) {
469469
t.Errorf("Literal %q not found in status message: %q", expectedCertMessage, certMessage)
@@ -473,11 +473,37 @@ func TestCertificateNotReadyWithBubbledUpMessage(t *testing.T) {
473473
func TestCertificateProvisionFailed(t *testing.T) {
474474
r := &RouteStatus{}
475475
r.InitializeConditions()
476-
r.MarkCertificateProvisionFailed("cert")
476+
r.MarkCertificateProvisionFailed(&netv1alpha1.Certificate{})
477477

478478
apistest.CheckConditionFailed(r, RouteConditionCertificateProvisioned, t)
479479
}
480480

481+
func TestCertificateFailedWithBubbledUpMessage(t *testing.T) {
482+
cert := &netv1alpha1.Certificate{
483+
Status: netv1alpha1.CertificateStatus{
484+
Status: duckv1.Status{
485+
Conditions: duckv1.Conditions{
486+
{
487+
Type: "Ready",
488+
Status: "False",
489+
Reason: "CommonName Too Long",
490+
},
491+
},
492+
},
493+
},
494+
}
495+
496+
r := &RouteStatus{}
497+
r.InitializeConditions()
498+
r.MarkCertificateProvisionFailed(cert)
499+
500+
expectedCertMessage := "CommonName Too Long"
501+
certMessage := r.Status.GetCondition("Ready").Message
502+
if !strings.Contains(certMessage, expectedCertMessage) {
503+
t.Errorf("Literal %q not found in status message: %q", expectedCertMessage, certMessage)
504+
}
505+
}
506+
481507
func TestRouteNotOwnCertificate(t *testing.T) {
482508
r := &RouteStatus{}
483509
r.InitializeConditions()

pkg/reconciler/route/route.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (c *Reconciler) externalDomainTLS(ctx context.Context, host string, r *v1.R
239239
if kaccessor.IsNotOwned(err) {
240240
r.Status.MarkCertificateNotOwned(desiredCert.Name)
241241
} else {
242-
r.Status.MarkCertificateProvisionFailed(desiredCert.Name)
242+
r.Status.MarkCertificateProvisionFailed(desiredCert)
243243
}
244244
return nil, nil, err
245245
}
@@ -274,7 +274,11 @@ func (c *Reconciler) externalDomainTLS(ctx context.Context, host string, r *v1.R
274274
tls = append(tls, resources.MakeIngressTLS(cert, sets.List(dnsNames)))
275275
} else {
276276
acmeChallenges = append(acmeChallenges, cert.Status.HTTP01Challenges...)
277-
r.Status.MarkCertificateNotReady(cert)
277+
if cert.IsFailed() {
278+
r.Status.MarkCertificateProvisionFailed(cert)
279+
} else {
280+
r.Status.MarkCertificateNotReady(cert)
281+
}
278282
// When httpProtocol is enabled, downgrade http scheme.
279283
// Explicitly not using the override settings here as to not to muck with
280284
// external-domain-tls semantics.
@@ -320,7 +324,7 @@ func (c *Reconciler) clusterLocalDomainTLS(ctx context.Context, r *v1.Route, tc
320324
if kaccessor.IsNotOwned(err) {
321325
r.Status.MarkCertificateNotOwned(desiredCert.Name)
322326
} else {
323-
r.Status.MarkCertificateProvisionFailed(desiredCert.Name)
327+
r.Status.MarkCertificateProvisionFailed(desiredCert)
324328
}
325329
return nil, err
326330
}
@@ -336,6 +340,8 @@ func (c *Reconciler) clusterLocalDomainTLS(ctx context.Context, r *v1.Route, tc
336340

337341
r.Status.MarkCertificateReady(cert.Name)
338342
tls = append(tls, resources.MakeIngressTLS(cert, sets.List(localDomains)))
343+
} else if cert.IsFailed() {
344+
r.Status.MarkCertificateProvisionFailed(cert)
339345
} else {
340346
r.Status.MarkCertificateNotReady(cert)
341347
}

0 commit comments

Comments
 (0)