From 55bae56d18db61680720c5073ac81ddee2e3b460 Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Fri, 18 Nov 2016 12:38:56 -0500 Subject: [PATCH 1/2] update missing probe severity to info --- pkg/api/graph/interfaces.go | 2 +- pkg/api/kubegraph/analysis/podspec.go | 2 +- pkg/cmd/cli/describe/projectstatus.go | 29 +++++++++++++++++++++++++++ pkg/deploy/graph/analysis/dc.go | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) diff --git a/pkg/api/graph/interfaces.go b/pkg/api/graph/interfaces.go index d59c00269bf3..a70dbbaf0239 100644 --- a/pkg/api/graph/interfaces.go +++ b/pkg/api/graph/interfaces.go @@ -28,7 +28,7 @@ type Severity string const ( // InfoSeverity is interesting - // TODO: Consider what to do with this once we revisit the graph api - currently not used. + // Currently used in missing probe markers InfoSeverity Severity = "info" // WarningSeverity is probably wrong, but we aren't certain WarningSeverity Severity = "warning" diff --git a/pkg/api/kubegraph/analysis/podspec.go b/pkg/api/kubegraph/analysis/podspec.go index 86ceae695199..29b433846f3c 100644 --- a/pkg/api/kubegraph/analysis/podspec.go +++ b/pkg/api/kubegraph/analysis/podspec.go @@ -100,7 +100,7 @@ func FindMissingLivenessProbes(g osgraph.Graph, f osgraph.Namer, setProbeCommand Node: podSpecNode, RelatedNodes: []graph.Node{topLevelNode}, - Severity: osgraph.WarningSeverity, + Severity: osgraph.InfoSeverity, Key: MissingLivenessProbeWarning, Message: fmt.Sprintf("%s has no liveness probe to verify pods are still running.", topLevelString), diff --git a/pkg/cmd/cli/describe/projectstatus.go b/pkg/cmd/cli/describe/projectstatus.go index d5586b4c4b9e..0077ef5a8c55 100644 --- a/pkg/cmd/cli/describe/projectstatus.go +++ b/pkg/cmd/cli/describe/projectstatus.go @@ -304,6 +304,10 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error warningMarkers := allMarkers.BySeverity(osgraph.WarningSeverity) if len(warningMarkers) > 0 { if d.Suggest { + // add linebreak between Errors list and Warnings list + if len(errorMarkers) > 0 { + fmt.Fprintln(out) + } fmt.Fprintln(out, "Warnings:") } for _, marker := range warningMarkers { @@ -322,6 +326,31 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error } } + infoMarkers := allMarkers.BySeverity(osgraph.InfoSeverity) + if len(infoMarkers) > 0 { + if d.Suggest { + // add linebreak between Warnings list and Info List + if len(warningMarkers) > 0 || len(warningMarkers) > 0 { + fmt.Fprintln(out) + } + fmt.Fprintln(out, "Info:") + } + for _, marker := range infoMarkers { + if d.Suggest { + fmt.Fprintln(out, indent+"* "+marker.Message) + switch s := marker.Suggestion.String(); { + case strings.Contains(s, "\n"): + fmt.Fprintln(out) + for _, line := range strings.Split(s, "\n") { + fmt.Fprintln(out, indent+" "+line) + } + case len(s) > 0: + fmt.Fprintln(out, indent+" try: "+s) + } + } + } + } + // We print errors by default and warnings if -v is used. If we get none, // this would be an extra new line. if len(errorMarkers) != 0 || (d.Suggest && len(warningMarkers) != 0) { diff --git a/pkg/deploy/graph/analysis/dc.go b/pkg/deploy/graph/analysis/dc.go index d28454d366de..5e81fb8d2e39 100644 --- a/pkg/deploy/graph/analysis/dc.go +++ b/pkg/deploy/graph/analysis/dc.go @@ -118,7 +118,7 @@ Node: // All of the containers in the deployment config lack a readiness probe markers = append(markers, osgraph.Marker{ Node: uncastDcNode, - Severity: osgraph.WarningSeverity, + Severity: osgraph.InfoSeverity, Key: MissingReadinessProbeWarning, Message: fmt.Sprintf("%s has no readiness probe to verify pods are ready to accept traffic or ensure deployment is successful.", f.ResourceName(dcNode)), From 2ce91621d8d7f821140f112e533c1535b1a6988f Mon Sep 17 00:00:00 2001 From: juanvallejo Date: Fri, 18 Nov 2016 13:43:09 -0500 Subject: [PATCH 2/2] create printMarkerSuggestions func --- pkg/cmd/cli/describe/projectstatus.go | 76 +++++++++++---------------- 1 file changed, 30 insertions(+), 46 deletions(-) diff --git a/pkg/cmd/cli/describe/projectstatus.go b/pkg/cmd/cli/describe/projectstatus.go index 0077ef5a8c55..068968b9c1c9 100644 --- a/pkg/cmd/cli/describe/projectstatus.go +++ b/pkg/cmd/cli/describe/projectstatus.go @@ -282,23 +282,7 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error errorSuggestions := 0 if len(errorMarkers) > 0 { fmt.Fprintln(out, "Errors:") - for _, marker := range errorMarkers { - fmt.Fprintln(out, indent+"* "+marker.Message) - if len(marker.Suggestion) > 0 { - errorSuggestions++ - if d.Suggest { - switch s := marker.Suggestion.String(); { - case strings.Contains(s, "\n"): - fmt.Fprintln(out) - for _, line := range strings.Split(s, "\n") { - fmt.Fprintln(out, indent+" "+line) - } - case len(s) > 0: - fmt.Fprintln(out, indent+" try: "+s) - } - } - } - } + errorSuggestions += printMarkerSuggestions(errorMarkers, d.Suggest, out, indent) } warningMarkers := allMarkers.BySeverity(osgraph.WarningSeverity) @@ -310,45 +294,19 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error } fmt.Fprintln(out, "Warnings:") } - for _, marker := range warningMarkers { - if d.Suggest { - fmt.Fprintln(out, indent+"* "+marker.Message) - switch s := marker.Suggestion.String(); { - case strings.Contains(s, "\n"): - fmt.Fprintln(out) - for _, line := range strings.Split(s, "\n") { - fmt.Fprintln(out, indent+" "+line) - } - case len(s) > 0: - fmt.Fprintln(out, indent+" try: "+s) - } - } - } + printMarkerSuggestions(warningMarkers, d.Suggest, out, indent) } infoMarkers := allMarkers.BySeverity(osgraph.InfoSeverity) if len(infoMarkers) > 0 { if d.Suggest { // add linebreak between Warnings list and Info List - if len(warningMarkers) > 0 || len(warningMarkers) > 0 { + if len(warningMarkers) > 0 || len(errorMarkers) > 0 { fmt.Fprintln(out) } fmt.Fprintln(out, "Info:") } - for _, marker := range infoMarkers { - if d.Suggest { - fmt.Fprintln(out, indent+"* "+marker.Message) - switch s := marker.Suggestion.String(); { - case strings.Contains(s, "\n"): - fmt.Fprintln(out) - for _, line := range strings.Split(s, "\n") { - fmt.Fprintln(out, indent+" "+line) - } - case len(s) > 0: - fmt.Fprintln(out, indent+" try: "+s) - } - } - } + printMarkerSuggestions(infoMarkers, d.Suggest, out, indent) } // We print errors by default and warnings if -v is used. If we get none, @@ -391,6 +349,32 @@ func (d *ProjectStatusDescriber) Describe(namespace, name string) (string, error }) } +// printMarkerSuggestions prints a formatted list of marker suggestions +// and returns the amount of suggestions printed +func printMarkerSuggestions(markers []osgraph.Marker, suggest bool, out *tabwriter.Writer, indent string) int { + suggestionAmount := 0 + for _, marker := range markers { + if len(marker.Suggestion) > 0 { + suggestionAmount++ + } + if len(marker.Suggestion) > 0 || len(marker.Message) > 0 { + if suggest { + fmt.Fprintln(out, indent+"* "+marker.Message) + switch s := marker.Suggestion.String(); { + case strings.Contains(s, "\n"): + fmt.Fprintln(out) + for _, line := range strings.Split(s, "\n") { + fmt.Fprintln(out, indent+" "+line) + } + case len(s) > 0: + fmt.Fprintln(out, indent+" try: "+s) + } + } + } + } + return suggestionAmount +} + func createForbiddenMarkers(forbiddenResources sets.String) []osgraph.Marker { markers := []osgraph.Marker{} for forbiddenResource := range forbiddenResources {