diff --git a/internal/version/version.go b/internal/version/version.go deleted file mode 100644 index de0ccb46a..000000000 --- a/internal/version/version.go +++ /dev/null @@ -1,29 +0,0 @@ -package version - -import ( - "bytes" - "io" - - "github.com/pkg/errors" - troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" - libVersion "github.com/replicatedhq/troubleshoot/pkg/version" - "gopkg.in/yaml.v2" -) - -func GetVersionFile() (io.Reader, error) { - // TODO: Should this type be agnostic to the tool? - // i.e should it be a TroubleshootVersion instead? - version := troubleshootv1beta2.SupportBundleVersion{ - ApiVersion: "troubleshoot.sh/v1beta2", - Kind: "SupportBundle", - Spec: troubleshootv1beta2.SupportBundleVersionSpec{ - VersionNumber: libVersion.Version(), - }, - } - b, err := yaml.Marshal(version) - if err != nil { - return nil, errors.Wrap(err, "failed to marshal version data") - } - - return bytes.NewBuffer(b), nil -} diff --git a/pkg/preflight/run.go b/pkg/preflight/run.go index d4add49e2..1202f6481 100644 --- a/pkg/preflight/run.go +++ b/pkg/preflight/run.go @@ -1,6 +1,7 @@ package preflight import ( + "bytes" "context" "fmt" "os" @@ -12,13 +13,13 @@ import ( "github.com/fatih/color" "github.com/pkg/errors" "github.com/replicatedhq/troubleshoot/internal/util" - "github.com/replicatedhq/troubleshoot/internal/version" analyzer "github.com/replicatedhq/troubleshoot/pkg/analyze" troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" "github.com/replicatedhq/troubleshoot/pkg/collect" "github.com/replicatedhq/troubleshoot/pkg/constants" "github.com/replicatedhq/troubleshoot/pkg/k8sutil" "github.com/replicatedhq/troubleshoot/pkg/types" + "github.com/replicatedhq/troubleshoot/pkg/version" "github.com/spf13/viper" spin "github.com/tj/go-spin" "go.opentelemetry.io/otel" @@ -179,7 +180,7 @@ func RunPreflights(interactive bool, output string, format string, args []string return errors.Wrap(err, "failed to get version file") } - err = collectorResults.SaveResult(bundlePath, constants.VERSION_FILENAME, version) + err = collectorResults.SaveResult(bundlePath, constants.VERSION_FILENAME, bytes.NewBuffer([]byte(version))) if err != nil { return errors.Wrap(err, "failed to write version") } diff --git a/pkg/supportbundle/supportbundle.go b/pkg/supportbundle/supportbundle.go index f40f5182e..3f5e0dad4 100644 --- a/pkg/supportbundle/supportbundle.go +++ b/pkg/supportbundle/supportbundle.go @@ -15,12 +15,12 @@ import ( "github.com/pkg/errors" "github.com/replicatedhq/troubleshoot/internal/traces" "github.com/replicatedhq/troubleshoot/internal/util" - "github.com/replicatedhq/troubleshoot/internal/version" analyzer "github.com/replicatedhq/troubleshoot/pkg/analyze" troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" "github.com/replicatedhq/troubleshoot/pkg/collect" "github.com/replicatedhq/troubleshoot/pkg/constants" "github.com/replicatedhq/troubleshoot/pkg/convert" + "github.com/replicatedhq/troubleshoot/pkg/version" "go.opentelemetry.io/otel" "k8s.io/client-go/rest" "k8s.io/klog/v2" @@ -150,7 +150,7 @@ func CollectSupportBundleFromSpec( return nil, errors.Wrap(err, "failed to get version file") } - err = result.SaveResult(bundlePath, constants.VERSION_FILENAME, version) + err = result.SaveResult(bundlePath, constants.VERSION_FILENAME, bytes.NewBuffer([]byte(version))) if err != nil { return nil, errors.Wrap(err, "failed to write version") } diff --git a/pkg/version/version.go b/pkg/version/version.go index 0684b7500..945d8bcad 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -5,6 +5,10 @@ import ( "runtime" "runtime/debug" "time" + + "github.com/pkg/errors" + troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2" + "gopkg.in/yaml.v2" ) var ( @@ -96,3 +100,21 @@ func getGoInfo() GoInfo { func GetUserAgent() string { return fmt.Sprintf("Replicated_Troubleshoot/%s", Version()) } + +func GetVersionFile() (string, error) { + // TODO: Should this type be agnostic to the tool? + // i.e should it be a TroubleshootVersion instead? + version := troubleshootv1beta2.SupportBundleVersion{ + ApiVersion: "troubleshoot.sh/v1beta2", + Kind: "SupportBundle", + Spec: troubleshootv1beta2.SupportBundleVersionSpec{ + VersionNumber: Version(), + }, + } + b, err := yaml.Marshal(version) + if err != nil { + return "", errors.Wrap(err, "failed to marshal version data") + } + + return string(b), nil +}