diff --git a/.github/workflows/chart-test.yml b/.github/workflows/chart-test.yml index fa699502..977e8211 100644 --- a/.github/workflows/chart-test.yml +++ b/.github/workflows/chart-test.yml @@ -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 diff --git a/ct.bash b/ct.bash new file mode 100755 index 00000000..ffaf5c00 --- /dev/null +++ b/ct.bash @@ -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 "$@" diff --git a/k8s-test.bash b/k8s-test.bash new file mode 100755 index 00000000..7adb335b --- /dev/null +++ b/k8s-test.bash @@ -0,0 +1,40 @@ +#!/usr/bin/env bash + +set -xe + +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}" + +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}" +function cleanup() { + "${CLUSTER_CLIENT}" delete ns "${TEST_NAMESPACE}" + if [ "${CREATE_CLUSTER:-true}" = "true" ]; then + kind delete cluster + fi +} +trap cleanup EXIT + +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}"