|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +set -eoux pipefail |
| 4 | + |
| 5 | +MINIO_VER="${MINIO_VER:-v6.3.1}" |
| 6 | +CREATE_CLUSTER="${CREATE_CLUSTER:-true}" |
| 7 | +KIND_CLUSTER_NAME="${KIND_CLUSTER_NAME:-kind}" |
| 8 | + |
| 9 | +IMG=test/source-controller |
| 10 | +TAG=latest |
| 11 | +MC_RELEASE=mc.RELEASE.2021-12-10T00-14-28Z |
| 12 | +MC_SHA256=01ec33b51ad208634deb8d701d52ac8f6be088e72563a92475ba6e6470653b73 |
| 13 | + |
| 14 | +ROOT_DIR="$(git rev-parse --show-toplevel)" |
| 15 | +BUILD_DIR="${ROOT_DIR}/build" |
| 16 | + |
| 17 | +if "${CREATE_CLUSTER}"; then |
| 18 | + KIND_CLUSTER_NAME="flux-${RANDOM}" |
| 19 | + export KUBECONFIG="${ROOT_DIR}/build/kindconfig" |
| 20 | + |
| 21 | + echo "Spinning up flux kind cluster" |
| 22 | + kind create cluster --name "${KIND_CLUSTER_NAME}" --kubeconfig "${KUBECONFIG}" |
| 23 | +fi |
| 24 | + |
| 25 | +function cleanup(){ |
| 26 | + EXIT_CODE="$?" |
| 27 | + |
| 28 | + # only dump all logs if an error has occurred |
| 29 | + if [ ${EXIT_CODE} -ne 0 ]; then |
| 30 | + kubectl -n kube-system describe pods |
| 31 | + kubectl -n source-system describe pods |
| 32 | + kubectl -n source-system get gitrepositories -oyaml |
| 33 | + kubectl -n source-system get helmrepositories -oyaml |
| 34 | + kubectl -n source-system get helmcharts -oyaml |
| 35 | + kubectl -n source-system get all |
| 36 | + kubectl -n source-system logs deploy/source-controller |
| 37 | + kubectl -n minio get all |
| 38 | + else |
| 39 | + echo "All E2E tests passed!" |
| 40 | + fi |
| 41 | + |
| 42 | + if "${CREATE_CLUSTER}"; then |
| 43 | + echo "Delete cluster" |
| 44 | + kind delete cluster --name "${KIND_CLUSTER_NAME}" |
| 45 | + fi |
| 46 | + exit ${EXIT_CODE} |
| 47 | +} |
| 48 | +trap cleanup EXIT |
| 49 | + |
| 50 | +kubectl wait node "${KIND_CLUSTER_NAME}-control-plane" --for=condition=ready --timeout=2m |
| 51 | + |
| 52 | +echo "Build, load image into kind and deploy controller" |
| 53 | +make docker-build IMG="${IMG}" TAG="${TAG}" BUILD_PLATFORMS=linux/amd64 BUILD_ARGS=--load |
| 54 | +kind load docker-image --name "${KIND_CLUSTER_NAME}" "${IMG}":"${TAG}" |
| 55 | +make dev-deploy IMG="${IMG}" TAG="${TAG}" |
| 56 | + |
| 57 | +echo "Run smoke tests" |
| 58 | +kubectl -n source-system apply -f "${ROOT_DIR}/config/samples" |
| 59 | +kubectl -n source-system rollout status deploy/source-controller --timeout=1m |
| 60 | +kubectl -n source-system wait gitrepository/gitrepository-sample --for=condition=ready --timeout=1m |
| 61 | +kubectl -n source-system wait helmrepository/helmrepository-sample --for=condition=ready --timeout=1m |
| 62 | +kubectl -n source-system wait helmchart/helmchart-sample --for=condition=ready --timeout=1m |
| 63 | +kubectl -n source-system delete -f "${ROOT_DIR}/config/samples" |
| 64 | + |
| 65 | +echo "Run HelmChart values file tests" |
| 66 | +kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/helmchart-valuesfile" |
| 67 | +kubectl -n source-system wait helmchart/podinfo --for=condition=ready --timeout=5m |
| 68 | +kubectl -n source-system wait helmchart/podinfo-git --for=condition=ready --timeout=5m |
| 69 | +kubectl -n source-system delete -f "${ROOT_DIR}/config/testdata/helmchart-valuesfile" |
| 70 | + |
| 71 | +echo "Setup Minio" |
| 72 | +kubectl create ns minio |
| 73 | +helm repo add minio https://helm.min.io/ |
| 74 | +helm upgrade --wait -i minio minio/minio \ |
| 75 | + --version "${MINIO_VER}" \ |
| 76 | + --namespace minio \ |
| 77 | + --set accessKey=myaccesskey \ |
| 78 | + --set secretKey=mysecretkey \ |
| 79 | + --set resources.requests.memory=128Mi \ |
| 80 | + --set persistence.enable=false |
| 81 | +kubectl -n minio port-forward svc/minio 9000:9000 &>/dev/null & |
| 82 | + |
| 83 | +sleep 2 |
| 84 | + |
| 85 | +if [ ! -f "${BUILD_DIR}/mc" ]; then |
| 86 | + mkdir -p "${BUILD_DIR}" |
| 87 | + curl -o "${BUILD_DIR}/mc" -LO "https://dl.min.io/client/mc/release/linux-amd64/archive/${MC_RELEASE}" |
| 88 | + if ! echo "${MC_SHA256} ${BUILD_DIR}/mc" | sha256sum --check; then |
| 89 | + echo "Checksum failed for mc." |
| 90 | + rm "${BUILD_DIR}/mc" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + |
| 94 | + chmod +x "${BUILD_DIR}/mc" |
| 95 | +fi |
| 96 | + |
| 97 | +"${BUILD_DIR}/mc" alias set minio http://localhost:9000 myaccesskey mysecretkey --api S3v4 |
| 98 | +kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/minio/secret.yaml" |
| 99 | + |
| 100 | +echo "Run Bucket tests" |
| 101 | +"${BUILD_DIR}/mc" mb minio/podinfo |
| 102 | +"${BUILD_DIR}/mc" mirror "${ROOT_DIR}/config/testdata/minio/manifests/" minio/podinfo |
| 103 | + |
| 104 | +kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/bucket/source.yaml" |
| 105 | +kubectl -n source-system wait bucket/podinfo --for=condition=ready --timeout=1m |
| 106 | + |
| 107 | + |
| 108 | +echo "Run HelmChart from Bucket tests" |
| 109 | +"${BUILD_DIR}/mc" mb minio/charts |
| 110 | +"${BUILD_DIR}/mc" mirror "${ROOT_DIR}/controllers/testdata/charts/helmchart/" minio/charts/helmchart |
| 111 | + |
| 112 | +kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/helmchart-from-bucket/source.yaml" |
| 113 | +kubectl -n source-system wait bucket/charts --for=condition=ready --timeout=1m |
| 114 | +kubectl -n source-system wait helmchart/helmchart-bucket --for=condition=ready --timeout=1m |
| 115 | + |
| 116 | +echo "Run large Git repo tests" |
| 117 | +kubectl -n source-system apply -f "${ROOT_DIR}/config/testdata/git/large-repo.yaml" |
| 118 | +kubectl -n source-system wait gitrepository/large-repo-go-git --for=condition=ready --timeout=2m |
| 119 | +kubectl -n source-system wait gitrepository/large-repo-libgit2 --for=condition=ready --timeout=2m |
0 commit comments