Skip to content

Commit

Permalink
Expose GetVersionFile function publicly
Browse files Browse the repository at this point in the history
Signed-off-by: Evans Mungai <evans@replicated.com>
  • Loading branch information
banjoh committed Sep 13, 2024
1 parent db80cee commit 4aa9b6f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
29 changes: 0 additions & 29 deletions internal/version/version.go

This file was deleted.

5 changes: 3 additions & 2 deletions pkg/preflight/run.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package preflight

import (
"bytes"
"context"
"fmt"
"os"
Expand All @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/supportbundle/supportbundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
}

0 comments on commit 4aa9b6f

Please sign in to comment.