Skip to content

Commit 9d688b2

Browse files
alvaroalemankubermatic-bot
authored andcommitted
Use S3 bucket for CI e2e state (#436)
* Use S3 bucket for CI e2e state * Use terraform output for ip address * Move terraform into PATH * Fix bash loop * Update bucket name * Hopefully fix ssh key * Fix ssh key import * Hopefully final fix for s3-based state
1 parent 19dc4c6 commit 9d688b2

File tree

7 files changed

+60
-14
lines changed

7 files changed

+60
-14
lines changed

hack/ci-e2e-test.sh

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -e
3+
set -euo pipefail
44

55
function cleanup {
66
set +e
@@ -9,39 +9,56 @@ function cleanup {
99
echo "Cleaning up machines."
1010
./test/tools/integration/cleanup_machines.sh
1111

12+
cd test/tools/integration
1213
for try in {1..20}; do
1314
# Clean up master
1415
echo "Cleaning up controller, attempt ${try}"
15-
make -C test/tools/integration destroy
16+
# Clean up only the server, we want to keep the key as only one key may exist
17+
# for a given fingerprint
18+
terraform destroy -target=hcloud_server.machine-controller-test -force
1619
if [[ $? == 0 ]]; then break; fi
1720
echo "Sleeping for $try seconds"
1821
sleep ${try}s
1922
done
2023
}
2124
trap cleanup EXIT
2225

23-
export BUILD_ID="${BUILD_ID}"
24-
2526
# Install dependencies
2627
echo "Installing dependencies."
2728
apt update && apt install -y jq rsync unzip &&
28-
curl --retry 5 -LO https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubectl &&
29+
curl --retry 5 -LO \
30+
https://storage.googleapis.com/kubernetes-release/release/v1.12.4/bin/linux/amd64/kubectl &&
2931
chmod +x kubectl &&
3032
mv kubectl /usr/local/bin
3133

3234
# Generate ssh keypair
33-
echo "Generating ssh keypairs."
34-
ssh-keygen -f $HOME/.ssh/id_rsa -P ''
35+
echo "Set permissions for ssh key"
36+
chmod 0700 $HOME/.ssh
37+
38+
# Initialize terraform
39+
echo "Initalizing terraform"
40+
cd test/tools/integration
41+
make terraform
42+
cp provider.tf{.disabled,}
43+
terraform init --input=false --backend-config=key=$BUILD_ID
44+
export TF_VAR_hcloud_token="${HZ_E2E_TOKEN}"
45+
export TF_VAR_hcloud_sshkey_content="$(cat ~/.ssh/id_rsa.pub)"
46+
export TF_VAR_hcloud_test_server_name="machine-controller-test-${BUILD_ID}"
3547

3648
for try in {1..20}; do
49+
set +e
3750
# Create environment at cloud provider
3851
echo "Creating environment at cloud provider."
39-
make -C test/tools/integration apply
52+
terraform import hcloud_ssh_key.default 265119
53+
terraform apply -auto-approve
4054
if [[ $? == 0 ]]; then break; fi
4155
echo "Sleeping for $try seconds"
4256
sleep ${try}s
4357
done
4458

59+
set -e
60+
cd -
61+
4562
# Build binaries
4663
echo "Building machine-controller and webhook"
4764
make machine-controller webhook

test/tools/integration/Makefile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SHELL := /bin/bash
2+
13
BUILD_ID ?= $(USER)-local
24

35
USER ?= prow
@@ -10,14 +12,20 @@ else ifeq ($(MAKECMDGOALS),destroy)
1012
EXTRA_ARG = -force
1113
endif
1214

15+
.PHONY: terraform
1316
terraform:
1417
@if ! which terraform; then \
15-
curl https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip > /tmp/terraform.zip && \
16-
unzip -n /tmp/terraform.zip terraform; \
18+
curl https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip \
19+
--retry 5 \
20+
-o /tmp/terraform.zip && \
21+
unzip -n /tmp/terraform.zip terraform && \
22+
mv terraform /usr/local/bin; \
1723
fi
1824

1925
.terraform: terraform
20-
terraform init >/dev/null 2>&1
26+
@if ! ls .terraform &>/dev/null; then \
27+
terraform init &>/dev/null; \
28+
fi
2129

2230
.PHONY: plan apply destroy
2331
plan apply destroy: .terraform

test/tools/integration/cleanup_machines.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -x
55

66
cd $(dirname $0)
77

8-
export ADDR=$(cat terraform.tfstate |jq -r '.modules[0].resources["hcloud_server.machine-controller-test"].primary.attributes.ipv4_address')
8+
export ADDR=$(terraform output -json|jq '.ip.value' -r)
99

1010

1111
ssh_exec() { ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$ADDR $@; }

test/tools/integration/output.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
output "ip" {
2+
value = "${hcloud_server.machine-controller-test.ipv4_address}"
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
backend "s3" {
3+
bucket = "terraform-machine-controller"
4+
endpoint = "http://minio.minio:9000"
5+
access_key = "PMIC1HMXNB2R67RNPIX8"
6+
secret_key = "NemiWx+uY79rcJ0hXrktzHk1dm9c0k85WepbuSlK"
7+
region = "myregion"
8+
skip_region_validation = "true"
9+
skip_metadata_api_check = "true"
10+
skip_requesting_account_id = "true"
11+
skip_credentials_validation = "true"
12+
force_path_style = "true"
13+
}
14+
}

test/tools/integration/provision_master.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set -x
55

66
cd $(dirname $0)
77

8-
export ADDR=$(cat terraform.tfstate |jq -r '.modules[0].resources["hcloud_server.machine-controller-test"].primary.attributes.ipv4_address')
8+
export ADDR=$(terraform output -json|jq '.ip.value' -r)
99

1010

1111
ssh_exec() { ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$ADDR $@; }
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
variable "hcloud_token" {}
22
variable "hcloud_sshkey_content" {}
3-
variable "hcloud_sshkey_name" {}
3+
4+
variable "hcloud_sshkey_name" {
5+
default = "machine-controller-e2e"
6+
}
7+
48
variable "hcloud_test_server_name" {}

0 commit comments

Comments
 (0)