Skip to content

Commit

Permalink
Propagate status from KCert to Route
Browse files Browse the repository at this point in the history
When autoTLS is enabled, KCert is one of the critical resources. This
patch changes changes to propagate status status from KCert to Route.
  • Loading branch information
nak3 committed Mar 6, 2020
1 parent 88710c3 commit e451110
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 61 deletions.
45 changes: 17 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 All @@ -44,6 +45,8 @@ func (rs *RouteStatus) IsReady() bool {
// InitializeConditions sets the initial values to the conditions.
func (rs *RouteStatus) InitializeConditions() {
routeCondSet.Manage(rs).InitializeConditions()
// Since Certificate is optional, initialize the status with Ready.
routeCondSet.Manage(rs).MarkTrue(RouteConditionCertificateProvisioned)
}

// MarkServiceNotOwned changes the IngressReady status to be false with the reason being that
Expand Down Expand Up @@ -99,43 +102,29 @@ 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)
}

func (rs *RouteStatus) MarkCertificateNotEnabled() {
routeCondSet.Manage(rs).MarkTrue(RouteConditionCertificateProvisioned)
}

// PropagateIngressStatus update RouteConditionIngressReady condition
Expand Down
45 changes: 17 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 All @@ -45,6 +46,8 @@ func (rs *RouteStatus) GetCondition(t apis.ConditionType) *apis.Condition {

func (rs *RouteStatus) InitializeConditions() {
routeCondSet.Manage(rs).InitializeConditions()
// Since Certificate is optional, initialize the status with Ready.
routeCondSet.Manage(rs).MarkTrue(RouteConditionCertificateProvisioned)
}

// // MarkResourceNotConvertible adds a Warning-severity condition to the resource noting that
Expand Down Expand Up @@ -112,43 +115,29 @@ 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)
}

func (rs *RouteStatus) MarkCertificateNotEnabled() {
routeCondSet.Manage(rs).MarkTrue(RouteConditionCertificateProvisioned)
}

// PropagateIngressStatus update RouteConditionIngressReady condition
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 @@ -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.MarkCertificateNotEnabled()
return tls, nil, nil
}
domainToTagMap, err := domains.GetAllDomainsAndTags(ctx, r, getTrafficNames(traffic.Targets), traffic.Visibility)
Expand Down
10 changes: 5 additions & 5 deletions pkg/reconciler/route/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1877,13 +1877,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.
WithURL, WithAddress, WithInitRouteConditions,
WithURL, WithAddress, WithInitRouteConditions, MarkCertificateNotReady,
MarkTrafficAssigned, MarkIngressNotConfigured, WithStatusTraffic(
v1.TrafficTarget{
RevisionName: "config-00001",
Percent: ptr.Int64(100),
LatestRevision: ptr.Bool(true),
}), MarkCertificateNotReady),
})),
}},
WantEvents: []string{
Eventf(corev1.EventTypeNormal, "Created", "Created placeholder service %q", "becomes-ready"),
Expand Down Expand Up @@ -2111,15 +2111,15 @@ func TestReconcile_EnableAutoTLS(t *testing.T) {
WithRouteUID("12-34"),
// Populated by reconciliation when all traffic has been assigned.
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),
}),
// The certificate has to be created in the not ready state for the ACME challenge
// ingress rules to be added.
MarkCertificateNotReady,
// Which also means no HTTPS URL
WithURL,
),
Expand Down

0 comments on commit e451110

Please sign in to comment.