Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(scripts): add scripts to ease local chart testing #196

Merged
merged 11 commits into from
Sep 17, 2024
3 changes: 1 addition & 2 deletions .github/workflows/chart-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ jobs:
cat <(echo '#!/usr/bin/env bash') <(echo 'exec .helm "${@//--reuse-values/--reset-then-reuse-values}"') | sudo tee $HELM_LOCATION
sudo chmod +x $HELM_LOCATION

kubectl create ns $TEST_NAMESPACE
ct install --target-branch ${TARGET_BRANCH} --upgrade --namespace=$TEST_NAMESPACE --config ct.yaml --debug
bash ct.bash --upgrade

helm-unittest:
runs-on: ubuntu-latest
Expand Down
24 changes: 24 additions & 0 deletions ct.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -xe

if ! command -v ct; then
echo "ct command not found in \$PATH"
exit 1
fi

TEST_NAMESPACE="${TEST_NAMESPACE:-helm-test}"
CLUSTER_CLIENT="${CLUSTER_CLIENT:-$(which kubectl)}"

if ! command -v "${CLUSTER_CLIENT}"; then
echo "${CLUSTER_CLIENT} command not found in \$PATH"
exit 1
fi

function cleanup() {
"${CLUSTER_CLIENT}" delete ns "${TEST_NAMESPACE}"
}
trap cleanup EXIT

"${CLUSTER_CLIENT}" create ns "${TEST_NAMESPACE}"
ct install --remote "${REMOTE:-origin}" --target-branch "${TARGET_BRANCH:-main}" --namespace="${TEST_NAMESPACE}" --config ct.yaml --debug "$@"
andrewazores marked this conversation as resolved.
Show resolved Hide resolved
44 changes: 44 additions & 0 deletions k8s-test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

set -x

CLUSTER_CLIENT="${CLUSTER_CLIENT:-$(which kubectl)}"

if ! command -v "${CLUSTER_CLIENT}"; then
echo "${CLUSTER_CLIENT} command not found in \$PATH"
exit 1
fi

if ! command -v helm; then
echo "No 'helm' found in \$PATH"
exit 1
fi

TEST_NAMESPACE="${TEST_NAMESPACE:-k8s-test}"
RELEASE_NAME="${RELEASE_NAME:-cryostat-k8s-test}"

function cleanup() {
"${CLUSTER_CLIENT}" delete ns "${TEST_NAMESPACE}"
if [ "${CREATE_CLUSTER:-true}" = "true" ]; then
kind delete cluster
fi
}
trap cleanup EXIT
cleanup
andrewazores marked this conversation as resolved.
Show resolved Hide resolved

set -e

if [ "${CREATE_CLUSTER:-true}" = "true" ]; then
if ! command -v kind; then
echo "No 'kind' found in \$PATH"
exit 1
fi
kind create cluster
fi

"${CLUSTER_CLIENT}" create ns "${TEST_NAMESPACE}"

helm install --namespace "${TEST_NAMESPACE}" "${RELEASE_NAME}" ./charts/cryostat
"${CLUSTER_CLIENT}" wait --timeout=2m --for=condition=Available=true --namespace "${TEST_NAMESPACE}" deployment -l app.kubernetes.io/name=cryostat
"${CLUSTER_CLIENT}" wait --timeout=2m --for=condition=Ready=true --namespace "${TEST_NAMESPACE}" pod -l app.kubernetes.io/name=cryostat
helm test --namespace "${TEST_NAMESPACE}" "${RELEASE_NAME}"