Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
66 changes: 66 additions & 0 deletions template/.github/workflows/build.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -374,3 +374,69 @@ 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 ]'

openshift_tests:
name: Run integration tests
needs:
- package_and_publish
strategy:
fail-fast: false
matrix:
cluster: [
{
distribution: openshift,
version: 4.14.0-okd,
nodes: 3,
instances: r1.2xlarge
}]
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-23.11.3/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/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64
chmod +x kubectl-kuttl_0.15.0_linux_x86_64
sudo mv kubectl-kuttl_0.15.0_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 openshift

- 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 }}
152 changes: 131 additions & 21 deletions template/scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,134 @@
#!/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 a specific smoke test of the openshift suite and skip resource deletion.
#
# ./scripts/run_tests.sh \
# --test-suite openshift \
# --test smoke_trino-439_hive-3.1.3_opa-0.61.0_hdfs-3.3.6_zookeeper-3.8.3_s3-use-tls-true_openshift-true \
# --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"
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 [ -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() {
echo "Usage: $0 [--test-suite <test-suite>] [--test <test-name>] [--skip-delete] [--parallel <number>]"
}

parse_args() {
while [[ "$#" -gt 0 ]]; do
case $1 in
--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 $@