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

Add 'fluxctl install' e2e smoke test #2552

Merged
merged 5 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
35 changes: 35 additions & 0 deletions test/e2e/10_helm_chart.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bats

load lib/install
load lib/poll

function setup() {
install_git_srv
install_tiller
install_flux_with_helm
}

@test "Helm chart installation smoke test" {
# The gitconfig secret must exist and have the right value
poll_until_equals "gitconfig secret" "${GITCONFIG}" "kubectl get secrets -n "${FLUX_NAMESPACE}" gitconfig -ojsonpath={..data.gitconfig} | base64 --decode"

# Test that the resources from https://github.com/fluxcd/flux-get-started are deployed
poll_until_true 'namespace demo' 'kubectl describe ns/demo'
poll_until_true 'workload podinfo' 'kubectl -n demo describe deployment/podinfo'
poll_until_true 'mongodb HelmRelease' 'kubectl -n demo describe helmrelease/mongodb'
}

function teardown() {
# For debugging purposes (in case the test fails)
echo '>>> Flux logs'
kubectl -n "${FLUX_NAMESPACE}" logs deployment/flux
echo '>>> List pods'
kubectl -n "${DEMO_NAMESPACE}" get pods
echo '>>> Check workload'
kubectl -n "${DEMO_NAMESPACE}" rollout status deployment/podinfo

uninstall_flux_with_helm
uninstall_tiller
uninstall_git_srv
kubectl delete namespace demo
}
29 changes: 29 additions & 0 deletions test/e2e/11_fluxctl_install.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bats

load lib/install
load lib/poll

function setup() {
install_git_srv
install_flux_with_fluxctl
}

@test "'fluxctl install' smoke test" {
# Test that the resources from https://github.com/fluxcd/flux-get-started are deployed
poll_until_true 'namespace demo' 'kubectl describe ns/demo'
poll_until_true 'workload podinfo' 'kubectl -n demo describe deployment/podinfo'
}

function teardown() {
# For debugging purposes (in case the test fails)
echo '>>> Flux logs'
kubectl -n "${FLUX_NAMESPACE}" logs deployment/flux
echo '>>> List pods'
kubectl -n "${DEMO_NAMESPACE}" get pods
echo '>>> Check workload'
kubectl -n "${DEMO_NAMESPACE}" rollout status deployment/podinfo

uninstall_flux_with_fluxctl
uninstall_git_srv
kubectl delete namespace demo
}
6 changes: 3 additions & 3 deletions test/e2e/fixtures/gitsrv.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ spec:
- mountPath: /git-server/repos
name: git-server-data
- mountPath: /git-server/keys
name: ssh-git
name: flux-git-deploy
volumes:
- name: ssh-git
- name: flux-git-deploy
secret:
secretName: ssh-git
secretName: flux-git-deploy
- name: git-server-data
emptyDir: {}
---
Expand Down
104 changes: 0 additions & 104 deletions test/e2e/helm_chart_smoke_test.bats

This file was deleted.

35 changes: 29 additions & 6 deletions test/e2e/lib/install.bash
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash

function install_tiller() {
if ! helm version > /dev/null 2>&1; then # only if helm isn't already installed
if ! helm version > /dev/null 2>&1; then # only if helm isn't already installed
kubectl --namespace kube-system create sa tiller
kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller
helm init --service-account tiller --upgrade --wait
fi
fi
}

function uninstall_tiller() {
Expand All @@ -27,13 +27,13 @@ function install_flux_with_helm() {
--set image.repository=docker.io/fluxcd/flux \
--set image.tag=latest \
--set git.url=ssh://git@gitsrv/git-server/repos/cluster.git \
--set git.secretName=ssh-git \
--set git.pollInterval=30s \
--set git.secretName=flux-git-deploy \
--set git.pollInterval=10s \
--set git.config.secretName=gitconfig \
--set git.config.enabled=true \
--set-string git.config.data="${GITCONFIG}" \
--set helmOperator.create=true `# just needed to add the HelmRelease CRD`\
--set helmOperator.git.secretName=ssh-git \
--set helmOperator.git.secretName=flux-git-deploy \
--set helmOperator.createCRD="${create_crds}" \
--set registry.excludeImage=* \
--set-string ssh.known_hosts="${KNOWN_HOSTS}" \
Expand All @@ -46,11 +46,34 @@ function uninstall_flux_with_helm() {
kubectl delete crd helmreleases.flux.weave.works > /dev/null 2>&1
}

fluxctl_install_cmd="fluxctl install --namespace "${FLUX_NAMESPACE}" --git-url=ssh://git@gitsrv/git-server/repos/cluster.git --git-email=foo"

function install_flux_with_fluxctl() {
local eol=$'\n'
# Use the local Flux image instead of the latest release, use a poll interval of 10s
# (to make tests quicker) and disable registry polling (to avoid overloading kind)
$fluxctl_install_cmd | \
sed 's%docker\.io/fluxcd/flux:.*%fluxcd/flux:latest%' | \
sed "s%--git-email=foo%--git-email=foo\\$eol - --git-poll-interval=10s%" | \
sed "s%--git-email=foo%--git-email=foo\\$eol - --sync-interval=10s%" | \
sed "s%--git-email=foo%--git-email=foo\\$eol - --registry-exclude-image=\*%" | \
kubectl apply -f -
kubectl -n "${FLUX_NAMESPACE}" rollout status deployment/flux
# Add the known hosts file manually (it's much easier than editing the manifests to add a volume)
local flux_podname=$(kubectl get pod -n flux-e2e -l name=flux -o jsonpath="{['items'][0].metadata.name}")
kubectl exec -n "${FLUX_NAMESPACE}" "${flux_podname}" -- sh -c "echo '$(cat ${FIXTURES_DIR}/known_hosts)' > /root/.ssh/known_hosts"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty horrible. I'm open for suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is also aimed at the sed expressions above (I tried to make a comment on the full block of code but it seems I failed)

Copy link
Member

@hiddeco hiddeco Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the install package already support additionalArguments? What about instead of doing the sed, we make a small adjustment to fluxctl install to accept a string slice of additional arguments, and then utilize this here?


There actually was someone on Slack yesterday who was wondering how he could use his own image with fluxctl install. So maybe adding an option to supply an own image to fluxctl install wouldn't even be a bad idea.

Copy link
Contributor Author

@2opremio 2opremio Oct 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your suggestions. I initially incorporated --extra-flux-arguments, but @squaremo thought it was better to edit the output. See #2287 (review)

@squaremo I still think there is a valid usecase here, could you reevaluate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hiddeco regardless, I will fix this in a separate PR. Are you OK with the rest?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to run the output of fluxctl install through kustomize to do the patching you need?

}

function uninstall_flux_with_fluxctl() {
$fluxctl_install_cmd | kubectl delete -f -

}

function install_git_srv() {
kubectl apply -n "${FLUX_NAMESPACE}" -f "${E2E_DIR}/fixtures/gitsrv.yaml"
kubectl -n "${FLUX_NAMESPACE}" rollout status deployment/gitsrv
}

function uninstall_git_srv() {
kubectl delete -n "${FLUX_NAMESPACE}" -f "${E2E_DIR}/fixtures/gitsrv.yaml"
}
}
26 changes: 26 additions & 0 deletions test/e2e/lib/poll.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash

function poll_until_equals() {
local what="$1"
local expected="$2"
local check_cmd="$3"
poll_until_true "$what" "[ '$expected' = \"\$( $check_cmd )\" ]"
}

function poll_until_true() {
2opremio marked this conversation as resolved.
Show resolved Hide resolved
local what="$1"
local check_cmd="$2"
echo -n ">>> Waiting for $what " >&3
retries=24
count=0
until eval "$check_cmd"; do
echo -n '.' >&3
sleep 5
count=$(($count + 1))
if [[ ${count} -eq ${retries} ]]; then
echo ' No more retries left!' >&3
return 1 # fail
fi
done
echo ' done' >&3
}
5 changes: 2 additions & 3 deletions test/e2e/run.bash
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export E2E_DIR="${FLUX_ROOT_DIR}/test/e2e"
export FIXTURES_DIR="${E2E_DIR}/fixtures"
export KNOWN_HOSTS=$(cat "${FIXTURES_DIR}/known_hosts")
export GITCONFIG=$(cat "${FIXTURES_DIR}/gitconfig")
export DEMO_NAMESPACE=demo

KIND_VERSION="v0.5.1"
CACHE_DIR="${FLUX_ROOT_DIR}/cache/$CURRENT_OS_ARCH"
Expand Down Expand Up @@ -46,7 +45,7 @@ defer kubectl delete namespace "$FLUX_NAMESPACE"
echo '>>> Creating ssh key and Git access secret'
ssh-keygen -t rsa -N "" -f "${FIXTURES_DIR}/id_rsa"
defer rm -f "${FIXTURES_DIR}/id_rsa" "${FIXTURES_DIR}/id_rsa.pub"
kubectl create secret generic ssh-git --namespace="${FLUX_NAMESPACE}" --from-file="${FIXTURES_DIR}/known_hosts" --from-file="${FIXTURES_DIR}/id_rsa" --from-file=identity="${FIXTURES_DIR}/id_rsa" --from-file="${FIXTURES_DIR}/id_rsa.pub"
kubectl create secret generic flux-git-deploy --namespace="${FLUX_NAMESPACE}" --from-file="${FIXTURES_DIR}/known_hosts" --from-file="${FIXTURES_DIR}/id_rsa" --from-file=identity="${FIXTURES_DIR}/id_rsa" --from-file="${FIXTURES_DIR}/id_rsa.pub"

if [ "${USING_KIND}" = 'true' ]; then
echo '>>> Loading images into the Kind cluster'
Expand All @@ -55,4 +54,4 @@ fi

# Run the tests
echo '>>> Running the tests'
(cd "${E2E_DIR}"; "${E2E_DIR}/bats/bin/bats" -t .)
(cd "${E2E_DIR}"; "${E2E_DIR}/bats/bin/bats" -t .)