Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix symlink arrays for Bash 3 #22559

Merged
merged 1 commit into from Apr 18, 2019

Conversation

Projects
None yet
5 participants
@cblecker
Copy link
Member

cblecker commented Apr 12, 2019

Yes, you read right, Bash 3. Unfortunately, there is a difference between how Bash 3 and more recent versions handle looping via arrays.

When #22218 was put in, these arrays were changed to a single entry with an empty string, as opposed to an empty array.

When

for linkname in "${OC_BINARY_SYMLINKS[@]##*/}"; do
ln -sf oc "${OS_OUTPUT_BINPATH}/${platform}/${linkname}"
done
ends up running in Bash 5, it doesn't run the loop because it sees a single empty entry. When it runs on Bash 3 however, it runs a single time, with ${linkname} being empty. This results in a symlink of oc -> oc, overwriting the binary that was just generated.

The one place where this matters is on Darwin, as it still ships with Bash 3 out of the box, and oc is the one binary you may actually need to build on Darwin.

What happens on Bash 5:

+ os::build::make_openshift_binary_symlinks
++ os::build::host_platform
+++ go env GOHOSTOS
+++ go env GOHOSTARCH
++ echo darwin/amd64
+ platform=darwin/amd64
+ [[ -f /opt/gopath/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/openshift ]]
+ [[ -f /opt/gopath/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/oc ]]
+ for linkname in "${OC_BINARY_COPY[@]##*/}"
+ ln -sf oc /opt/gopath/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/kubectl
+ cleanup
+ return_code=0

What happens on Bash 3, prior to this PR:

+ os::build::make_openshift_binary_symlinks
++ os::build::host_platform
+++ go env GOHOSTOS
+++ go env GOHOSTARCH
++ echo darwin/amd64
+ platform=darwin/amd64
+ [[ -f /private/tmp/openshift-cli-20190411-16204-14onmse/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/openshift ]]
+ [[ -f /private/tmp/openshift-cli-20190411-16204-14onmse/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/oc ]]
+ for linkname in '"${OC_BINARY_SYMLINKS[@]##*/}"'
+ ln -sf oc /private/tmp/openshift-cli-20190411-16204-14onmse/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/
+ for linkname in '"${OC_BINARY_COPY[@]##*/}"'
+ ln -sf oc /private/tmp/openshift-cli-20190411-16204-14onmse/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/kubectl
+ cleanup
+ return_code=0

What happens on Bash 3, after this PR:

+ os::build::make_openshift_binary_symlinks
++ os::build::host_platform
+++ go env GOHOSTOS
+++ go env GOHOSTARCH
++ echo darwin/amd64
+ platform=darwin/amd64
+ [[ -f /private/tmp/openshift-cli-20190411-34396-1mczt4j/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/openshift ]]
+ [[ -f /private/tmp/openshift-cli-20190411-34396-1mczt4j/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/oc ]]
+ ((  0  ))
+ ((  1  ))
+ for linkname in '"${OC_BINARY_COPY[@]##*/}"'
+ ln -sf oc /private/tmp/openshift-cli-20190411-34396-1mczt4j/src/github.com/openshift/origin/_output/local/bin/darwin/amd64/kubectl
+ cleanup
+ return_code=0

/assign @smarterclayton @deads2k

@cblecker cblecker force-pushed the cblecker:bash-3-is-awful branch from 7e11fd3 to 15a60cd Apr 12, 2019

@openshift-ci-robot openshift-ci-robot added size/S and removed size/XS labels Apr 12, 2019

@cblecker

This comment has been minimized.

Copy link
Member Author

cblecker commented Apr 12, 2019

/retest

@cblecker

This comment has been minimized.

Copy link
Member Author

cblecker commented Apr 15, 2019

Tests are passing.

It would be good to get this in, as it impacts building the oc tool on Darwin, in particular, distributing the tool via Homebrew.

ping @smarterclayton @deads2k

@smarterclayton

This comment has been minimized.

Copy link
Member

smarterclayton commented Apr 18, 2019

Ugh, kube now requires bash 4 and up for some scripting. Let me review, we can tolerate some drift for near term.

@smarterclayton

This comment has been minimized.

Copy link
Member

smarterclayton commented Apr 18, 2019

/lgtm

@openshift-ci-robot

This comment has been minimized.

Copy link

openshift-ci-robot commented Apr 18, 2019

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cblecker, smarterclayton

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-robot openshift-merge-robot merged commit 60373e7 into openshift:master Apr 18, 2019

10 checks passed

ci/prow/artifacts Job succeeded.
Details
ci/prow/cmd Job succeeded.
Details
ci/prow/e2e-aws Job succeeded.
Details
ci/prow/e2e-aws-serial Job succeeded.
Details
ci/prow/images Job succeeded.
Details
ci/prow/integration Job succeeded.
Details
ci/prow/unit Job succeeded.
Details
ci/prow/verify Job succeeded.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
tide In merge pool.
Details

@cblecker cblecker deleted the cblecker:bash-3-is-awful branch Apr 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.