@@ -34,7 +34,7 @@ import (
3434 _ "github.com/openshift/installer/pkg/gather/gcp"
3535)
3636
37- func newGatherCmd () * cobra.Command {
37+ func newGatherCmd (ctx context. Context ) * cobra.Command {
3838 cmd := & cobra.Command {
3939 Use : "gather" ,
4040 Short : "Gather debugging data for a given installation failure" ,
@@ -47,7 +47,7 @@ to debug the installation failures`,
4747 return cmd .Help ()
4848 },
4949 }
50- cmd .AddCommand (newGatherBootstrapCmd ())
50+ cmd .AddCommand (newGatherBootstrapCmd (ctx ))
5151 return cmd
5252}
5353
@@ -58,15 +58,15 @@ var gatherBootstrapOpts struct {
5858 skipAnalysis bool
5959}
6060
61- func newGatherBootstrapCmd () * cobra.Command {
61+ func newGatherBootstrapCmd (ctx context. Context ) * cobra.Command {
6262 cmd := & cobra.Command {
6363 Use : "bootstrap" ,
6464 Short : "Gather debugging data for a failing-to-bootstrap control plane" ,
6565 Args : cobra .ExactArgs (0 ),
6666 Run : func (_ * cobra.Command , _ []string ) {
6767 cleanup := command .SetupFileHook (command .RootOpts .Dir )
6868 defer cleanup ()
69- bundlePath , err := runGatherBootstrapCmd (command .RootOpts .Dir )
69+ bundlePath , err := runGatherBootstrapCmd (ctx , command .RootOpts .Dir )
7070 if err != nil {
7171 logrus .Fatal (err )
7272 }
@@ -87,14 +87,14 @@ func newGatherBootstrapCmd() *cobra.Command {
8787 return cmd
8888}
8989
90- func runGatherBootstrapCmd (directory string ) (string , error ) {
90+ func runGatherBootstrapCmd (ctx context. Context , directory string ) (string , error ) {
9191 assetStore , err := assetstore .NewStore (directory )
9292 if err != nil {
9393 return "" , errors .Wrap (err , "failed to create asset store" )
9494 }
9595 // add the default bootstrap key pair to the sshKeys list
9696 bootstrapSSHKeyPair := & tls.BootstrapSSHKeyPair {}
97- if err := assetStore .Fetch (bootstrapSSHKeyPair ); err != nil {
97+ if err := assetStore .Fetch (ctx , bootstrapSSHKeyPair ); err != nil {
9898 return "" , errors .Wrapf (err , "failed to fetch %s" , bootstrapSSHKeyPair .Name ())
9999 }
100100 tmpfile , err := os .CreateTemp ("" , "bootstrap-ssh" )
@@ -118,7 +118,7 @@ func runGatherBootstrapCmd(directory string) (string, error) {
118118
119119 if ha .Bootstrap == "" && len (ha .Masters ) == 0 {
120120 config := & installconfig.InstallConfig {}
121- if err := assetStore .Fetch (config ); err != nil {
121+ if err := assetStore .Fetch (ctx , config ); err != nil {
122122 return "" , errors .Wrapf (err , "failed to fetch %s" , config .Name ())
123123 }
124124
@@ -140,6 +140,7 @@ func runGatherBootstrapCmd(directory string) (string, error) {
140140
141141func gatherBootstrap (bootstrap string , port int , masters []string , directory string ) (string , error ) {
142142 gatherID := time .Now ().Format ("20060102150405" )
143+ archives := map [string ]string {}
143144
144145 serialLogBundle := filepath .Join (directory , fmt .Sprintf ("serial-log-bundle-%s.tar.gz" , gatherID ))
145146 serialLogBundlePath , err := filepath .Abs (serialLogBundle )
@@ -154,9 +155,32 @@ func gatherBootstrap(bootstrap string, port int, masters []string, directory str
154155 logrus .Info ("Pulling VM console logs" )
155156 if err := consoleGather .Run (); err != nil {
156157 logrus .Infof ("Failed to gather VM console logs: %s" , err .Error ())
158+ } else {
159+ archives [serialLogBundlePath ] = "serial"
157160 }
158161 }
159162
163+ clusterLogBundlePath , err := pullLogsFromBootstrap (gatherID , bootstrap , port , masters , directory )
164+ if err != nil {
165+ logrus .Infof ("Failed to gather bootstrap logs: %s" , err .Error ())
166+ } else {
167+ archives [clusterLogBundlePath ] = ""
168+ }
169+
170+ if len (archives ) == 0 {
171+ return "" , fmt .Errorf ("failed to gather VM console and bootstrap logs" )
172+ }
173+
174+ logBundlePath := filepath .Join (directory , fmt .Sprintf ("log-bundle-%s.tar.gz" , gatherID ))
175+ err = serialgather .CombineArchives (logBundlePath , archives )
176+ if err != nil {
177+ return "" , errors .Wrap (err , "failed to combine archives" )
178+ }
179+
180+ return logBundlePath , nil
181+ }
182+
183+ func pullLogsFromBootstrap (gatherID string , bootstrap string , port int , masters []string , directory string ) (string , error ) {
160184 logrus .Info ("Pulling debug logs from the bootstrap machine" )
161185 client , err := ssh .NewClient ("core" , net .JoinHostPort (bootstrap , strconv .Itoa (port )), gatherBootstrapOpts .sshKeys )
162186 if err != nil {
@@ -180,14 +204,7 @@ func gatherBootstrap(bootstrap string, port int, masters []string, directory str
180204 return "" , errors .Wrap (err , "failed to stat log file" )
181205 }
182206
183- logBundlePath := filepath .Join (filepath .Dir (clusterLogBundlePath ), fmt .Sprintf ("log-bundle-%s.tar.gz" , gatherID ))
184- archives := map [string ]string {serialLogBundlePath : "serial" , clusterLogBundlePath : "" }
185- err = serialgather .CombineArchives (logBundlePath , archives )
186- if err != nil {
187- return "" , errors .Wrap (err , "failed to combine archives" )
188- }
189-
190- return logBundlePath , nil
207+ return clusterLogBundlePath , nil
191208}
192209
193210func logClusterOperatorConditions (ctx context.Context , config * rest.Config ) error {
0 commit comments