Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions template/.github/workflows/build.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,73 @@ jobs:
run: ./preflight-linux-amd64 check container "$IMAGE_TAG" > preflight.out
- name: "Passed?"
run: '[ "$(./preflight-linux-amd64 check container "$IMAGE_TAG" | jq -r .passed)" == true ]'

integration_tests:
name: Run integration tests
if: ${{ !github.event.pull_request.head.repo.fork }}
needs:
- package_and_publish
env:
STACKABLECTL_VERSION: "23.11.3"
KUTTL_VERSION: "0.15.0"
strategy:
fail-fast: false
matrix:
cluster: [
{
distribution: openshift,
version: 4.14.0-okd,
nodes: 3,
instances: r1.large
}]
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # tag=v5.0.0
with:
python-version: '3.11'
- run: pip install beku-stackabletech

- name: Install test requirements
run: |
# Install requirements for the run_tests.sh script.
PATH=/usr/bin:$PATH

wget --no-verbose https://github.com/stackabletech/stackable-cockpit/releases/download/stackablectl-"$STACKABLECTL_VERSION"/stackablectl-x86_64-unknown-linux-gnu
chmod +x stackablectl-x86_64-unknown-linux-gnu
sudo mv stackablectl-x86_64-unknown-linux-gnu /usr/bin/stackablectl

wget --no-verbose https://github.com/kudobuilder/kuttl/releases/download/v"$KUTTL_VERSION"/kubectl-kuttl_"$KUTTL_VERSION"_linux_x86_64
chmod +x kubectl-kuttl_"$KUTTL_VERSION"_linux_x86_64
sudo mv kubectl-kuttl_"$KUTTL_VERSION"_linux_x86_64 /usr/bin/kubectl-kuttl
kubectl-kuttl version

- name: Create Cluster
id: create-cluster
uses: replicatedhq/replicated-actions/create-cluster@v1
with:
api-token: ${{ secrets.REPLICATED_API_TOKEN }}
kubernetes-distribution: ${{ matrix.cluster.distribution }}
kubernetes-version: ${{ matrix.cluster.version }}
cluster-name: ${{ github.ref_name }}-${{ matrix.cluster.distribution }}-${{ matrix.cluster.version }}
timeout-minutes: 10
ttl: 2h
nodes: ${{ matrix.cluster.nodes }}
instance-type: ${{ matrix.cluster.instances }}
export-kubeconfig: true

- name: Run a test
run: |
PATH=/usr/bin:$PATH

scripts/run_tests.sh --test-suite openshift --parallel 2

- name: Remove Cluster
if: always()
id: remove-cluster
uses: replicatedhq/replicated-actions/remove-cluster@v1
continue-on-error: true # It could be that the cluster is already removed
with:
api-token: ${{ secrets.REPLICATED_API_TOKEN }}
cluster-id: ${{ steps.create-cluster.outputs.cluster-id }}
170 changes: 149 additions & 21 deletions template/scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,152 @@
#!/usr/bin/env bash
#
# Run the integration test suite for this operator.
#
# If a "tests/release.yaml" file is present, it will install the operators listed
# in the release file first. The name of the test suite in that file must be "tests".
# Since each operator test suite has different dependencies, the "tests/release.yaml"
# file is not included in this repository.
#
# Optionally you can provide a specific test suite to run and even a specific
# test name.
#
# Example 1 - run all tests of the openshift suite.
#
# ./scripts/run_tests.sh --test-suite openshift --parallel 2
#
# Example 2 - run all tests that contain the word "smoke" in the openshift suite and skip resource deletion.
#
# ./scripts/run_tests.sh \
# --test-suite openshift \
# --test smoke \
# --skip-delete
#

# Check if the test expansion tool beku is installed
set +e
which beku > /dev/null 2>&1
beku_installed=$?
set -e
if [ $beku_installed -ne 0 ]; then
echo "Please install beku.py to run the tests, see https://github.com/stackabletech/beku.py"
exit 1
fi

echo "Using beku version: $(beku --version)"

# cleanup any old tests
rm -rf tests/_work

# Expand the tests
beku

# Run tests, pass the params
pushd tests/_work
kubectl kuttl test "$@"
popd

DIR_NAME=$(dirname "$0")
REPO_ROOT=$(dirname "$DIR_NAME")
TEST_ROOT="$REPO_ROOT/tests/_work"
RELEASE_FILE="$REPO_ROOT/tests/release.yaml"
STACKABLECTL_SKIP_RELEASE=""
BEKU_TEST_SUITE=""
KUTTL_TEST=""
KUTTL_SKIP_DELETE=""
KUTTL_PARALLEL=""

is_installed() {
local command="$1"
local install_url="$2"

if ! which "$command" >/dev/null 2>&1; then
echo "Command [$command] not found. To install it, please see $install_url"
exit 1
fi
}

install_operators() {
if [ -n "$STACKABLECTL_SKIP_RELEASE" ]; then
echo "Skipping operator installation"
return
fi

if [ -f "$RELEASE_FILE" ]; then
echo "Installing operators with stackablectl version: $(stackablectl --version)"
stackablectl release install --release-file "$RELEASE_FILE" tests
else
echo "No tests/release.yaml found, skipping operator installation"
fi
}

expand_test_suite() {
# Expand the tests
echo "Running beku version: $(beku --version)"
if [ -z "$BEKU_TEST_SUITE" ]; then
echo "No test suite specified, expanding all tests"
beku
else
echo "Expanding test suite: $BEKU_TEST_SUITE"
beku --suite "$BEKU_TEST_SUITE"
fi
}

run_tests() {
echo "Running kuttl version: $(kubectl-kuttl --version)"

local OPTS=("test")

if [ -n "$KUTTL_SKIP_DELETE" ]; then
OPTS+=("--skip-delete")
fi

if [ -n "$KUTTL_PARALLEL" ]; then
OPTS+=("--parallel $KUTTL_PARALLEL")
fi

if [ -n "$KUTTL_TEST" ]; then
OPTS+=("--test=$KUTTL_TEST")
fi

pushd "$TEST_ROOT" || exit
kubectl-kuttl "${OPTS[*]}"
popd || exit
}

usage() {
cat <<USAGE
Usage:
run_tests.sh [options]
Options:
--test-suite <test-suite> Run a test suite from the test_definition.yaml file. Default is all tests.
--test <test-name> Run a specific test or a set of tests.
--skip-delete Skip resource deletion after the test run.
--parallel <number> Run tests in parallel. Default is to run all tests in parallel.
--skip-release Skip the operator installation.
USAGE
}

parse_args() {
while [[ "$#" -gt 0 ]]; do
case $1 in
--skip-release)
STACKABLECTL_SKIP_RELEASE="true"
;;
--skip-delete)
KUTTL_SKIP_DELETE="true"
;;
--parallel)
KUTTL_PARALLEL="$2"
shift
;;
--test-suite)
BEKU_TEST_SUITE="$2"
shift
;;
--test)
KUTTL_TEST="$2"
shift
;;
*)
echo "Unknown parameter : $1"
usage
exit 1
;;
esac
shift
done
}

main() {
parse_args "$@"

is_installed beku "https://github.com/stackabletech/beku.py"
is_installed stackablectl "https://github.com/stackabletech/stackable-cockpit/blob/main/rust/stackablectl/README.md"
is_installed kubectl "https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/"
is_installed kubectl-kuttl "https://kuttl.dev/"

expand_test_suite
install_operators
run_tests
}

main "$@"