Skip to content

Commit

Permalink
Merge pull request #633 from openshift-cherrypick-robot/cherry-pick-6…
Browse files Browse the repository at this point in the history
…32-to-release-4.6

[release-4.6] Bug 1893693: account for nil in LastTransitionTime in route status
  • Loading branch information
openshift-merge-robot committed Nov 26, 2020
2 parents ffd6836 + 2f93544 commit 299b6af
Showing 1 changed file with 30 additions and 27 deletions.
57 changes: 30 additions & 27 deletions pkg/helpers/describe/describer.go
Expand Up @@ -900,27 +900,14 @@ func (d *RouteDescriber) Describe(namespace, name string, settings describe.Desc
}

return tabbedString(func(out *tabwriter.Writer) error {
var hostName string
formatMeta(out, route.ObjectMeta)
if len(route.Spec.Host) > 0 {
formatString(out, "Requested Host", route.Spec.Host)
for _, ingress := range route.Status.Ingress {
if route.Spec.Host != ingress.Host {
continue
}
hostName = ""
if len(ingress.RouterCanonicalHostname) > 0 {
hostName = fmt.Sprintf(" (host %s)", ingress.RouterCanonicalHostname)
}
switch status, condition := routedisplayhelpers.IngressConditionStatus(&ingress, routev1.RouteAdmitted); status {
case corev1.ConditionTrue:
fmt.Fprintf(out, "\t exposed on router %s%s %s ago\n", ingress.RouterName, hostName, strings.ToLower(FormatRelativeTime(condition.LastTransitionTime.Time)))
case corev1.ConditionFalse:
fmt.Fprintf(out, "\t rejected by router %s: %s%s (%s ago)\n", ingress.RouterName, hostName, condition.Reason, strings.ToLower(FormatRelativeTime(condition.LastTransitionTime.Time)))
if len(condition.Message) > 0 {
fmt.Fprintf(out, "\t %s\n", condition.Message)
}
}
formatRouteIngress(out, true, ingress)
}
} else {
formatString(out, "Requested Host", "<auto>")
Expand All @@ -930,19 +917,7 @@ func (d *RouteDescriber) Describe(namespace, name string, settings describe.Desc
if route.Spec.Host == ingress.Host {
continue
}
hostName = ""
if len(ingress.RouterCanonicalHostname) > 0 {
hostName = fmt.Sprintf(" (host %s)", ingress.RouterCanonicalHostname)
}
switch status, condition := routedisplayhelpers.IngressConditionStatus(&ingress, routev1.RouteAdmitted); status {
case corev1.ConditionTrue:
fmt.Fprintf(out, "\t%s exposed on router %s %s%s ago\n", ingress.Host, ingress.RouterName, hostName, strings.ToLower(FormatRelativeTime(condition.LastTransitionTime.Time)))
case corev1.ConditionFalse:
fmt.Fprintf(out, "\trejected by router %s: %s%s (%s ago)\n", ingress.RouterName, hostName, condition.Reason, strings.ToLower(FormatRelativeTime(condition.LastTransitionTime.Time)))
if len(condition.Message) > 0 {
fmt.Fprintf(out, "\t %s\n", condition.Message)
}
}
formatRouteIngress(out, false, ingress)
}
formatString(out, "Path", route.Spec.Path)

Expand Down Expand Up @@ -1008,6 +983,34 @@ func (d *RouteDescriber) Describe(namespace, name string, settings describe.Desc
})
}

func formatRouteIngress(out *tabwriter.Writer, short bool, ingress routev1.RouteIngress) {
hostName := ""
if len(ingress.RouterCanonicalHostname) > 0 {
hostName = fmt.Sprintf(" (host %s)", ingress.RouterCanonicalHostname)
}
switch status, condition := routedisplayhelpers.IngressConditionStatus(&ingress, routev1.RouteAdmitted); status {
case corev1.ConditionTrue:
fmt.Fprintf(out, "\t ")
if !short {
fmt.Fprintf(out, "%s", ingress.Host)
}
fmt.Fprintf(out, " exposed on router %s%s", ingress.RouterName, hostName)
if condition.LastTransitionTime != nil {
fmt.Fprintf(out, " %s ago", strings.ToLower(FormatRelativeTime(condition.LastTransitionTime.Time)))
}
fmt.Fprintf(out, "\n")
case corev1.ConditionFalse:
fmt.Fprintf(out, "\trejected by router %s: %s%s", ingress.RouterName, hostName, condition.Reason)
if condition.LastTransitionTime != nil {
fmt.Fprintf(out, " (%s ago)", strings.ToLower(FormatRelativeTime(condition.LastTransitionTime.Time)))
}
fmt.Fprintf(out, "\n")
if len(condition.Message) > 0 {
fmt.Fprintf(out, "\t %s\n", condition.Message)
}
}
}

// ProjectDescriber generates information about a Project
type ProjectDescriber struct {
projectClient projectclient.ProjectV1Interface
Expand Down

0 comments on commit 299b6af

Please sign in to comment.