Skip to content

Commit 1c6fe9f

Browse files
committed
add numbers to support bundle name as needed
1 parent ed9264e commit 1c6fe9f

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

cmd/troubleshoot/cli/receive.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"path/filepath"
1111

1212
"github.com/mholt/archiver"
13+
"github.com/pkg/errors"
1314
"github.com/replicatedhq/troubleshoot/pkg/logger"
1415
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
1516
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -131,7 +132,12 @@ func receiveSupportBundle(collectorJobNamespace string, collectorJobName string)
131132
paths = append(paths, filepath.Join(bundlePath, id))
132133
}
133134

134-
if err := tarGz.Archive(paths, "support-bundle.tar.gz"); err != nil {
135+
filename, err := findFileName("support-bundle", "tar.gz")
136+
if err != nil {
137+
return errors.Wrap(err, "find file name")
138+
}
139+
140+
if err := tarGz.Archive(paths, filename); err != nil {
135141
return err
136142
}
137143
return nil

cmd/troubleshoot/cli/run_nocrd.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,16 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
193193
paths = append(paths, collectorDir)
194194
}
195195

196-
if err := tarGz.Archive(paths, "support-bundle.tar.gz"); err != nil {
196+
filename, err := findFileName("support-bundle", "tar.gz")
197+
if err != nil {
198+
return "", errors.Wrap(err, "find file name")
199+
}
200+
201+
if err := tarGz.Archive(paths, filename); err != nil {
197202
return "", errors.Wrap(err, "create archive")
198203
}
199204

200-
return "support-bundle.tar.gz", nil
205+
return filename, nil
201206
}
202207

203208
func parseAndSaveCollectorOutput(output string, bundlePath string) (string, error) {

cmd/troubleshoot/cli/util.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package cli
22

33
import (
4+
"fmt"
45
"net/url"
56
"os"
67

8+
"github.com/pkg/errors"
79
troubleshootclientv1beta1 "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/typed/troubleshoot/v1beta1"
810
"github.com/spf13/viper"
911
"k8s.io/client-go/tools/clientcmd"
@@ -39,3 +41,19 @@ func createTroubleshootK8sClient() (*troubleshootclientv1beta1.TroubleshootV1bet
3941

4042
return troubleshootClient, nil
4143
}
44+
45+
func findFileName(basename, extension string) (string, error) {
46+
n := 1
47+
name := basename
48+
for {
49+
filename := name + "." + extension
50+
if _, err := os.Stat(filename); os.IsNotExist(err) {
51+
return filename, nil
52+
} else if err != nil {
53+
return "", errors.Wrap(err, "check file exists")
54+
}
55+
56+
name = fmt.Sprintf("%s (%d)", basename, n)
57+
n = n + 1
58+
}
59+
}

0 commit comments

Comments
 (0)