Skip to content

Commit f9efac3

Browse files
authored
Merge pull request #43 from replicatedhq/progress
Show progress when collecting support bundle
2 parents e90b397 + 920e1ef commit f9efac3

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

cmd/preflight/cli/run_nocrd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"strings"
1515
"time"
1616

17+
"github.com/ahmetalpbalkan/go-cursor"
1718
"github.com/pkg/errors"
1819
analyzerunner "github.com/replicatedhq/troubleshoot/pkg/analyze"
1920
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
@@ -36,6 +37,9 @@ import (
3637
)
3738

3839
func runPreflightsNoCRD(v *viper.Viper, arg string) error {
40+
fmt.Print(cursor.Hide())
41+
defer fmt.Print(cursor.Show())
42+
3943
preflightContent := ""
4044
if !isURL(arg) {
4145
if _, err := os.Stat(arg); os.IsNotExist(err) {

cmd/troubleshoot/cli/run_nocrd.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ import (
1313
"path/filepath"
1414
"time"
1515

16+
"github.com/ahmetalpbalkan/go-cursor"
1617
"github.com/mholt/archiver"
1718
troubleshootv1beta1 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta1"
1819
collectrunner "github.com/replicatedhq/troubleshoot/pkg/collect"
1920
"github.com/replicatedhq/troubleshoot/pkg/logger"
2021
"github.com/spf13/viper"
22+
"github.com/tj/go-spin"
2123
"gopkg.in/yaml.v2"
2224
corev1 "k8s.io/api/core/v1"
2325
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -31,6 +33,9 @@ import (
3133
)
3234

3335
func runTroubleshootNoCRD(v *viper.Viper, arg string) error {
36+
fmt.Print(cursor.Hide())
37+
defer fmt.Print(cursor.Show())
38+
3439
collectorContent := ""
3540
if !isURL(arg) {
3641
if _, err := os.Stat(arg); os.IsNotExist(err) {
@@ -68,17 +73,43 @@ func runTroubleshootNoCRD(v *viper.Viper, arg string) error {
6873
return fmt.Errorf("unable to parse %s collectors", arg)
6974
}
7075

71-
archivePath, err := runCollectors(v, collector)
76+
s := spin.New()
77+
finishedCh := make(chan bool, 1)
78+
progressChan := make(chan string, 1)
79+
go func() {
80+
currentDir := ""
81+
for {
82+
select {
83+
case dir := <-progressChan:
84+
currentDir = filepath.Base(dir)
85+
case <-finishedCh:
86+
fmt.Printf("\r")
87+
return
88+
case <-time.After(time.Millisecond * 100):
89+
if currentDir == "" {
90+
fmt.Printf("\r%s \033[36mCollecting support bundle\033[m %s", cursor.ClearEntireLine(), s.Next())
91+
} else {
92+
fmt.Printf("\r%s \033[36mCollecting support bundle\033[m %s: %s", cursor.ClearEntireLine(), s.Next(), currentDir)
93+
}
94+
}
95+
}
96+
}()
97+
defer func() {
98+
finishedCh <- true
99+
}()
100+
101+
archivePath, err := runCollectors(v, collector, progressChan)
72102
if err != nil {
73103
return err
74104
}
75105

106+
fmt.Printf("\r%s", cursor.ClearEntireLine())
76107
fmt.Printf("%s\n", archivePath)
77108

78109
return nil
79110
}
80111

81-
func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector) (string, error) {
112+
func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, progressChan chan string) (string, error) {
82113
cfg, err := config.GetConfig()
83114
if err != nil {
84115
return "", err
@@ -218,6 +249,7 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector) (str
218249
return
219250
}
220251

252+
progressChan <- collectorDir
221253
collectorDirs = append(collectorDirs, collectorDir)
222254

223255
if err := client.Delete(context.Background(), newPod); err != nil {

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ require (
66
github.com/Masterminds/goutils v1.1.0 // indirect
77
github.com/Masterminds/semver v1.4.2 // indirect
88
github.com/Masterminds/sprig v2.20.0+incompatible // indirect
9+
github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412
910
github.com/andrewchambers/go-jqpipe v0.0.0-20180509223707-2d54cef8cd94 // indirect
1011
github.com/blang/semver v3.5.1+incompatible
1112
github.com/docker/distribution v2.7.1+incompatible // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb0
2525
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
2626
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
2727
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
28+
github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412 h1:vOVO0ypMfTt6tZacyI0kp+iCZb1XSNiYDqnzBWYgfe4=
29+
github.com/ahmetalpbalkan/go-cursor v0.0.0-20131010032410-8136607ea412/go.mod h1:AI9hp1tkp10pAlK5TCwL+7yWbRgtDm9jhToq6qij2xs=
2830
github.com/alecthomas/gometalinter v2.0.11+incompatible/go.mod h1:qfIpQGGz3d+NmgyPBqv+LSh50emm1pt72EtcX2vKYQk=
2931
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
3032
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=

0 commit comments

Comments
 (0)