Skip to content

Commit fd257b5

Browse files
authored
Merge pull request #91 from bearium/stdout_results
Added Namespace for Collection and Allows for tests to output to stdout
2 parents 0292824 + 3afe32c commit fd257b5

File tree

8 files changed

+131
-427
lines changed

8 files changed

+131
-427
lines changed

cmd/collector/cli/run.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ func Run() *cobra.Command {
3232
}
3333

3434
collector := collect.Collector{
35-
Collect: c,
36-
Redact: v.GetBool("redact"),
35+
Collect: c,
36+
Redact: v.GetBool("redact"),
37+
Namespace: v.GetString("namespace"),
3738
}
3839
b, err := collector.RunCollectorSync()
3940
if err != nil {

cmd/preflight/cli/run_nocrd.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ func runPreflightsNoCRD(v *viper.Viper, arg string) error {
124124
return showInteractiveResults(preflight.Name, analyzeResults)
125125
}
126126

127-
logger.Printf("only interactive results are supported\n")
128-
return nil
127+
return showStdoutResults(preflight.Name, analyzeResults)
129128
}
130129

131130
func runCollectors(v *viper.Viper, preflight troubleshootv1beta1.Preflight) (map[string][]byte, error) {
@@ -149,6 +148,7 @@ func runCollectors(v *viper.Viper, preflight troubleshootv1beta1.Preflight) (map
149148
Redact: true,
150149
Collect: desiredCollector,
151150
ClientConfig: config,
151+
Namespace: v.GetString("namespace"),
152152
}
153153

154154
result, err := collector.RunCollectorSync()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
7+
)
8+
9+
func showStdoutResults(preflightName string, analyzeResults []*analyzerunner.AnalyzeResult) error {
10+
fmt.Printf("\n=== TEST %s\n", preflightName)
11+
for _, analyzeResult := range analyzeResults {
12+
fmt.Printf("=== RUN: %s\n", analyzeResult.Title)
13+
}
14+
var failed bool
15+
for _, analyzeResult := range analyzeResults {
16+
testResultfailed := outputResult(analyzeResult)
17+
if testResultfailed {
18+
failed = true
19+
}
20+
}
21+
if failed {
22+
fmt.Printf("--- FAIL %s\n", preflightName)
23+
fmt.Println("FAILED")
24+
} else {
25+
fmt.Printf("--- PASS %s\n", preflightName)
26+
fmt.Println("PASS")
27+
}
28+
return nil
29+
}
30+
31+
func outputResult(analyzeResult *analyzerunner.AnalyzeResult) bool {
32+
if analyzeResult.IsPass {
33+
fmt.Printf(" --- PASS %s\n", analyzeResult.Title)
34+
fmt.Printf(" --- %s\n", analyzeResult.Message)
35+
} else if analyzeResult.IsWarn {
36+
fmt.Printf(" --- WARN: %s\n", analyzeResult.Title)
37+
fmt.Printf(" --- %s\n", analyzeResult.Message)
38+
} else if analyzeResult.IsFail {
39+
fmt.Printf(" --- FAIL: %s\n", analyzeResult.Title)
40+
fmt.Printf(" --- %s\n", analyzeResult.Message)
41+
return true
42+
}
43+
return false
44+
}

cmd/troubleshoot/cli/run_nocrd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
168168
Redact: true,
169169
Collect: desiredCollector,
170170
ClientConfig: config,
171+
Namespace: v.GetString("namespace"),
171172
}
172173

173174
progressChan <- collector.GetDisplayName()

go.mod

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,46 @@ go 1.12
44

55
require (
66
github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412
7+
github.com/aws/aws-sdk-go v1.22.0 // indirect
78
github.com/blang/semver v3.5.1+incompatible
9+
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
10+
github.com/dsnet/compress v0.0.1 // indirect
11+
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 // indirect
12+
github.com/emicklei/go-restful v2.9.6+incompatible // indirect
13+
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
814
github.com/fatih/color v1.7.0
15+
github.com/frankban/quicktest v1.7.2 // indirect
916
github.com/gin-gonic/gin v1.4.0
1017
github.com/gizak/termui/v3 v3.1.0
18+
github.com/go-openapi/spec v0.19.2 // indirect
19+
github.com/golang/snappy v0.0.1 // indirect
20+
github.com/google/gofuzz v1.0.0 // indirect
21+
github.com/googleapis/gnostic v0.3.0 // indirect
1122
github.com/hashicorp/go-getter v1.3.1-0.20190627223108-da0323b9545e
1223
github.com/hashicorp/go-multierror v1.0.0
24+
github.com/imdario/mergo v0.3.7 // indirect
25+
github.com/mailru/easyjson v0.0.0-20190620125010-da37f6c1e481 // indirect
26+
github.com/mattn/go-colorable v0.1.2 // indirect
1327
github.com/mholt/archiver v3.1.1+incompatible
28+
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
29+
github.com/nwaples/rardecode v1.0.0 // indirect
30+
github.com/onsi/ginkgo v1.8.0 // indirect
1431
github.com/onsi/gomega v1.5.0
32+
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
33+
github.com/pierrec/lz4 v2.2.6+incompatible // indirect
1534
github.com/pkg/errors v0.8.1
16-
github.com/replicatedhq/kots v0.2.0 // indirect
1735
github.com/spf13/cobra v0.0.5
1836
github.com/spf13/viper v1.4.0
1937
github.com/stretchr/testify v1.3.0
2038
github.com/tj/go-spin v1.1.0
39+
github.com/ugorji/go v1.1.7 // indirect
40+
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
41+
go.opencensus.io v0.20.2 // indirect
42+
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 // indirect
2143
golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc
44+
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a // indirect
45+
golang.org/x/sys v0.0.0-20190621203818-d432491b9138 // indirect
46+
google.golang.org/appengine v1.5.0 // indirect
2247
gopkg.in/yaml.v2 v2.2.2
2348
k8s.io/api v0.0.0-20190409021203-6e4e0e4f393b
2449
k8s.io/apiextensions-apiserver v0.0.0-20190409022649-727a075fdec8
@@ -29,4 +54,5 @@ require (
2954
k8s.io/kube-openapi v0.0.0-20190815110238-8ff09bc626d6 // indirect
3055
k8s.io/utils v0.0.0-20190809000727-6c36bc71fc4a // indirect
3156
sigs.k8s.io/controller-runtime v0.2.0-beta.2
57+
sigs.k8s.io/kustomize v2.0.3+incompatible // indirect
3258
)

0 commit comments

Comments
 (0)