Skip to content

Commit

Permalink
Add MarkHTTPDownward
Browse files Browse the repository at this point in the history
  • Loading branch information
nak3 committed Apr 21, 2020
1 parent 410aaf6 commit 6a2d8fb
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 5 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/serving/v1/route_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ func (rs *RouteStatus) MarkAutoTLSNotEnabled() {
"autoTLS is not enabled")
}

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

// PropagateIngressStatus update RouteConditionIngressReady condition
// in RouteStatus according to IngressStatus.
func (rs *RouteStatus) PropagateIngressStatus(cs v1alpha1.IngressStatus) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/serving/v1/route_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ func TestRouteAutoTLSNotEnabled(t *testing.T) {
apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

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

apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

func TestIngressNotConfigured(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/serving/v1alpha1/route_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ func (rs *RouteStatus) MarkAutoTLSNotEnabled() {
"autoTLS is not enabled")
}

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

// PropagateIngressStatus update RouteConditionIngressReady condition
// in RouteStatus according to IngressStatus.
func (rs *RouteStatus) PropagateIngressStatus(cs v1alpha1.IngressStatus) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/serving/v1alpha1/route_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,14 @@ func TestRouteAutoTLSNotEnabled(t *testing.T) {
apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

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

apistest.CheckConditionSucceeded(r, RouteConditionCertificateProvisioned, t)
}

func TestIngressNotConfigured(t *testing.T) {
r := &RouteStatus{}
r.InitializeConditions()
Expand Down
1 change: 1 addition & 0 deletions pkg/reconciler/route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ func (c *Reconciler) tls(ctx context.Context, host string, r *v1.Route, traffic
}
}
setTargetsScheme(&r.Status, dnsNames.List(), "http")
r.Status.MarkHTTPDownward(cert.Name)
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/reconciler/route/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ func TestReconcile_EnableAutoTLS(t *testing.T) {
Object: Route("default", "becomes-ready", WithConfigTarget("config"),
WithRouteUID("12-34"),
// Populated by reconciliation when all traffic has been assigned.
WithURL, WithAddress, WithInitRouteConditions, MarkCertificateNotReady,
WithURL, WithAddress, WithInitRouteConditions, WithRouteConditionsHTTPDownward,
MarkTrafficAssigned, MarkIngressNotConfigured, WithStatusTraffic(
v1.TrafficTarget{
RevisionName: "config-00001",
Expand Down Expand Up @@ -2159,15 +2159,14 @@ func TestReconcile_EnableAutoTLS(t *testing.T) {
WithAddress, WithInitRouteConditions,
// The certificate has to be created in the not ready state for the ACME challenge
// ingress rules to be added.
MarkCertificateNotReady,
MarkTrafficAssigned, MarkIngressNotConfigured, WithStatusTraffic(
v1.TrafficTarget{
RevisionName: "config-00001",
Percent: ptr.Int64(100),
LatestRevision: ptr.Bool(true),
}),
// Which also means no HTTPS URL
WithURL,
WithURL, WithRouteConditionsHTTPDownward,
),
}},
Key: "default/becomes-ready",
Expand Down Expand Up @@ -2279,13 +2278,13 @@ func TestReconcile_EnableAutoTLS(t *testing.T) {
Object: Route("default", "becomes-ready", WithConfigTarget("config"),
WithRouteUID("12-34"),
// Populated by reconciliation when all traffic has been assigned.
WithAddress, WithRouteConditionsAutoTLSDisabled,
WithAddress, WithRouteConditionsHTTPDownward,
MarkTrafficAssigned, MarkIngressNotConfigured, WithStatusTraffic(
v1.TrafficTarget{
RevisionName: "config-00001",
Percent: ptr.Int64(100),
LatestRevision: ptr.Bool(true),
}), MarkCertificateNotReady, MarkIngressNotConfigured,
}), MarkIngressNotConfigured,
// The certificate is not ready. So we want to have HTTP URL.
WithURL),
}},
Expand Down
6 changes: 6 additions & 0 deletions pkg/testing/v1/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,12 @@ func WithRouteConditionsAutoTLSDisabled(rt *v1.Route) {
rt.Status.MarkAutoTLSNotEnabled()
}

// WithRouteConditionsHTTPDownward calls MarkHTTPDownward( after initialized the Service's conditions.
func WithRouteConditionsHTTPDownward(rt *v1.Route) {
rt.Status.InitializeConditions()
rt.Status.MarkHTTPDownward(routenames.Certificate(rt))
}

// MarkTrafficAssigned calls the method of the same name on .Status
func MarkTrafficAssigned(r *v1.Route) {
r.Status.MarkTrafficAssigned()
Expand Down

0 comments on commit 6a2d8fb

Please sign in to comment.