From 2f5a74e6b82a79730b3e7b8eda524160b6cd10df Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 9 Jun 2019 15:11:17 -0700 Subject: [PATCH] cmd/openshift-install/gather: Guard against cluster-side artifact collisions Support running multiple gather commands without cluster-side collisions. For example: 1. Alice runs gather bootstrap, her command writes a tarball on the bootstrap machine and starts downloading it. 2. Bob runs gather bootstrap, his command starts writing to the same tarball on the bootstrap machine. 3. Alice's download croaks on the truncated file. But maybe Alice's download already has an open file descriptor, so Bob's clobber doesn't break the download? I guess it depends on the specifics of how installer-gather.sh's > ~/log-bundle.tar.gz worked. With this commit, we avoid potential issues by passing in an optional gather ID which the cluster-side scripts use to uniquify their collection directories. We still race if multiple gathers are launched in the same second, but that's at least a narrower window, and we can close it later by using a better source of random characters. --- cmd/openshift-install/gather.go | 7 ++++--- .../files/usr/local/bin/installer-gather.sh | 17 ++++++++++++----- .../usr/local/bin/installer-masters-gather.sh | 8 +++++++- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/cmd/openshift-install/gather.go b/cmd/openshift-install/gather.go index f8331dff46d..83c6bcafe6b 100644 --- a/cmd/openshift-install/gather.go +++ b/cmd/openshift-install/gather.go @@ -113,11 +113,12 @@ func logGatherBootstrap(bootstrap string, port int, masters []string, directory if err != nil { return errors.Wrap(err, "failed to create SSH client") } - if err := ssh.Run(client, fmt.Sprintf("/usr/local/bin/installer-gather.sh %s", strings.Join(masters, " "))); err != nil { + gatherID := time.Now().Format("20060102150405") + if err := ssh.Run(client, fmt.Sprintf("/usr/local/bin/installer-gather.sh --id %s %s", gatherID, strings.Join(masters, " "))); err != nil { return errors.Wrap(err, "failed to run remote command") } - file := filepath.Join(directory, fmt.Sprintf("log-bundle-%s.tar.gz", time.Now().Format("20060102150405"))) - if err := ssh.PullFileTo(client, "/home/core/log-bundle.tar.gz", file); err != nil { + file := filepath.Join(directory, fmt.Sprintf("log-bundle-%s.tar.gz", gatherID)) + if err := ssh.PullFileTo(client, fmt.Sprintf("/home/core/log-bundle-%s.tar.gz", gatherID), file); err != nil { return errors.Wrap(err, "failed to pull log file from remote") } logrus.Infof("Bootstrap gather logs captured here %q", file) diff --git a/data/data/bootstrap/files/usr/local/bin/installer-gather.sh b/data/data/bootstrap/files/usr/local/bin/installer-gather.sh index 254895a1f06..5a010e70430 100755 --- a/data/data/bootstrap/files/usr/local/bin/installer-gather.sh +++ b/data/data/bootstrap/files/usr/local/bin/installer-gather.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash -ARTIFACTS="/tmp/artifacts" +if test "x${1}" = 'x--id' +then + GATHER_ID="${2}" + shift 2 +fi + +ARTIFACTS="/tmp/artifacts-${GATHER_ID}" echo "Gathering bootstrap journals ..." mkdir -p "${ARTIFACTS}/bootstrap/journals" @@ -112,8 +118,9 @@ do echo "Collecting info from ${master}" scp -o PreferredAuthentications=publickey -o StrictHostKeyChecking=false -o UserKnownHostsFile=/dev/null -q /usr/local/bin/installer-masters-gather.sh "core@${master}:" mkdir -p "${ARTIFACTS}/control-plane/${master}" - ssh -o PreferredAuthentications=publickey -o StrictHostKeyChecking=false -o UserKnownHostsFile=/dev/null "core@${master}" -C 'sudo ./installer-masters-gather.sh' ~/log-bundle.tar.gz -echo "Log bundle written to ~/log-bundle.tar.gz" +TAR_FILE="${TAR_FILE:-${HOME}/log-bundle-${GATHER_ID}.tar.gz}" +tar cz -C "${ARTIFACTS}" . >"${TAR_FILE}" +echo "Log bundle written to ${TAR_FILE}" diff --git a/data/data/bootstrap/files/usr/local/bin/installer-masters-gather.sh b/data/data/bootstrap/files/usr/local/bin/installer-masters-gather.sh index 4fd080ca099..8e674722a69 100755 --- a/data/data/bootstrap/files/usr/local/bin/installer-masters-gather.sh +++ b/data/data/bootstrap/files/usr/local/bin/installer-masters-gather.sh @@ -1,6 +1,12 @@ #!/usr/bin/env bash -ARTIFACTS="${1:-/tmp/artifacts}" +if test "x${1}" = 'x--id' +then + GATHER_ID="${2}" + shift 2 +fi + +ARTIFACTS="/tmp/artifacts-${GATHER_ID}" mkdir -p "${ARTIFACTS}" echo "Gathering master journals ..."