Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

e2e: Add sync failure test #2581

Merged
merged 4 commits into from
Nov 6, 2019
Merged
Changes from 1 commit
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
45 changes: 39 additions & 6 deletions test/e2e/12_sync.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ load lib/poll
load lib/defer

git_port_forward_pid=""
clone_dir=""

function setup() {
kubectl create namespace "$FLUX_NAMESPACE"
Expand All @@ -17,18 +18,19 @@ function setup() {
# shellcheck disable=SC2154
git_port_forward_pid="${git_srv_result[1]}"
install_flux_with_fluxctl
# Clone the repo and
clone_dir="$(mktemp -d)"
git clone -b master ssh://git@localhost/git-server/repos/cluster.git "$clone_dir"
# shellcheck disable=SC2164
cd "$clone_dir"
}

@test "Basic sync test" {
# Wait until flux deploys the workloads
poll_until_true 'workload podinfo' 'kubectl -n demo describe deployment/podinfo'

# Clone the repo and check the sync tag
local clone_dir
clone_dir="$(mktemp -d)"
defer rm -rf "$clone_dir"
git clone -b master ssh://git@localhost/git-server/repos/cluster.git "$clone_dir"
cd "$clone_dir"
# Check the sync tag
git pull -f --tags
local sync_tag_hash
sync_tag_hash=$(git rev-list -n 1 flux)
head_hash=$(git rev-list -n 1 HEAD)
Expand All @@ -45,7 +47,38 @@ function setup() {
[ "$sync_tag_hash" = "$head_hash" ]
}

@test "Sync fails on duplicate resource" {
# Wait until flux deploys the workloads
poll_until_true 'workload podinfo' 'kubectl -n demo describe deployment/podinfo'

# Check the sync tag
git pull -f --tags
local sync_tag_hash
sync_tag_hash=$(git rev-list -n 1 flux)
head_hash=$(git rev-list -n 1 HEAD)
[ "$sync_tag_hash" = "$head_hash" ]

# Bump the image of podinfo, duplicate the resource definition (to cause a sync failure)
# and make sure the sync doesn't go through
sed -i'.bak' 's%stefanprodan/podinfo:2.1.0%stefanprodan/podinfo:3.1.5%' "${clone_dir}/workloads/podinfo-dep.yaml"
2opremio marked this conversation as resolved.
Show resolved Hide resolved
cp "${clone_dir}/workloads/podinfo-dep.yaml" "${clone_dir}/workloads/podinfo-dep-2.yaml"
git add "${clone_dir}/workloads/podinfo-dep-2.yaml"
git -c 'user.email=foo@bar.com' -c 'user.name=Foo' commit -am "Bump podinfo and duplicate it to cause an error"
git push
# Wait until we find the duplicate failure in the logs
poll_until_true "duplicate resource in Flux logs" "kubectl logs -n $FLUX_NAMESPACE -l name=flux | grep -q \"duplicate definition of 'demo:deployment/podinfo'\""
# Make sure that the version of podinfo wasn't bumped
local podinfo_image
podinfo_image=$(kubectl get pod -n demo -l app=podinfo -o"jsonpath={['items'][0]['spec']['containers'][0]['image']}")
[ "$podinfo_image" = "stefanprodan/podinfo:2.1.0" ]
2opremio marked this conversation as resolved.
Show resolved Hide resolved
# Make sure that the Flux sync tag remains untouched
git pull -f --tags
sync_tag_hash=$(git rev-list -n 1 flux)
[ "$sync_tag_hash" = "$head_hash" ]
2opremio marked this conversation as resolved.
Show resolved Hide resolved
}

function teardown() {
rm -rf "$clone_dir"
# Teardown the created port-forward to gitsrv and restore Git settings.
kill "$git_port_forward_pid"
unset GIT_SSH_COMMAND
Expand Down