Skip to content

Commit 33d519b

Browse files
authored
feat: add finch version output to support-bundle (runfinch#1124)
Signed-off-by: Swagat Bora <[email protected]>
1 parent 5ba7305 commit 33d519b

File tree

5 files changed

+267
-30
lines changed

5 files changed

+267
-30
lines changed

Diff for: cmd/finch/main_native.go

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ var newApp = func(
104104
ecc,
105105
ncc,
106106
lima,
107+
system.NewStdLib(),
107108
)
108109

109110
// append nerdctl commands

Diff for: cmd/finch/main_remote.go

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ var newApp = func(
114114
ecc,
115115
ncc,
116116
lima,
117+
system.NewStdLib(),
117118
)
118119

119120
// append nerdctl commands

Diff for: pkg/mocks/pkg_support.go

+52
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: pkg/support/support.go

+61-14
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
const (
3232
bundlePrefix = "finch-support"
3333
platformFileName = "platform.yaml"
34+
versionFileName = "version-output.txt"
3435
logPrefix = "logs"
3536
configPrefix = "configs"
3637
additionalPrefix = "misc"
@@ -48,14 +49,22 @@ type BundleBuilder interface {
4849
GenerateSupportBundle([]string, []string) (string, error)
4950
}
5051

52+
// SystemDeps provides methods to get system dependencies.
53+
//
54+
//go:generate mockgen -copyright_file=../../copyright_header -destination=../mocks/pkg_support.go -package=mocks -mock_names SystemDeps=SupportSystemDeps . SystemDeps
55+
type SystemDeps interface {
56+
system.ExecutableFinder
57+
}
58+
5159
type bundleBuilder struct {
52-
logger flog.Logger
53-
fs afero.Fs
54-
config BundleConfig
55-
finch fpath.Finch
56-
ecc command.Creator
57-
ncc command.NerdctlCmdCreator
58-
lima wrapper.LimaWrapper
60+
logger flog.Logger
61+
fs afero.Fs
62+
config BundleConfig
63+
finch fpath.Finch
64+
ecc command.Creator
65+
ncc command.NerdctlCmdCreator
66+
lima wrapper.LimaWrapper
67+
systemDeps SystemDeps
5968
}
6069

6170
// NewBundleBuilder produces a new BundleBuilder.
@@ -67,15 +76,17 @@ func NewBundleBuilder(
6776
ecc command.Creator,
6877
ncc command.NerdctlCmdCreator,
6978
lima wrapper.LimaWrapper,
79+
systemDeps SystemDeps,
7080
) BundleBuilder {
7181
return &bundleBuilder{
72-
logger: logger,
73-
fs: fs,
74-
config: config,
75-
finch: finch,
76-
ecc: ecc,
77-
ncc: ncc,
78-
lima: lima,
82+
logger: logger,
83+
fs: fs,
84+
config: config,
85+
finch: finch,
86+
ecc: ecc,
87+
ncc: ncc,
88+
lima: lima,
89+
systemDeps: systemDeps,
7990
}
8091
}
8192

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

122+
bb.logger.Debugln("Collecting finch version output...")
123+
version := bb.getFinchVersion()
124+
err = writeVersionOutput(writer, version, zipPrefix)
125+
if err != nil {
126+
return "", err
127+
}
128+
111129
bb.logger.Debugln("Copying in log files...")
112130
for _, file := range bb.config.LogFiles() {
113131
if fileShouldBeExcluded(file, excludeFiles) {
@@ -320,6 +338,21 @@ func getFinchVersion() string {
320338
return version.Version
321339
}
322340

341+
func (bb *bundleBuilder) getFinchVersion() string {
342+
// get current finch executable
343+
executable, err := bb.systemDeps.Executable()
344+
if err != nil {
345+
return ""
346+
}
347+
cmd := bb.ecc.Create(executable, "version")
348+
out, err := cmd.Output()
349+
if err != nil {
350+
return ""
351+
}
352+
output := string(out)
353+
return output
354+
}
355+
323356
func writePlatformData(writer *zip.Writer, platform *PlatformData, prefix string) error {
324357
platformFile, err := writer.Create(path.Join(prefix, platformFileName))
325358
if err != nil {
@@ -371,3 +404,17 @@ func fileShouldBeExcluded(filename string, exclude []string) bool {
371404
func isFileFromVM(filename string) bool {
372405
return strings.HasPrefix(filename, "vm:")
373406
}
407+
408+
func writeVersionOutput(writer *zip.Writer, version, prefix string) error {
409+
versionFile, err := writer.Create(path.Join(prefix, versionFileName))
410+
if err != nil {
411+
return err
412+
}
413+
414+
_, err = versionFile.Write([]byte(version))
415+
if err != nil {
416+
return err
417+
}
418+
419+
return nil
420+
}

0 commit comments

Comments
 (0)