Skip to content

Commit bab9c54

Browse files
Merge pull request #8263 from r4f4/bootstrap-gather-console-fix
OCPBUGS-30774: always save serial logs if they were gathered
2 parents fc9bf80 + 177216e commit bab9c54

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

cmd/openshift-install/gather.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ func runGatherBootstrapCmd(ctx context.Context, directory string) (string, error
140140

141141
func 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

193210
func logClusterOperatorConditions(ctx context.Context, config *rest.Config) error {

0 commit comments

Comments
 (0)