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

Commit

Permalink
Test gc by kustomizing flux deployment
Browse files Browse the repository at this point in the history
This adds the ability to give an alternate kustomization when
installing flux, and uses that to test flux with garbage collection.
  • Loading branch information
squaremo committed Nov 5, 2019
1 parent 8e8f800 commit ea912e9
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 6 deletions.
2 changes: 1 addition & 1 deletion test/e2e/12_sync.bats
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function setup() {
sed -i'.bak' 's%stefanprodan/podinfo:2.1.0%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)
Expand Down
60 changes: 60 additions & 0 deletions test/e2e/13_sync_gc.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/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]}"
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() {
kill "$git_port_forward_pid"
# 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"
}
3 changes: 3 additions & 0 deletions test/e2e/fixtures/kustom/13_sync_gc/gc_patch.json
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" }
]
12 changes: 12 additions & 0 deletions test/e2e/fixtures/kustom/13_sync_gc/kustomization.yaml
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ patchesJson6902:
version: v1
kind: Deployment
name: flux
path: e2e_patch.yaml
path: e2e_patch.json
1 change: 1 addition & 0 deletions test/e2e/fixtures/test_patch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
19 changes: 15 additions & 4 deletions test/e2e/lib/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,21 @@ fluxctl_install_cmd="fluxctl install --git-url=ssh://git@gitsrv/git-server/repos
function install_flux_with_fluxctl() {
local kustomtmp
kustomtmp="$(mktemp -d)"
# This generates the base descriptions, which we'll then patch with a kustomization
$fluxctl_install_cmd --namespace "${FLUX_NAMESPACE}" -o "${kustomtmp}" 2>&3
cp ${E2E_DIR}/fixtures/{kustomization,e2e_patch}.yaml "${kustomtmp}/"
kubectl apply -k "${kustomtmp}" >&3
mkdir "${kustomtmp}/base"
# This generates the base manifests, which we'll then patch with a kustomization
echo ">>> writing base configuration to ${kustomtmp}" >&3
$fluxctl_install_cmd --namespace "${FLUX_NAMESPACE}" -o "${kustomtmp}/base/"
# Everything goes into one directory, but not everything is
# necessarily used by the kustomization
cp -R "${E2E_DIR}"/fixtures/kustom/* "${kustomtmp}/"
local kustomization
kustomization="base"
if [ -n "$1" ]; then
# use the kustomization given instead; ../base will still be
# there to be used as a base
kustomization="$1"
fi
kubectl apply -k "${kustomtmp}/${kustomization}" >&3
kubectl -n "${FLUX_NAMESPACE}" rollout status -w --timeout=30s deployment/flux
# Add the known hosts file manually (it's much easier than editing the manifests to add a volume)
local flux_podname
Expand Down

0 comments on commit ea912e9

Please sign in to comment.