From d8eeed53c9a2d381294609692d4dff3b79d7f468 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 29 Nov 2019 16:44:12 +0100 Subject: [PATCH 01/11] Install a newer version of bats I need this for executing bats tests in parallel (`--jobs` flag). Bats hasn't made a release in over a year, so instead of using a release I am installing the archive of the (current) master commit. --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 100c3f291..836642335 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SUDO := $(shell docker info > /dev/null 2> /dev/null || echo "sudo") TEST_FLAGS?= -BATS_VERSION := 1.1.0 +BATS_COMMIT := 87b16eb8ec381beca7f05d028e4ad7cf3f647a0f SHELLCHECK_VERSION := 0.7.0 SHFMT_VERSION := 2.6.4 @@ -135,12 +135,12 @@ cache/%/shfmt-$(SHFMT_VERSION): mkdir -p cache/$* curl --fail -L -o $@ "https://github.com/mvdan/sh/releases/download/v$(SHFMT_VERSION)/shfmt_v$(SHFMT_VERSION)_`echo $* | tr - _`" -test/e2e/bats: cache/bats-v$(BATS_VERSION).tar.gz +test/e2e/bats: cache/bats-core-$(BATS_COMMIT).tar.gz mkdir -p $@ tar -C $@ --strip-components 1 -xzf $< -cache/bats-v$(BATS_VERSION).tar.gz: - curl --fail -L -o $@ https://github.com/bats-core/bats-core/archive/v$(BATS_VERSION).tar.gz +cache/bats-core-$(BATS_COMMIT).tar.gz: + curl --fail -L -o $@ https://github.com/bats-core/bats-core/archive/$(BATS_COMMIT).tar.gz $(GOBIN)/fluxctl: $(FLUXCTL_DEPS) $(GENERATED_TEMPLATES_FILE) go install ./cmd/fluxctl From 091955dd8ef38799a8829d88eea59f4288210500 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 29 Nov 2019 19:47:28 +0100 Subject: [PATCH 02/11] Use bats fork for BATS_JOB_SLOT env variable --- Makefile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 836642335..d88a0c420 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ SUDO := $(shell docker info > /dev/null 2> /dev/null || echo "sudo") TEST_FLAGS?= -BATS_COMMIT := 87b16eb8ec381beca7f05d028e4ad7cf3f647a0f +BATS_COMMIT := 3a1c2f28be260f8687ff83183cef4963faabedd6 SHELLCHECK_VERSION := 0.7.0 SHFMT_VERSION := 2.6.4 @@ -140,7 +140,8 @@ test/e2e/bats: cache/bats-core-$(BATS_COMMIT).tar.gz tar -C $@ --strip-components 1 -xzf $< cache/bats-core-$(BATS_COMMIT).tar.gz: - curl --fail -L -o $@ https://github.com/bats-core/bats-core/archive/$(BATS_COMMIT).tar.gz + # Use 2opremio's fork until https://github.com/bats-core/bats-core/pull/255 is merged + curl --fail -L -o $@ https://github.com/2opremio/bats-core/archive/$(BATS_COMMIT).tar.gz $(GOBIN)/fluxctl: $(FLUXCTL_DEPS) $(GENERATED_TEMPLATES_FILE) go install ./cmd/fluxctl From 3f975672f20b346ed694f360182a089c64a8c8b7 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 29 Nov 2019 19:47:52 +0100 Subject: [PATCH 03/11] Install GNU parallel in CircleCI --- .circleci/config.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9172d96fc..ab7b6f0e4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -90,7 +90,9 @@ jobs: sudo killall apt-get || true sudo apt-get update - sudo apt-get install -y git rng-tools memcached + sudo apt-get install -y git rng-tools memcached parallel + mkdir -p "$HOME/.parallel" + touch "$HOME/.parallel/will-cite" git version docker version - restore_cache: From 321eef4209cd09f3d685d65037d7b6486b6255ab Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 29 Nov 2019 20:27:41 +0100 Subject: [PATCH 04/11] Allow running tests in parallel --- test/e2e/lib/env.bash | 5 +++++ test/e2e/run.bash | 44 ++++++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/test/e2e/lib/env.bash b/test/e2e/lib/env.bash index de5286182..bd42e18b5 100644 --- a/test/e2e/lib/env.bash +++ b/test/e2e/lib/env.bash @@ -10,3 +10,8 @@ KNOWN_HOSTS=$(cat "${FIXTURES_DIR}/known_hosts") export KNOWN_HOSTS GITCONFIG=$(cat "${FIXTURES_DIR}/gitconfig") export GITCONFIG + +# Wire the test to the right cluster when tests are run in parallel +if eval [ -n '$KUBECONFIG_SLOT_'"${BATS_JOB_SLOT}" ]; then + eval export KUBECONFIG='$KUBECONFIG_SLOT_'"${BATS_JOB_SLOT}" +fi diff --git a/test/e2e/run.bash b/test/e2e/run.bash index b134e2377..e080ae929 100755 --- a/test/e2e/run.bash +++ b/test/e2e/run.bash @@ -12,34 +12,48 @@ CACHE_DIR="${FLUX_ROOT_DIR}/cache/$CURRENT_OS_ARCH" KIND_VERSION="v0.5.1" KIND_CACHE_PATH="${CACHE_DIR}/kind-$KIND_VERSION" -KIND_CLUSTER=flux-e2e -USING_KIND=false +KIND_CLUSTER_PREFIX=flux-e2e +BATS_EXTRA_ARGS="" # shellcheck disable=SC1090 source "${E2E_DIR}/lib/defer.bash" trap run_deferred EXIT -# Check if there is a kubernetes cluster running, otherwise use Kind -if ! kubectl version > /dev/null 2>&1; then +function install_kind() { if [ ! -f "${KIND_CACHE_PATH}" ]; then echo '>>> Downloading Kind' mkdir -p "${CACHE_DIR}" curl -sL "https://github.com/kubernetes-sigs/kind/releases/download/${KIND_VERSION}/kind-${CURRENT_OS_ARCH}" -o "${KIND_CACHE_PATH}" fi - echo '>>> Creating Kind Kubernetes cluster' cp "${KIND_CACHE_PATH}" "${FLUX_ROOT_DIR}/test/bin/kind" chmod +x "${FLUX_ROOT_DIR}/test/bin/kind" - kind create cluster --name "${KIND_CLUSTER}" --wait 5m - defer kind --name "${KIND_CLUSTER}" delete cluster > /dev/null 2>&1 || true - KUBECONFIG="$(kind --name="${KIND_CLUSTER}" get kubeconfig-path)" - export KUBECONFIG - USING_KIND=true - kubectl get pods --all-namespaces +} + +# Create multiple Kind clusters and run jobs in parlallel? +# Let users specify how many, e.g. with E2E_KIND_CLUSTER_NUM=3 make e2e +if [ -n "$CI" ]; then + # Use two Kind clusters when running the tests in CircleCI + E2E_KIND_CLUSTER_NUM=2 fi +E2E_KIND_CLUSTER_NUM=${E2E_KIND_CLUSTER_NUM:-1} + +# Check if there is a kubernetes cluster running, otherwise use Kind +if ! kubectl version > /dev/null 2>&1; then + install_kind -if [ "${USING_KIND}" = 'true' ]; then - echo '>>> Loading images into the Kind cluster' - kind --name "${KIND_CLUSTER}" load docker-image 'docker.io/fluxcd/flux:latest' + echo '>>> Creating Kind Kubernetes cluster(s)' + seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind create cluster --name "${KIND_CLUSTER_PREFIX}_{}" --wait 5m + for I in $(seq 1 "${E2E_KIND_CLUSTER_NUM}"); do + defer kind --name "${KIND_CLUSTER_PREFIX}_${I}" delete cluster > /dev/null 2>&1 || true + # Wire tests with the right cluster based on their BATS_JOB_SLOT env variable + eval export KUBECONFIG_SLOT_"${I}"="$(kind --name="${KIND_CLUSTER_PREFIX}_${I}" get kubeconfig-path)" + done + + echo '>>> Loading images into the Kind cluster(s)' + seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind --name "${KIND_CLUSTER_PREFIX}_{}" load docker-image 'docker.io/fluxcd/flux:latest' + if [ "${E2E_KIND_CLUSTER_NUM}" -gt 1 ]; then + BATS_EXTRA_ARGS="--jobs=${E2E_KIND_CLUSTER_NUM}" + fi fi echo '>>> Running the tests' @@ -48,5 +62,5 @@ E2E_TESTS=${E2E_TESTS:-.} ( cd "${E2E_DIR}" # shellcheck disable=SC2086 - "${E2E_DIR}/bats/bin/bats" -t ${E2E_TESTS} + "${E2E_DIR}/bats/bin/bats" -t ${BATS_EXTRA_ARGS} ${E2E_TESTS} ) From 2172bcc0a25929e2217be5476d246f04b2810aca Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Sat, 30 Nov 2019 14:45:49 +0100 Subject: [PATCH 05/11] Load libraries in setup() to access BATS_* variables --- test/e2e/10_helm_chart.bats | 8 ++++---- test/e2e/11_fluxctl_install.bats | 8 ++++---- test/e2e/12_sync.bats | 10 +++++----- test/e2e/13_sync_gc.bats | 10 +++++----- test/e2e/20_commit_signing.bats | 12 ++++++------ test/e2e/20_commit_verification.bats | 12 ++++++------ test/e2e/22_manifest_generation.bats | 10 +++++----- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/test/e2e/10_helm_chart.bats b/test/e2e/10_helm_chart.bats index 20cb23c63..5c9d39bb3 100644 --- a/test/e2e/10_helm_chart.bats +++ b/test/e2e/10_helm_chart.bats @@ -1,10 +1,10 @@ #!/usr/bin/env bats -load lib/env -load lib/install -load lib/poll - function setup() { + load lib/env + load lib/install + load lib/poll + kubectl create namespace "$FLUX_NAMESPACE" install_git_srv install_tiller diff --git a/test/e2e/11_fluxctl_install.bats b/test/e2e/11_fluxctl_install.bats index 454f3c87f..5c15c31f1 100644 --- a/test/e2e/11_fluxctl_install.bats +++ b/test/e2e/11_fluxctl_install.bats @@ -1,10 +1,10 @@ #!/usr/bin/env bats -load lib/env -load lib/install -load lib/poll - function setup() { + load lib/env + load lib/install + load lib/poll + kubectl create namespace "$FLUX_NAMESPACE" install_git_srv install_flux_with_fluxctl diff --git a/test/e2e/12_sync.bats b/test/e2e/12_sync.bats index 91bbe9102..c161f6448 100644 --- a/test/e2e/12_sync.bats +++ b/test/e2e/12_sync.bats @@ -1,13 +1,13 @@ #!/usr/bin/env bats -load lib/env -load lib/install -load lib/poll -load lib/defer - clone_dir="" function setup() { + load lib/env + load lib/install + load lib/poll + load lib/defer + kubectl create namespace "$FLUX_NAMESPACE" # Install flux and the git server, allowing external access install_git_srv git_srv_result diff --git a/test/e2e/13_sync_gc.bats b/test/e2e/13_sync_gc.bats index 459b79101..a0bc536da 100644 --- a/test/e2e/13_sync_gc.bats +++ b/test/e2e/13_sync_gc.bats @@ -1,11 +1,11 @@ #!/usr/bin/env bats -load lib/env -load lib/install -load lib/poll -load lib/defer - function setup() { + load lib/env + load lib/install + load lib/poll + load lib/defer + kubectl create namespace "$FLUX_NAMESPACE" # Install flux and the git server, allowing external access install_git_srv git_srv_result diff --git a/test/e2e/20_commit_signing.bats b/test/e2e/20_commit_signing.bats index a2f353241..0fe07eebc 100644 --- a/test/e2e/20_commit_signing.bats +++ b/test/e2e/20_commit_signing.bats @@ -1,12 +1,12 @@ #!/usr/bin/env bats -load lib/defer -load lib/env -load lib/gpg -load lib/install -load lib/poll - function setup() { + load lib/defer + load lib/env + load lib/gpg + load lib/install + load lib/poll + kubectl create namespace "${FLUX_NAMESPACE}" &> /dev/null # Install the git server, allowing external access diff --git a/test/e2e/20_commit_verification.bats b/test/e2e/20_commit_verification.bats index 4927b7a00..2fe661ab8 100644 --- a/test/e2e/20_commit_verification.bats +++ b/test/e2e/20_commit_verification.bats @@ -1,12 +1,12 @@ #!/usr/bin/env bats -load lib/env -load lib/gpg -load lib/install -load lib/poll -load lib/defer - function setup() { + load lib/env + load lib/gpg + load lib/install + load lib/poll + load lib/defer + kubectl create namespace "${FLUX_NAMESPACE}" # Create a temporary GNUPGHOME diff --git a/test/e2e/22_manifest_generation.bats b/test/e2e/22_manifest_generation.bats index 4450fe1b8..9aad80ef9 100644 --- a/test/e2e/22_manifest_generation.bats +++ b/test/e2e/22_manifest_generation.bats @@ -1,11 +1,11 @@ #!/usr/bin/env bats -load lib/env -load lib/install -load lib/poll -load lib/defer - function setup() { + load lib/env + load lib/install + load lib/poll + load lib/defer + kubectl create namespace "$FLUX_NAMESPACE" # Install flux and the git server, allowing external access install_git_srv git_srv_result "22_manifest_generation/gitsrv" From 7f274fabe444c07d089ea88a6ddda2b7320c62f0 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Sat, 30 Nov 2019 15:12:10 +0100 Subject: [PATCH 06/11] Fix --jobs argument --- test/e2e/run.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/run.bash b/test/e2e/run.bash index e080ae929..8f43fffd5 100755 --- a/test/e2e/run.bash +++ b/test/e2e/run.bash @@ -52,7 +52,7 @@ if ! kubectl version > /dev/null 2>&1; then echo '>>> Loading images into the Kind cluster(s)' seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind --name "${KIND_CLUSTER_PREFIX}_{}" load docker-image 'docker.io/fluxcd/flux:latest' if [ "${E2E_KIND_CLUSTER_NUM}" -gt 1 ]; then - BATS_EXTRA_ARGS="--jobs=${E2E_KIND_CLUSTER_NUM}" + BATS_EXTRA_ARGS="--jobs ${E2E_KIND_CLUSTER_NUM}" fi fi From ca5f56d3e9a92a919b7ece4373fc16b3f6a95de4 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Wed, 4 Dec 2019 16:26:53 +0100 Subject: [PATCH 07/11] Use a large resource_class in CircleCI and use 4 clusters in e2e --- .circleci/config.yml | 1 + test/e2e/run.bash | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index ab7b6f0e4..1959a69f7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -61,6 +61,7 @@ jobs: working_directory: /home/circleci/go/src/github.com/fluxcd/flux machine: image: ubuntu-1604:201903-01 + resource_class: large environment: GO_VERSION: 1.13.1 # We don't need a GOPATH but CircleCI defines it, so we override it diff --git a/test/e2e/run.bash b/test/e2e/run.bash index 8f43fffd5..4bd0dd271 100755 --- a/test/e2e/run.bash +++ b/test/e2e/run.bash @@ -32,8 +32,8 @@ function install_kind() { # Create multiple Kind clusters and run jobs in parlallel? # Let users specify how many, e.g. with E2E_KIND_CLUSTER_NUM=3 make e2e if [ -n "$CI" ]; then - # Use two Kind clusters when running the tests in CircleCI - E2E_KIND_CLUSTER_NUM=2 + # Use four Kind clusters when running the tests in CircleCI + E2E_KIND_CLUSTER_NUM=4 fi E2E_KIND_CLUSTER_NUM=${E2E_KIND_CLUSTER_NUM:-1} From 38c58ed22936788b356e5a94a632eadd3b6b765c Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 5 Dec 2019 11:37:19 +0100 Subject: [PATCH 08/11] Stop using underscores for cluster names to avoid DNS warnings --- test/e2e/run.bash | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/e2e/run.bash b/test/e2e/run.bash index 4bd0dd271..75f25bcaa 100755 --- a/test/e2e/run.bash +++ b/test/e2e/run.bash @@ -42,15 +42,15 @@ if ! kubectl version > /dev/null 2>&1; then install_kind echo '>>> Creating Kind Kubernetes cluster(s)' - seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind create cluster --name "${KIND_CLUSTER_PREFIX}_{}" --wait 5m + seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind create cluster --name "${KIND_CLUSTER_PREFIX}-{}" --wait 5m for I in $(seq 1 "${E2E_KIND_CLUSTER_NUM}"); do - defer kind --name "${KIND_CLUSTER_PREFIX}_${I}" delete cluster > /dev/null 2>&1 || true + defer kind --name "${KIND_CLUSTER_PREFIX}-${I}" delete cluster > /dev/null 2>&1 || true # Wire tests with the right cluster based on their BATS_JOB_SLOT env variable - eval export KUBECONFIG_SLOT_"${I}"="$(kind --name="${KIND_CLUSTER_PREFIX}_${I}" get kubeconfig-path)" + eval export KUBECONFIG_SLOT_"${I}"="$(kind --name="${KIND_CLUSTER_PREFIX}-${I}" get kubeconfig-path)" done echo '>>> Loading images into the Kind cluster(s)' - seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind --name "${KIND_CLUSTER_PREFIX}_{}" load docker-image 'docker.io/fluxcd/flux:latest' + seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind --name "${KIND_CLUSTER_PREFIX}-{}" load docker-image 'docker.io/fluxcd/flux:latest' if [ "${E2E_KIND_CLUSTER_NUM}" -gt 1 ]; then BATS_EXTRA_ARGS="--jobs ${E2E_KIND_CLUSTER_NUM}" fi From c370ed7db5f0468eff92e7808a4210c55f26f34b Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 5 Dec 2019 15:37:49 +0100 Subject: [PATCH 09/11] Measure cluster creation and image loading time --- test/e2e/run.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/e2e/run.bash b/test/e2e/run.bash index 75f25bcaa..2822db1a0 100755 --- a/test/e2e/run.bash +++ b/test/e2e/run.bash @@ -42,7 +42,7 @@ if ! kubectl version > /dev/null 2>&1; then install_kind echo '>>> Creating Kind Kubernetes cluster(s)' - seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind create cluster --name "${KIND_CLUSTER_PREFIX}-{}" --wait 5m + seq 1 "${E2E_KIND_CLUSTER_NUM}" | time parallel -- kind create cluster --name "${KIND_CLUSTER_PREFIX}-{}" --wait 5m for I in $(seq 1 "${E2E_KIND_CLUSTER_NUM}"); do defer kind --name "${KIND_CLUSTER_PREFIX}-${I}" delete cluster > /dev/null 2>&1 || true # Wire tests with the right cluster based on their BATS_JOB_SLOT env variable @@ -50,7 +50,7 @@ if ! kubectl version > /dev/null 2>&1; then done echo '>>> Loading images into the Kind cluster(s)' - seq 1 "${E2E_KIND_CLUSTER_NUM}" | parallel -- kind --name "${KIND_CLUSTER_PREFIX}-{}" load docker-image 'docker.io/fluxcd/flux:latest' + seq 1 "${E2E_KIND_CLUSTER_NUM}" | time parallel -- kind --name "${KIND_CLUSTER_PREFIX}-{}" load docker-image 'docker.io/fluxcd/flux:latest' if [ "${E2E_KIND_CLUSTER_NUM}" -gt 1 ]; then BATS_EXTRA_ARGS="--jobs ${E2E_KIND_CLUSTER_NUM}" fi From b87eb46a3f4a0d8257522d82e3e01bec1c0424f9 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 5 Dec 2019 16:37:18 +0100 Subject: [PATCH 10/11] Fix typo Co-Authored-By: Michael Bridgen --- test/e2e/run.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/run.bash b/test/e2e/run.bash index 2822db1a0..00de456a5 100755 --- a/test/e2e/run.bash +++ b/test/e2e/run.bash @@ -29,7 +29,7 @@ function install_kind() { chmod +x "${FLUX_ROOT_DIR}/test/bin/kind" } -# Create multiple Kind clusters and run jobs in parlallel? +# Create multiple Kind clusters and run jobs in parallel? # Let users specify how many, e.g. with E2E_KIND_CLUSTER_NUM=3 make e2e if [ -n "$CI" ]; then # Use four Kind clusters when running the tests in CircleCI From 7ab4e5be6e9b027a1bfc09e8b07680e6b1725a56 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Thu, 5 Dec 2019 16:45:47 +0100 Subject: [PATCH 11/11] Add comment about ~/.parallel/will-cite --- .circleci/config.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1959a69f7..f31c7bda8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -92,8 +92,9 @@ jobs: sudo apt-get update sudo apt-get install -y git rng-tools memcached parallel - mkdir -p "$HOME/.parallel" - touch "$HOME/.parallel/will-cite" + # avoid needing to invoke parallel with --will-cite, + # see e.g see https://bugs.launchpad.net/ubuntu/+source/parallel/+bug/1779764 + mkdir -p "$HOME/.parallel" && touch "$HOME/.parallel/will-cite" git version docker version - restore_cache: