Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate status from KCert to Route #7163

Merged
merged 13 commits into from
May 20, 2020
55 changes: 27 additions & 28 deletions pkg/apis/serving/v1/route_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
var routeCondSet = apis.NewLivingConditionSet(
RouteConditionAllTrafficAssigned,
RouteConditionIngressReady,
RouteConditionCertificateProvisioned,
)

// GetGroupVersionKind returns the GroupVersionKind.
Expand Down Expand Up @@ -99,43 +100,41 @@ func (rs *RouteStatus) MarkMissingTrafficTarget(kind, name string) {
}

func (rs *RouteStatus) MarkCertificateProvisionFailed(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionFalse,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateProvisionFailed",
Message: fmt.Sprintf("Certificate %s fails to be provisioned.", name),
})
routeCondSet.Manage(rs).MarkFalse(RouteConditionCertificateProvisioned,
"CertificateProvisionFailed",
"Certificate %s fails to be provisioned.", name)
}

func (rs *RouteStatus) MarkCertificateReady(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionTrue,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateReady",
Message: fmt.Sprintf("Certificate %s is successfully provisioned", name),
})
routeCondSet.Manage(rs).MarkTrue(RouteConditionCertificateProvisioned)
}

func (rs *RouteStatus) MarkCertificateNotReady(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionUnknown,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateNotReady",
Message: fmt.Sprintf("Certificate %s is not ready.", name),
})
routeCondSet.Manage(rs).MarkUnknown(RouteConditionCertificateProvisioned,
"CertificateNotReady",
"Certificate %s is not ready.", name)
}

func (rs *RouteStatus) MarkCertificateNotOwned(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionFalse,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateNotOwned",
Message: fmt.Sprintf("There is an existing certificate %s that we don't own.", name),
})
routeCondSet.Manage(rs).MarkFalse(RouteConditionCertificateProvisioned,
"CertificateNotOwned",
"There is an existing certificate %s that we don't own.", name)
}

// MarkAutoTLSNotEnabled sets RouteConditionCertificateProvisioned to true when
// certificate config such as autoTLS is not enabled.
func (rs *RouteStatus) MarkAutoTLSNotEnabled() {
routeCondSet.Manage(rs).MarkTrueWithReason(RouteConditionCertificateProvisioned,
"AutoTLSNotEnabled",
"autoTLS is not enabled")
}

// MarkHTTPDowngrade sets RouteConditionCertificateProvisioned to true when plain
// HTTP is enabled even when Certificated is not ready.
func (rs *RouteStatus) MarkHTTPDowngrade(name string) {
routeCondSet.Manage(rs).MarkTrueWithReason(RouteConditionCertificateProvisioned,
"HTTPDowngrade",
"Certificate %s is not ready downgrade HTTP.", name)
}

// PropagateIngressStatus update RouteConditionIngressReady condition
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/serving/v1/route_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ func TestTypicalRouteFlow(t *testing.T) {
apistest.CheckConditionOngoing(r, RouteConditionReady, t)

r.MarkTrafficAssigned()
r.MarkAutoTLSNotEnabled()
apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t)
apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t)
apistest.CheckConditionOngoing(r, RouteConditionReady, t)
Expand Down Expand Up @@ -281,6 +282,7 @@ func TestIngressFailureRecovery(t *testing.T) {
apistest.CheckConditionOngoing(r, RouteConditionReady, t)

r.MarkTrafficAssigned()
r.MarkAutoTLSNotEnabled()
r.PropagateIngressStatus(netv1alpha1.IngressStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Expand Down Expand Up @@ -372,6 +374,22 @@ func TestRouteNotOwnCertificate(t *testing.T) {
apistest.CheckConditionFailed(r, RouteConditionCertificateProvisioned, t)
}

func TestRouteAutoTLSNotEnabled(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
r.MarkAutoTLSNotEnabled()

apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

func TestRouteHTTPDowngrade(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
r.MarkHTTPDowngrade("cert")

apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

func TestIngressNotConfigured(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
Expand Down
55 changes: 27 additions & 28 deletions pkg/apis/serving/v1alpha1/route_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
var routeCondSet = apis.NewLivingConditionSet(
RouteConditionAllTrafficAssigned,
RouteConditionIngressReady,
RouteConditionCertificateProvisioned,
)

func (r *Route) GetGroupVersionKind() schema.GroupVersionKind {
Expand Down Expand Up @@ -112,43 +113,41 @@ func (rs *RouteStatus) MarkMissingTrafficTarget(kind, name string) {
}

func (rs *RouteStatus) MarkCertificateProvisionFailed(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionFalse,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateProvisionFailed",
Message: fmt.Sprintf("Certificate %s fails to be provisioned.", name),
})
routeCondSet.Manage(rs).MarkFalse(RouteConditionCertificateProvisioned,
"CertificateProvisionFailed",
"Certificate %s fails to be provisioned.", name)
}

func (rs *RouteStatus) MarkCertificateReady(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionTrue,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateReady",
Message: fmt.Sprintf("Certificate %s is successfully provisioned", name),
})
routeCondSet.Manage(rs).MarkTrue(RouteConditionCertificateProvisioned)
}

func (rs *RouteStatus) MarkCertificateNotReady(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionUnknown,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateNotReady",
Message: fmt.Sprintf("Certificate %s is not ready.", name),
})
routeCondSet.Manage(rs).MarkUnknown(RouteConditionCertificateProvisioned,
"CertificateNotReady",
"Certificate %s is not ready.", name)
}

func (rs *RouteStatus) MarkCertificateNotOwned(name string) {
routeCondSet.Manage(rs).SetCondition(apis.Condition{
Type: RouteConditionCertificateProvisioned,
Status: corev1.ConditionFalse,
Severity: apis.ConditionSeverityWarning,
Reason: "CertificateNotOwned",
Message: fmt.Sprintf("There is an existing certificate %s that we don't own.", name),
})
routeCondSet.Manage(rs).MarkFalse(RouteConditionCertificateProvisioned,
"CertificateNotOwned",
"There is an existing certificate %s that we don't own.", name)
}

// MarkAutoTLSNotEnabled sets RouteConditionCertificateProvisioned to true when
// certificate config such as autoTLS is not enabled.
func (rs *RouteStatus) MarkAutoTLSNotEnabled() {
routeCondSet.Manage(rs).MarkTrueWithReason(RouteConditionCertificateProvisioned,
"AutoTLSNotEnabled",
"autoTLS is not enabled")
}

// MarkHTTPDowngrade sets RouteConditionCertificateProvisioned to true when plain
// HTTP is enabled even when Certificated is not ready.
func (rs *RouteStatus) MarkHTTPDowngrade(name string) {
routeCondSet.Manage(rs).MarkTrueWithReason(RouteConditionCertificateProvisioned,
"HTTPDowngrade",
"Certificate %s is not ready downgrade HTTP.", name)
}

// PropagateIngressStatus update RouteConditionIngressReady condition
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/serving/v1alpha1/route_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func TestTypicalRouteFlow(t *testing.T) {
apistest.CheckConditionOngoing(r, RouteConditionReady, t)

r.MarkTrafficAssigned()
r.MarkAutoTLSNotEnabled()
apistest.CheckConditionSucceeded(r, RouteConditionAllTrafficAssigned, t)
apistest.CheckConditionOngoing(r, RouteConditionIngressReady, t)
apistest.CheckConditionOngoing(r, RouteConditionReady, t)
Expand Down Expand Up @@ -273,6 +274,7 @@ func TestIngressFailureRecovery(t *testing.T) {
apistest.CheckConditionOngoing(r, RouteConditionReady, t)

r.MarkTrafficAssigned()
r.MarkAutoTLSNotEnabled()
r.PropagateIngressStatus(netv1alpha1.IngressStatus{
Status: duckv1.Status{
Conditions: duckv1.Conditions{{
Expand Down Expand Up @@ -376,6 +378,22 @@ func TestRouteNotOwnCertificate(t *testing.T) {
apistest.CheckConditionFailed(r, RouteConditionCertificateProvisioned, t)
}

func TestRouteAutoTLSNotEnabled(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
r.MarkAutoTLSNotEnabled()

apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

func TestRouteHTTPDowngrade(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
r.MarkHTTPDowngrade("cert")

apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

func TestIngressNotConfigured(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
Expand Down
4 changes: 3 additions & 1 deletion pkg/reconciler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func (c *Reconciler) reconcileIngressResources(ctx context.Context, r *v1.Route,
func (c *Reconciler) tls(ctx context.Context, host string, r *v1.Route, traffic *traffic.Config) ([]netv1alpha1.IngressTLS, []netv1alpha1.HTTP01Challenge, error) {
tls := []netv1alpha1.IngressTLS{}
if !config.FromContext(ctx).Network.AutoTLS {
r.Status.MarkAutoTLSNotEnabled()
return tls, nil, nil
}
domainToTagMap, err := domains.GetAllDomainsAndTags(ctx, r, getTrafficNames(traffic.Targets), traffic.Visibility)
Expand Down Expand Up @@ -248,7 +249,7 @@ func (c *Reconciler) tls(ctx context.Context, host string, r *v1.Route, traffic
} else {
acmeChallenges = append(acmeChallenges, cert.Status.HTTP01Challenges...)
r.Status.MarkCertificateNotReady(cert.Name)
// When httpProtocol is enabled, downward http scheme.
// When httpProtocol is enabled, downgrade http scheme.
if config.FromContext(ctx).Network.HTTPProtocol == network.HTTPEnabled {
if dnsNames.Has(host) {
r.Status.URL = &apis.URL{
Expand All @@ -257,6 +258,7 @@ func (c *Reconciler) tls(ctx context.Context, host string, r *v1.Route, traffic
}
}
setTargetsScheme(&r.Status, dnsNames.List(), "http")
r.Status.MarkHTTPDowngrade(cert.Name)
}
}
}
Expand Down
Loading