Merge pull request #57 from replicatedhq/divolgin/file

add numbers to support bundle name as needed
This commit is contained in:
divolgin
2019-08-21 10:01:37 -07:00
committed by GitHub
3 changed files with 32 additions and 3 deletions
+7 -1
View File
@@ -10,6 +10,7 @@ import (
"path/filepath"
"github.com/mholt/archiver"
"github.com/pkg/errors"
"github.com/replicatedhq/troubleshoot/pkg/logger"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -131,7 +132,12 @@ func receiveSupportBundle(collectorJobNamespace string, collectorJobName string)
paths = append(paths, filepath.Join(bundlePath, id))
}
if err := tarGz.Archive(paths, "support-bundle.tar.gz"); err != nil {
filename, err := findFileName("support-bundle", "tar.gz")
if err != nil {
return errors.Wrap(err, "find file name")
}
if err := tarGz.Archive(paths, filename); err != nil {
return err
}
return nil
+7 -2
View File
@@ -193,11 +193,16 @@ func runCollectors(v *viper.Viper, collector troubleshootv1beta1.Collector, prog
paths = append(paths, collectorDir)
}
if err := tarGz.Archive(paths, "support-bundle.tar.gz"); err != nil {
filename, err := findFileName("support-bundle", "tar.gz")
if err != nil {
return "", errors.Wrap(err, "find file name")
}
if err := tarGz.Archive(paths, filename); err != nil {
return "", errors.Wrap(err, "create archive")
}
return "support-bundle.tar.gz", nil
return filename, nil
}
func parseAndSaveCollectorOutput(output string, bundlePath string) (string, error) {
+18
View File
@@ -1,9 +1,11 @@
package cli
import (
"fmt"
"net/url"
"os"
"github.com/pkg/errors"
troubleshootclientv1beta1 "github.com/replicatedhq/troubleshoot/pkg/client/troubleshootclientset/typed/troubleshoot/v1beta1"
"github.com/spf13/viper"
"k8s.io/client-go/tools/clientcmd"
@@ -39,3 +41,19 @@ func createTroubleshootK8sClient() (*troubleshootclientv1beta1.TroubleshootV1bet
return troubleshootClient, nil
}
func findFileName(basename, extension string) (string, error) {
n := 1
name := basename
for {
filename := name + "." + extension
if _, err := os.Stat(filename); os.IsNotExist(err) {
return filename, nil
} else if err != nil {
return "", errors.Wrap(err, "check file exists")
}
name = fmt.Sprintf("%s (%d)", basename, n)
n = n + 1
}
}