Skip to content

Commit

Permalink
[WFLY-19334] Add testing on Kubernetes for PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
kabir committed May 15, 2024
1 parent 8a3f98f commit 10d0fa8
Show file tree
Hide file tree
Showing 25 changed files with 21,577 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function runPostHelmInstallCommands() {
echo "Applying all OpenTelemetry Collector resources"
oc apply -f charts/opentelemetry-collector.yaml
oc apply -f charts/opentelemetry-collector-openshift.yaml
}

function cleanPrerequisites() {
echo "Deleting all OpenTelemetry Collector resources"
oc delete -f charts/opentelemetry-collector.yaml
oc delete -f charts/opentelemetry-collector-openshift.yaml
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function runPostHelmInstallCommands() {
oc apply -f charts/management.yml
kubectl apply -f charts/management-openshiftkube .yml
}


Expand All @@ -13,6 +13,6 @@ function getMvnVerifyExtraArguments()
function cleanPrerequisites()
{
echo "Removing microprofile-health-management service and route"
oc delete route microprofile-health-management
oc delete service microprofile-health-management
kubectl delete route microprofile-health-management
kubectl delete service microprofile-health-management
}
224 changes: 224 additions & 0 deletions .github/workflows/kubernetes-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
name: WildFly Quickstarts Kubernetes CI
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
push:
# kubernetes-testing is a temporary entry
#branches: [main, kubernetes-testing]
branches: [main]
env:
KUBERNETES_CORE_DIRECTORY: .github/workflows/scripts/kubernetes/core
KUBERNETES_QS_OVERRIDES_DIRECTORY: .github/workflows/scripts/kubernetes/overrides
# Only run the latest job
concurrency:
group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}'
cancel-in-progress: true
jobs:
calculate-changed-quickstarts:
name: Matrix for Kubernetes
runs-on: ubuntu-latest
outputs:
quickstart-matrix: ${{ steps.calculate-matrix.outputs.matrix }}
steps:
# - name: Output event
# run: echo "${{ toJSON(github.event) }}"
- uses: actions/checkout@v4
- name: Get all directories
id: get-top-level-directories
run: |
declare -a test_directories
for file in ./*; do
fileName=$(basename "${file}")
if [ ! -d "${file}" ]; then
# echo "${fileName} is not a directory!"
continue
fi
test_directories+=(${fileName})
done
echo "top_dirs=${test_directories[*]}" >> $GITHUB_OUTPUT
- name: Find Changed Files
id: changed-files
uses: tj-actions/changed-files@v44
# To compare changes between the current commit and the last pushed remote commit set `since_last_remote_commit: true`. e.g
# with:
# since_last_remote_commit: true
- name: Determine changed directories
id: quickstarts-to-test
env:
ALL_CHANGED_FILES: ${{ steps.changed-files.outputs.all_changed_files }}
ALL_BASE_DIRECTORIES: ${{ steps.get-top-level-directories.outputs.top_dirs }}
run: |
# set -x
##################################################
# Look for all the changed quickstarts
echo "Checking for changed files...."
declare -a quickstarts_to_test
for file in ${ALL_CHANGED_FILES}; do
echo "Checking file ${file}"
# Changes to the .adoc and the soon-to-be retired .ci directory do not count
# Don't use quotes for the wildcard values or filtering will not work!
if [[ "${file}" == *.adoc ]] || [[ "${file}" == *.html ]] || [[ "${file}" == .ci.* ]]; then
echo "Skipping .adoc and .ci/ files!"
continue
fi
# Changes to the Kubernetes CI setup files should trigger all tests
# Don't use quotes for the wildcard values or filtering will not work!
if [[ "${file}" == ".github/workflows/kubernetes-ci.yml" ]] || [[ "${file}" == ${{ env.KUBERNETES_CORE_DIRECTORY }}/* ]]; then
echo "Detected changes in the Kubernetes CI setup file ${file}. All tests will need to be run."
root_dir_file_changed=1
break
fi
# Don't use quotes for the wildcard values or filtering will not work!
if [[ "${file}" == ${{ env.KUBERNETES_CORE_DIRECTORY }}/qs_overrides/.* ]]; then
# Work out the name of the quickstarts
IFS='/' read -ra parts <<< "${file}"
IFS='/' read -ra core_dir_parts <<< "${{ env.KUBERNETES_CORE_DIRECTORY }}/qs_overrides"
qs_dir_index=${#core_dir_parts[@]}
qs_dir_index=$((qs_dir_index + 1))
echo "Adding '${parts[$qs_dir_index]}' to the list of quickstarts since ${file} was changed"
quickstarts_to_test+=(${parts[$qs_dir_index]})
fi
# All changes to files in the root folder apply to all quickstarts
IFS='/' read -ra parts <<< "${file}"
if [ "${#parts[@]}" == 1 ] && [ "${parts[0]}" != '.gitignore' ] ; then
echo "Changed detected in ${file} which is in the root directory. All tests will need to be run."
root_dir_file_changed=1
break
else
echo "Adding (${parts[0]}) to the list of quickstarts"
quickstarts_to_test+=(${parts[0]})
fi
done
if [ "${root_dir_file_changed}" == "1" ]; then
quickstarts_to_test=(${ALL_BASE_DIRECTORIES[@]})
fi
echo "Got initial list of quickstarts. Deduping..."
# Dedupe
declare -a tmp
output_dirs=$(printf "%s\n" "${quickstarts_to_test[@]}" | sort -u)
for dir in ${output_dirs}; do
tmp+=(${dir})
done
quickstarts_to_test=(${tmp[@]})
echo "Current list of quickstarts before checking whether they can be run"
echo "${quickstarts_to_test[*]})"

############################################################
# Now filter the quickstarts we found depending on if they have been enhanced


echo "Checking which quickstarts can be run...."

declare -a tmp2
for fileName in "${quickstarts_to_test[@]}"; do
echo "Checking ${fileName}"
# Quickstarts that have not been migrated yet
grep -q "^${fileName}$" ${{ env.KUBERNETES_CORE_DIRECTORY }}/excluded-directories.txt && is_in_excluded=1 || is_in_excluded=0
if [ "${is_in_excluded}" = "1" ]; then
echo "Skipping ${fileName} since it is excluded!"
continue
fi
if [ ! -f "./.github/workflows/quickstart_${fileName}_ci.yml" ]; then
echo "Skipping ${fileName} since it has no ./.github/workflows/quickstart_${fileName}_ci.yml!"
continue
fi

if [ ! -d "./${fileName}/charts" ]; then
echo "Skipping ${fileName} since it has no ./${fileName}/charts!"
continue
fi

echo "Adding ${fileName} to the list"
tmp2+=(${fileName})
done


quickstarts_to_test=(${tmp2[@]})

echo "quickstarts_to_test=${quickstarts_to_test[*]}" >> $GITHUB_OUTPUT
- name: Calculate Matrix and Output Quickstart List
id: calculate-matrix
env:
QUICKSTARTS_TO_TEST: ${{ steps.quickstarts-to-test.outputs.quickstarts_to_test }}
run: |
set -x
matrix="{\"quickstart\":["
first=1
echo "The list of quickstarts has been determined to:"
for qs_dir in ${QUICKSTARTS_TO_TEST}; do
echo "${qs_dir}"
if [ "${first}" = "0" ]; then
matrix="${matrix}, "
fi
matrix="${matrix}\"${qs_dir}\""
first=0
done
matrix="${matrix}]}"
echo "Calculated Matrix JSON: ${matrix}"
echo "matrix=${matrix}" >> $GITHUB_OUTPUT
run-tests-on-kubernetes:
name: Test on Kubernetes
runs-on: ubuntu-latest
needs: calculate-changed-quickstarts
strategy:
matrix: ${{fromJSON(needs.calculate-changed-quickstarts.outputs.quickstart-matrix)}}
steps:
- name: Setup Minikube
id: minikube
uses: manusa/actions-setup-minikube@v2.10.0
with:
driver: docker
container runtime: containerd
minikube version: 'v1.33.0'
kubernetes version: 'v1.30.0'
github token: ${{ secrets.GITHUB_TOKEN }}
start args: "--memory='4gb' --cpus='2'"
- name: Enable minikube registry
run: |
minikube addons enable registry
kubectl port-forward --namespace kube-system service/registry 5000:80 &
- uses: azure/setup-helm@v4.2.0
with:
version: v3.14.2
- name: Add WildFly Helm Chart
run: |
helm repo add wildfly https://docs.wildfly.org/wildfly-charts/
helm repo update wildfly
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.21.3
- uses: actions/setup-java@v4
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'
cache: 'maven'
cache-dependency-path: '${{ matrix.quickstart }}/**/pom.xml'
- name: Run the Quickstart tests
shell: bash
run: |
${{ env.KUBERNETES_CORE_DIRECTORY }}/run-quickstart-test-on-kubernetes.sh ${{ matrix.quickstart }} && passed=1 || passed=0
if [ "${passed}" = "1" ]; then
echo "Tests for ${qs_dir} PASSED!"
else
echo "Tests for ${qs_dir} FAILED!"
exit 1
fi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Quickstarts that should not be tested on OpenShift.
# One per line with no trailing spaces, and make sure to have a newline at the end
# microprofile-reactive-messaging-kafka
# Can't connect to server... I see something relating to adding a user in the README but nothing in the OpenShift tests about this so it is odd
ejb-remote
# Some problems once the operator is installed. I haven't been able to get my go environment set up to the same version
ejb-txn-remote-call

115 changes: 115 additions & 0 deletions .github/workflows/scripts/kubernetes/core/overridable-functions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# These functions are 'overridable in the individual quickstarts.
# To do so create a ./qs-overrides/${qs_dir}/overridable-functions.sh and override the
# functions you need to. ${qs_dir} in this case is the same as the name of the quickstart directory
# that you want to tweak

# The default is to use the quickstart directory as the name, but in some cases
# a quickstart may need to shorten the name of the application in order to control
# the length of the resources created by OpenShift
#
# Parameters
# 1 - the name of the qs directory (not the full path)
function applicationName() {
echo "${1}"
}


# Override if the tests should install and run in a different namespace.
# If not specified the 'default' namespace will be used
# The main script will take care of
#
# Parameters
# 1 - the name of the qs directory
function namespace() {
application="${1}"
# Uncomment to make the tests run in the 'testing' namespace
#echo "testing"
}


# Installs any prerequisites before doing the Helm install.
# The current directory is the quickstart directory
#
# Parameters
# 1 - application name
function installPrerequisites()
{
application="${1}"
echo "No prerequisites required for ${application}"
}

# Cleans any prerequisites after doing the Helm uninstall.
# The current directory is the quickstart directory
#
# Parameters
# 1 - application name
function cleanPrerequisites()
{
application="${1}"
echo "No prerequisites to clean for ${application}"
}

# Performs the 'helm install' command.
# The current directory is the quickstart directory
# Parameters
# 1 - application name
# 2 - set arguments
#
# Returns the exit status of the helm install
#
# Additionally the following env vars may be used:
# * helm_install_timeout - the adjusted timeout for the helm install
#
function helmInstall() {
application="${1}"
helm_set_arguments="$2"

# '--wait' waits until the pods are ready
# `--timeout` sets the timeout for the wait.
# https://helm.sh/docs/helm/helm_install/ has more details
# Don't quote ${helm_set_arguments} since then it fails when there are none
helm install "${application}" wildfly/wildfly -f charts/helm.yaml --wait --timeout=${helm_install_timeout} ${helm_set_arguments}
echo "$?"
}

# Commands to run once the Helm install has completed
function runPostHelmInstallCommands() {
echo "No post helm install commands"
}


# Whether to disable TLS route.
# Default is to not do anything.
# To disable TLS routes, override this method change the body to 'echo "1"'
function disableTlsRoute() {
echo ""
}

# If the Helm variables set by the parent script (e.g. 'build.enabled') need a prefix, return
# that here. If e.g "wildfly." is returned, the resulting 'build.enabled' becomes 'wildfly.build.enabled'
function getHelmSetVariablePrefix() {
echo ""
}

# If we need to specify any extra arguments (such as system properties) to the
# 'mvn verify -Pintegration-testing command, specify those here'
function getMvnVerifyExtraArguments() {
echo ""
}

# More output when the helm install has gone wrong
# Parameters
# 1 - application name
#
function helmInstallFailed() {
# Noop - the main work is done elsewhere
echo ""
}

# More output when the tests have failed
# Parameters
# 1 - application name
#
function testsFailed() {
echo ""
}
Loading

0 comments on commit 10d0fa8

Please sign in to comment.