Skip to content

Commit

Permalink
feat: add finch version output to support-bundle
Browse files Browse the repository at this point in the history
Signed-off-by: Swagat Bora <[email protected]>
  • Loading branch information
swagatbora90 committed Oct 4, 2024
1 parent 5ba7305 commit 77fa357
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 30 deletions.
1 change: 1 addition & 0 deletions cmd/finch/main_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ var newApp = func(
ecc,
ncc,
lima,
system.NewStdLib(),
)

// append nerdctl commands
Expand Down
1 change: 1 addition & 0 deletions cmd/finch/main_remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var newApp = func(
ecc,
ncc,
lima,
system.NewStdLib(),
)

// append nerdctl commands
Expand Down
52 changes: 52 additions & 0 deletions pkg/mocks/pkg_support.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 61 additions & 14 deletions pkg/support/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
const (
bundlePrefix = "finch-support"
platformFileName = "platform.yaml"
versionFileName = "version-output.txt"
logPrefix = "logs"
configPrefix = "configs"
additionalPrefix = "misc"
Expand All @@ -48,14 +49,22 @@ type BundleBuilder interface {
GenerateSupportBundle([]string, []string) (string, error)
}

// SystemDeps provides methods to get system dependencies.
//
//go:generate mockgen -copyright_file=../../copyright_header -destination=../mocks/pkg_support.go -package=mocks -mock_names SystemDeps=SupportSystemDeps . SystemDeps
type SystemDeps interface {
system.ExecutableFinder
}

type bundleBuilder struct {
logger flog.Logger
fs afero.Fs
config BundleConfig
finch fpath.Finch
ecc command.Creator
ncc command.NerdctlCmdCreator
lima wrapper.LimaWrapper
logger flog.Logger
fs afero.Fs
config BundleConfig
finch fpath.Finch
ecc command.Creator
ncc command.NerdctlCmdCreator
lima wrapper.LimaWrapper
systemDeps SystemDeps
}

// NewBundleBuilder produces a new BundleBuilder.
Expand All @@ -67,15 +76,17 @@ func NewBundleBuilder(
ecc command.Creator,
ncc command.NerdctlCmdCreator,
lima wrapper.LimaWrapper,
systemDeps SystemDeps,
) BundleBuilder {
return &bundleBuilder{
logger: logger,
fs: fs,
config: config,
finch: finch,
ecc: ecc,
ncc: ncc,
lima: lima,
logger: logger,
fs: fs,
config: config,
finch: finch,
ecc: ecc,
ncc: ncc,
lima: lima,
systemDeps: systemDeps,
}
}

Expand Down Expand Up @@ -108,6 +119,13 @@ func (bb *bundleBuilder) GenerateSupportBundle(additionalFiles []string, exclude
return "", err
}

bb.logger.Debugln("Collecting finch version output...")
version := bb.getFinchVersion()
err = writeVersionOutput(writer, version, zipPrefix)
if err != nil {
return "", err
}

bb.logger.Debugln("Copying in log files...")
for _, file := range bb.config.LogFiles() {
if fileShouldBeExcluded(file, excludeFiles) {
Expand Down Expand Up @@ -320,6 +338,21 @@ func getFinchVersion() string {
return version.Version
}

func (bb *bundleBuilder) getFinchVersion() string {
// get current finch executable
executable, err := bb.systemDeps.Executable()
if err != nil {
return ""
}
cmd := bb.ecc.Create(executable, "version")
out, err := cmd.Output()
if err != nil {
return ""
}
output := string(out)
return output
}

func writePlatformData(writer *zip.Writer, platform *PlatformData, prefix string) error {
platformFile, err := writer.Create(path.Join(prefix, platformFileName))
if err != nil {
Expand Down Expand Up @@ -371,3 +404,17 @@ func fileShouldBeExcluded(filename string, exclude []string) bool {
func isFileFromVM(filename string) bool {
return strings.HasPrefix(filename, "vm:")
}

func writeVersionOutput(writer *zip.Writer, version, prefix string) error {
versionFile, err := writer.Create(path.Join(prefix, versionFileName))
if err != nil {
return err
}

_, err = versionFile.Write([]byte(version))
if err != nil {
return err
}

return nil
}
Loading

0 comments on commit 77fa357

Please sign in to comment.