Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions hack/ci-e2e-test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -e
set -euo pipefail

function cleanup {
set +e
Expand All @@ -9,39 +9,56 @@ function cleanup {
echo "Cleaning up machines."
./test/tools/integration/cleanup_machines.sh

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

export BUILD_ID="${BUILD_ID}"

# Install dependencies
echo "Installing dependencies."
apt update && apt install -y jq rsync unzip &&
curl --retry 5 -LO https://storage.googleapis.com/kubernetes-release/release/v1.10.0/bin/linux/amd64/kubectl &&
curl --retry 5 -LO \
https://storage.googleapis.com/kubernetes-release/release/v1.12.4/bin/linux/amd64/kubectl &&
chmod +x kubectl &&
mv kubectl /usr/local/bin

# Generate ssh keypair
echo "Generating ssh keypairs."
ssh-keygen -f $HOME/.ssh/id_rsa -P ''
echo "Set permissions for ssh key"
chmod 0700 $HOME/.ssh

# Initialize terraform
echo "Initalizing terraform"
cd test/tools/integration
make terraform
cp provider.tf{.disabled,}
terraform init --input=false --backend-config=key=$BUILD_ID
export TF_VAR_hcloud_token="${HZ_E2E_TOKEN}"
export TF_VAR_hcloud_sshkey_content="$(cat ~/.ssh/id_rsa.pub)"
export TF_VAR_hcloud_test_server_name="machine-controller-test-${BUILD_ID}"

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

set -e
cd -

# Build binaries
echo "Building machine-controller and webhook"
make machine-controller webhook
Expand Down
14 changes: 11 additions & 3 deletions test/tools/integration/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SHELL := /bin/bash

BUILD_ID ?= $(USER)-local

USER ?= prow
Expand All @@ -10,14 +12,20 @@ else ifeq ($(MAKECMDGOALS),destroy)
EXTRA_ARG = -force
endif

.PHONY: terraform
terraform:
@if ! which terraform; then \
curl https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip > /tmp/terraform.zip && \
unzip -n /tmp/terraform.zip terraform; \
curl https://releases.hashicorp.com/terraform/0.11.11/terraform_0.11.11_linux_amd64.zip \
--retry 5 \
-o /tmp/terraform.zip && \
unzip -n /tmp/terraform.zip terraform && \
mv terraform /usr/local/bin; \
fi

.terraform: terraform
terraform init >/dev/null 2>&1
@if ! ls .terraform &>/dev/null; then \
terraform init &>/dev/null; \
fi

.PHONY: plan apply destroy
plan apply destroy: .terraform
Expand Down
2 changes: 1 addition & 1 deletion test/tools/integration/cleanup_machines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -x

cd $(dirname $0)

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


ssh_exec() { ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$ADDR $@; }
Expand Down
3 changes: 3 additions & 0 deletions test/tools/integration/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
output "ip" {
value = "${hcloud_server.machine-controller-test.ipv4_address}"
}
14 changes: 14 additions & 0 deletions test/tools/integration/provider.tf.disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
terraform {
backend "s3" {
bucket = "terraform-machine-controller"
endpoint = "http://minio.minio:9000"
access_key = "PMIC1HMXNB2R67RNPIX8"
secret_key = "NemiWx+uY79rcJ0hXrktzHk1dm9c0k85WepbuSlK"
region = "myregion"
skip_region_validation = "true"
skip_metadata_api_check = "true"
skip_requesting_account_id = "true"
skip_credentials_validation = "true"
force_path_style = "true"
}
}
2 changes: 1 addition & 1 deletion test/tools/integration/provision_master.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -x

cd $(dirname $0)

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


ssh_exec() { ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@$ADDR $@; }
Expand Down
6 changes: 5 additions & 1 deletion test/tools/integration/variables.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
variable "hcloud_token" {}
variable "hcloud_sshkey_content" {}
variable "hcloud_sshkey_name" {}

variable "hcloud_sshkey_name" {
default = "machine-controller-e2e"
}

variable "hcloud_test_server_name" {}