-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sam Berning <[email protected]>
- Loading branch information
1 parent
3df1317
commit 5a169ef
Showing
18 changed files
with
1,618 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/runfinch/finch/pkg/command" | ||
"github.com/runfinch/finch/pkg/flog" | ||
"github.com/runfinch/finch/pkg/lima" | ||
"github.com/runfinch/finch/pkg/support" | ||
) | ||
|
||
func newSupportBundleCommand(logger flog.Logger, builder support.BundleBuilder, lcc command.LimaCmdCreator) *cobra.Command { | ||
supportBundleCommand := &cobra.Command{ | ||
Use: "support-bundle", | ||
Short: "Gathers logs and info into a bundle to help debug issues", | ||
} | ||
supportBundleCommand.AddCommand( | ||
newSupportBundleGenerateCommand(logger, builder, lcc), | ||
) | ||
return supportBundleCommand | ||
} | ||
|
||
func newSupportBundleGenerateCommand(logger flog.Logger, builder support.BundleBuilder, lcc command.LimaCmdCreator) *cobra.Command { | ||
supportBundleGenerateCommand := &cobra.Command{ | ||
Use: "generate", | ||
Args: cobra.NoArgs, | ||
Short: "Generate support bundle", | ||
RunE: newGenerateSupportBundleAction(logger, builder, lcc).runAdapter, | ||
} | ||
|
||
supportBundleGenerateCommand.Flags().StringArray("include", []string{}, "additional files to include in the support bundle") | ||
supportBundleGenerateCommand.Flags().StringArray("exclude", []string{}, "files to exclude from the support bundle") | ||
return supportBundleGenerateCommand | ||
} | ||
|
||
type generateSupportBundleAction struct { | ||
logger flog.Logger | ||
builder support.BundleBuilder | ||
lcc command.LimaCmdCreator | ||
} | ||
|
||
func newGenerateSupportBundleAction( | ||
logger flog.Logger, | ||
builder support.BundleBuilder, | ||
lcc command.LimaCmdCreator, | ||
) *generateSupportBundleAction { | ||
return &generateSupportBundleAction{ | ||
logger: logger, | ||
builder: builder, | ||
lcc: lcc, | ||
} | ||
} | ||
|
||
func (a *generateSupportBundleAction) runAdapter(cmd *cobra.Command, args []string) error { | ||
additionalFiles, err := cmd.Flags().GetStringArray("include") | ||
if err != nil { | ||
return err | ||
} | ||
excludeFiles, err := cmd.Flags().GetStringArray("exclude") | ||
if err != nil { | ||
return err | ||
} | ||
return a.run(additionalFiles, excludeFiles) | ||
} | ||
|
||
func (a *generateSupportBundleAction) run(additionalFiles []string, excludeFiles []string) error { | ||
err := a.assertVMExists() | ||
if err != nil { | ||
return err | ||
} | ||
a.logger.Info("Generating support bundle...") | ||
bundleFile, err := a.builder.GenerateSupportBundle(additionalFiles, excludeFiles) | ||
if err != nil { | ||
return err | ||
} | ||
a.logger.Infof("Bundle created: %s", bundleFile) | ||
a.logger.Info("Files posted on a Github issue can be read by anyone.") | ||
a.logger.Info("Please ensure there is no sensitive information in the bundle before uploading.") | ||
return nil | ||
} | ||
|
||
func (a *generateSupportBundleAction) assertVMExists() error { | ||
status, err := lima.GetVMStatus(a.lcc, a.logger, limaInstanceName) | ||
if err != nil { | ||
return err | ||
} | ||
switch status { | ||
case lima.Nonexistent: | ||
return fmt.Errorf("cannot create support bundle for nonexistent VM, run `finch %s init` to create a new instance", | ||
virtualMachineRootCmd) | ||
default: | ||
return nil | ||
} | ||
} |
Oops, something went wrong.