Skip to content

Conversation

@crawford
Copy link
Contributor

@crawford crawford commented Dec 5, 2018

Instead of requiring that the user has Terraform installed, this now
includes the pre-built Terraform binary within the installer. At
runtime, the installer unpacks Terraform into the temporary directory
and executes it from that location. This also simplifies the version
output - since the Terraform version is known at build-time, there is
no need to show the user. Lastly, this cleans up some of the log
messages so that they don't explicitly refer to Terraform.

Including Terraform in the installer adds 18MB to the binary size,
bringing the total up to 82MB.

@openshift-ci-robot openshift-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 5, 2018
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: crawford

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

The pull request process is described here

Details 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-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 5, 2018
@smarterclayton
Copy link
Contributor

What's the final size?

@crawford
Copy link
Contributor Author

crawford commented Dec 5, 2018

Size after this change:

$ size bin/openshift-install
   text    data     bss     dec     hex filename
55288484         375497  253360 55917341        3553b1d bin/openshift-install

$ ls -lah bin/openshift-install
-rwxr-xr-x 1 alex users 82M Dec  5 15:21 bin/openshift-install

v.s. before:

$ size bin/openshift-install
   text    data     bss     dec     hex filename
37110376         375497  253360 37739233        23fdae1 bin/openshift-install

$ ls -lah bin/openshift-install
-rwxr-xr-x 1 alex users 64M Dec  5 15:23 bin/openshift-install

@smarterclayton
Copy link
Contributor

smarterclayton commented Dec 5, 2018

Well within reason. I assume having a vendor tree you splice in as an switch filepath.Base(os.Args[0]) { case "terraform": terraform.Entrypoint(); default: installer.ENtrypoint() } was deemed too painful right now?

@crawford
Copy link
Contributor Author

crawford commented Dec 5, 2018

I didn't bother looking at vendoring Terraform because I was almost certain that was going to be painful and would take much longer to accomplish. We can always revisit this approach later.

@smarterclayton
Copy link
Contributor

Yeah that's fine. I only bring it up because of previous discussion around OSBS, all I care about right now is something that works.

@crawford
Copy link
Contributor Author

crawford commented Dec 5, 2018

Curious if this actually passes the tests...

/retest

@wking
Copy link
Member

wking commented Dec 5, 2018

I'm fine with this approach in the short term. 👍

@crawford crawford changed the title WIP: move terraform into the installer *: include terraform in the installer binary Dec 5, 2018
@openshift-ci-robot openshift-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 5, 2018
@crawford
Copy link
Contributor Author

crawford commented Dec 6, 2018

/retest

@wking
Copy link
Member

wking commented Dec 6, 2018

release.sh will need terraform for the target OS/arch. Not sure off the top of my head how to address that. Shifting hardlinks?

Instead of requiring that the user has Terraform installed, this now
includes the pre-built Terraform binary within the installer. At
runtime, the installer unpacks Terraform into the temporary directory
and executes it from that location. This also simplifies the version
output - since the Terraform version is known at build-time, there is
no need to show the user. Lastly, this cleans up some of the log
messages so that they don't explicitly refer to Terraform.

Including Terraform in the installer adds 18MB to the binary size,
bringing the total up to 82MB.
@crawford
Copy link
Contributor Author

crawford commented Dec 6, 2018

release.sh will need terraform for the target OS/arch. Not sure off the top of my head how to address that. Shifting hardlinks?

We also need to address the "caching" logic. It's currently just checking to see that terraform exists. It doesn't verify that it is the correct version or architecture. I think if we solve that, it also solves the issue you brought up.

fi &&
mkdir -p data/data/bin &&
rm -f data/data/bin/terraform &&
ln -s "../../../${TERRAFORM_BINARY}" data/data/bin/terraform
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wking do you know a good way of calculating "../../.." from "data/data/bin/terraform"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came up with the following, but it may be more effort than it is worth:

diff --git a/hack/get-terraform.sh b/hack/get-terraform.sh
index aae1b69cd..c47aaa11e 100755
--- a/hack/get-terraform.sh
+++ b/hack/get-terraform.sh
@@ -25,6 +25,7 @@ fi &&
 TERRAFORM_VERSION="0.11.8" &&
 TERRAFORM_URL="https://releases.hashicorp.com/terraform/${TERRAFORM_VERSION}/terraform_${TERRAFORM_VERSION}_${OS}_${ARCH}.zip" &&
 TERRAFORM_BINARY=".cache/terraform_${TERRAFORM_VERSION}_${OS}_${ARCH}"
+TERRAFORM_SYMLINK="data/data/bin/terraform"
 cd "$(dirname "$0")/.." &&
 if [ ! -x "${TERRAFORM_BINARY}" ]
 then
@@ -33,6 +34,6 @@ then
        curl -L "${TERRAFORM_URL}" | "${FUNZIP}" >"${TERRAFORM_BINARY}" &&
        chmod +x "${TERRAFORM_BINARY}"
 fi &&
-mkdir -p data/data/bin &&
-rm -f data/data/bin/terraform &&
-ln -s "../../../${TERRAFORM_BINARY}" data/data/bin/terraform
+mkdir -p "$(dirname "${TERRAFORM_SYMLINK}")" &&
+rm -f "${TERRAFORM_SYMLINK}" &&
+ln -s "$(dirname "${TERRAFORM_SYMLINK}" | sed 's_[^/]*_.._g')/${TERRAFORM_BINARY}" "${TERRAFORM_SYMLINK}"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you know a good way of calculating "../../.." from "data/data/bin/terraform"?

Well, one way would be to use hardlinks instead of symlinks:

$ rm -f data/data/bin/terraform
$ ls -l .cache/terraform_0.11.8_linux_amd64 
-rwxr-xr-x. 1 trking trking 76422048 Dec  6 21:54 .cache/terraform_0.11.8_linux_amd64
$ ln .cache/terraform_0.11.8_linux_amd64 data/data/bin/terraform
$ ls -l .cache/terraform_0.11.8_linux_amd64 
-rwxr-xr-x. 2 trking trking 76422048 Dec  6 21:54 .cache/terraform_0.11.8_linux_amd64
$ ls -l data/data/bin/terraform 
-rwxr-xr-x. 2 trking trking 76422048 Dec  6 21:54 data/data/bin/terraform

See the <number of links> field changing from 1 to 2 after the ln call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume all of this will always be on the same filesystem, so a hardlink should work. I'll go with that instead.

@openshift-ci-robot
Copy link
Contributor

@crawford: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws 4014f34 link /test e2e-aws

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

return errors.Wrap(err, "failed to unpack Terraform binary")
}

err = os.Chmod(filepath.Join(dir, executablePath), 0555)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need FromSlash too, and so will exec.Command(filepath.Join(clusterDir, executablePath), args...). In fact, why are we bothering with bin at all? This would be easier if we just had executableFilename = "terraform", or some such. And since we have CI to catch us if we typo an instance, I'd be fine hard-coding "terraform"everywhere and skipping the variable altogether (although I'm also fine with a slash-lessexecutableFilename`).

// Terraform call itself failed, in which case, details can be found in the
// output.
func (ex *executor) execute(clusterDir string, args ...string) error {
func Execute(clusterDir string, args ...string) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to make this public. Can we change this (and the name in the godoc above) to execute?

@wking
Copy link
Member

wking commented Dec 7, 2018

I left a few minor suggestions inline, but I'm fine landing this as-is (after you squash the WIP commit in) and iterating afterwards if you don't want to pick up the suggestions now.

@crawford
Copy link
Contributor Author

Closing in favor of #822.

/close

@openshift-ci-robot
Copy link
Contributor

@crawford: Closed this PR.

Details

In response to this:

Closing in favor of #822.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@crawford crawford deleted the terraform branch December 10, 2018 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants