Skip to content

Commit

Permalink
Bubble up KCertificate Status Message when its not ready (#14496)
Browse files Browse the repository at this point in the history
* basic change done kcert error bubbling up correctly, still need to fail when url is too long

* Update pkg/apis/serving/v1/route_lifecycle.go

Co-authored-by: Dave Protasowski <dprotaso@gmail.com>

---------

Co-authored-by: Dave Protasowski <dprotaso@gmail.com>
  • Loading branch information
gabo1208 and dprotaso committed Oct 20, 2023
1 parent 2c0b8dc commit f69766c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pkg/apis/serving/v1/route_lifecycle.go
Expand Up @@ -174,10 +174,11 @@ func (rs *RouteStatus) MarkCertificateReady(name string) {

// MarkCertificateNotReady marks the RouteConditionCertificateProvisioned
// condition to indicate that the Certificate is not ready.
func (rs *RouteStatus) MarkCertificateNotReady(name string) {
func (rs *RouteStatus) MarkCertificateNotReady(c *v1alpha1.Certificate) {
certificateCondition := c.Status.GetCondition("Ready")
routeCondSet.Manage(rs).MarkUnknown(RouteConditionCertificateProvisioned,
"CertificateNotReady",
"Certificate %s is not ready.", name)
"Certificate %s is not ready: %s", c.Name, certificateCondition.GetReason())
}

// MarkCertificateNotOwned changes the RouteConditionCertificateProvisioned
Expand Down
29 changes: 28 additions & 1 deletion pkg/apis/serving/v1/route_lifecycle_test.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1

import (
"strings"
"testing"
"time"

Expand Down Expand Up @@ -438,11 +439,37 @@ func TestCertificateReady(t *testing.T) {
func TestCertificateNotReady(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
r.MarkCertificateNotReady("cert")
r.MarkCertificateNotReady(&netv1alpha1.Certificate{})

apistest.CheckConditionOngoing(r, RouteConditionCertificateProvisioned, t)
}

func TestCertificateNotReadyWithBubbledUpMessage(t *testing.T) {
cert := &netv1alpha1.Certificate{
Status: netv1alpha1.CertificateStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{
{
Type: "Ready",
Status: "False",
Reason: "CommonName Too Long",
},
},
},
},
}

r := &RouteStatus{}
r.InitializeConditions()
r.MarkCertificateNotReady(cert)

expectedCertMessage := "CommonName Too Long"
certMessage := r.Status.GetCondition("Ready").Message
if !strings.Contains(certMessage, expectedCertMessage) {
t.Errorf("Literal %q not found in status message: %q", expectedCertMessage, certMessage)
}
}

func TestCertificateProvisionFailed(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/route/route.go
Expand Up @@ -265,7 +265,7 @@ func (c *Reconciler) tls(ctx context.Context, host string, r *v1.Route, traffic
tls = append(tls, resources.MakeIngressTLS(cert, dnsNames.List()))
} else {
acmeChallenges = append(acmeChallenges, cert.Status.HTTP01Challenges...)
r.Status.MarkCertificateNotReady(cert.Name)
r.Status.MarkCertificateNotReady(cert)
// When httpProtocol is enabled, downgrade http scheme.
// Explicitly not using the override settings here as to not to muck with
// external-domain-tls semantics.
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/v1/route.go
Expand Up @@ -208,7 +208,7 @@ func MarkUnknownTrafficError(msg string) RouteOption {

// MarkCertificateNotReady calls the method of the same name on .Status
func MarkCertificateNotReady(r *v1.Route) {
r.Status.MarkCertificateNotReady(routenames.Certificate(r))
r.Status.MarkCertificateNotReady(&netv1alpha1.Certificate{})
}

// MarkCertificateNotOwned calls the method of the same name on .Status
Expand Down

0 comments on commit f69766c

Please sign in to comment.