github.com/openshift/installer@v1.4.17/cmd/openshift-install/analyze.go (about) 1 package main 2 3 import ( 4 "path/filepath" 5 6 "github.com/pkg/errors" 7 "github.com/sirupsen/logrus" 8 "github.com/spf13/cobra" 9 10 "github.com/openshift/installer/cmd/openshift-install/command" 11 "github.com/openshift/installer/pkg/gather/service" 12 ) 13 14 var ( 15 analyzeOpts struct { 16 gatherBundle string 17 } 18 ) 19 20 func newAnalyzeCmd() *cobra.Command { 21 cmd := &cobra.Command{ 22 Use: "analyze", 23 Short: "Analyze debugging data for a given installation failure", 24 Long: `Analyze debugging data for a given installation failure. 25 26 This command helps users to analyze the reasons for an installation that failed while bootstrapping.`, 27 Args: cobra.ExactArgs(0), 28 Run: func(_ *cobra.Command, _ []string) { 29 gatherBundle := analyzeOpts.gatherBundle 30 if gatherBundle == "" { 31 var err error 32 gatherBundle, err = getGatherBundleFromAssetsDirectory() 33 if err != nil { 34 logrus.Fatal(err) 35 } 36 } 37 if !filepath.IsAbs(gatherBundle) { 38 gatherBundle = filepath.Join(command.RootOpts.Dir, gatherBundle) 39 } 40 if err := service.AnalyzeGatherBundle(gatherBundle); err != nil { 41 logrus.Fatal(err) 42 } 43 }, 44 } 45 cmd.PersistentFlags().StringVar(&analyzeOpts.gatherBundle, "file", "", "Filename of the bootstrap gather bundle; either absolute or relative to the assets directory") 46 return cmd 47 } 48 49 func getGatherBundleFromAssetsDirectory() (string, error) { 50 matches, err := filepath.Glob(filepath.Join(command.RootOpts.Dir, "log-bundle-*.tar.gz")) 51 if err != nil { 52 return "", errors.Wrap(err, "could not find gather bundles in assets directory") 53 } 54 switch len(matches) { 55 case 0: 56 return "", errors.New("no bootstrap gather bundles found in assets directory") 57 case 1: 58 return matches[0], nil 59 default: 60 return "", errors.New("multiple bootstrap gather bundles found in assets directory; select specific gather bundle by using the --file flag") 61 } 62 }