Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add finch version output to support-bundle #1124

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading