This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2577 from fluxcd/e2e/sync-gc
End-to-end test for garbage collection
- Loading branch information
Showing
11 changed files
with
141 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,15 @@ function setup() { | |
export GIT_SSH_COMMAND="$git_ssh_cmd" | ||
# shellcheck disable=SC2154 | ||
git_port_forward_pid="${git_srv_result[1]}" | ||
# Teardown the created port-forward to gitsrv and restore Git settings. | ||
defer kill "$git_port_forward_pid" | ||
|
||
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" | ||
defer rm -rf "$clone_dir" | ||
# shellcheck disable=SC2164 | ||
cd "$clone_dir" | ||
} | ||
|
@@ -41,7 +46,7 @@ function setup() { | |
sed -i'.bak' 's%stefanprodan/podinfo:.*%stefanprodan/podinfo:3.1.5%' "${clone_dir}/workloads/podinfo-dep.yaml" | ||
git -c '[email protected]' -c 'user.name=Foo' commit -am "Bump podinfo" | ||
head_hash=$(git rev-list -n 1 HEAD) | ||
git push | ||
git push >&3 | ||
poll_until_equals "podinfo image" "stefanprodan/podinfo:3.1.5" "kubectl get pod -n demo -l app=podinfo -o\"jsonpath={['items'][0]['spec']['containers'][0]['image']}\"" | ||
git pull -f --tags | ||
sync_tag_hash=$(git rev-list -n 1 flux) | ||
|
@@ -81,9 +86,7 @@ function setup() { | |
} | ||
|
||
function teardown() { | ||
rm -rf "$clone_dir" | ||
# Teardown the created port-forward to gitsrv and restore Git settings. | ||
kill "$git_port_forward_pid" | ||
run_deferred | ||
# Uninstall Flux and the global resources it installs. | ||
uninstall_flux_with_fluxctl | ||
# Removing the namespace also takes care of removing gitsrv. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env bats | ||
|
||
load lib/env | ||
load lib/install | ||
load lib/poll | ||
load lib/defer | ||
|
||
git_port_forward_pid="" | ||
|
||
function setup() { | ||
kubectl create namespace "$FLUX_NAMESPACE" | ||
# Install flux and the git server, allowing external access | ||
install_git_srv flux-git-deploy git_srv_result | ||
# shellcheck disable=SC2154 | ||
git_ssh_cmd="${git_srv_result[0]}" | ||
export GIT_SSH_COMMAND="$git_ssh_cmd" | ||
# shellcheck disable=SC2154 | ||
git_port_forward_pid="${git_srv_result[1]}" | ||
defer kill "$git_port_forward_pid" | ||
install_flux_with_fluxctl "13_sync_gc" | ||
} | ||
|
||
@test "Sync with garbage collection test" { | ||
# Wait until flux deploys the workloads, which indicates it has at least started a sync | ||
poll_until_true 'workload podinfo' 'kubectl -n demo describe deployment/podinfo' | ||
|
||
# make sure we have _finished_ a sync run | ||
fluxctl --k8s-fwd-ns "${FLUX_NAMESPACE}" sync | ||
|
||
# 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" | ||
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" ] | ||
|
||
# Remove a manifest and commit that | ||
git rm workloads/podinfo-dep.yaml | ||
git -c '[email protected]' -c 'user.name=Foo' commit -m "Remove podinfo deployment" | ||
head_hash=$(git rev-list -n 1 HEAD) | ||
git push >&3 | ||
|
||
fluxctl --k8s-fwd-ns "${FLUX_NAMESPACE}" sync | ||
|
||
poll_until_equals "podinfo deployment removed" "[]" "kubectl get deploy -n demo -o\"jsonpath={['items']}\"" | ||
git pull -f --tags >&3 | ||
sync_tag_hash=$(git rev-list -n 1 flux) | ||
[ "$sync_tag_hash" = "$head_hash" ] | ||
} | ||
|
||
function teardown() { | ||
run_deferred | ||
# Removing the namespace also takes care of removing Flux and gitsrv. | ||
kubectl delete namespace "$FLUX_NAMESPACE" | ||
# Only remove the demo workloads after Flux, so that they cannot be recreated. | ||
kubectl delete namespace "$DEMO_NAMESPACE" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[ | ||
{ "op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": "--sync-garbage-collection" } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
bases: | ||
- "../base" | ||
patchesJson6902: | ||
## this patch is for test-specific patches; supply a filename to | ||
## install_flux_with_fluxctl and it will use that rather than the | ||
## (empty) default. | ||
- target: | ||
group: apps | ||
version: v1 | ||
kind: Deployment | ||
name: flux | ||
path: gc_patch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --git-poll-interval=10s | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --sync-interval=10s | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --registry-exclude-image=* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
resources: | ||
- flux-account.yaml | ||
- flux-deployment.yaml | ||
- flux-secret.yaml | ||
- memcache-dep.yaml | ||
- memcache-svc.yaml | ||
patchesJson6902: | ||
# use a poll interval of 10s (to make tests quicker) and disable | ||
# registry polling (to avoid overloading kind) | ||
- target: | ||
group: apps | ||
version: v1 | ||
kind: Deployment | ||
name: flux | ||
path: e2e_patch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters