Skip to content

Commit

Permalink
ToSqueeze: Addressed Kabir's review
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfinelli committed Dec 17, 2024
1 parent f1d722a commit 8f5d336
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 126 deletions.
126 changes: 58 additions & 68 deletions .github/workflows/scripts/kubernetes/core/overridable-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ function cleanPrerequisites()
echo "No prerequisites to clean for ${application}"
}

# Trigger the custom behaviour when it comes to
# provision the server and push the imagestream.
# Returns
# 0 - false
# 1 - true
#
function customProvisionServer() {
echo 0
}

# Provision server and push imagestream
# The current directory is the quickstart directory
#
Expand All @@ -62,17 +72,25 @@ function cleanPrerequisites()
#
function provisionServer()
{
application="${1}"
qs_dir="${2}"
echo "Nothing to do in provisionServer()..."
}

echo "Building application and provisioning server image..."
mvn -B package -Popenshift wildfly:image -DskipTests
# Trigger a custom behaviour when it comes to
# setting up the environment
# Returns
# 0 - false
# 1 - true
#
function customProcessing() {
echo 0
}

echo "Tagging image and pushing to registry..."
export root_image_name="localhost:5000/${application}"
export image="${root_image_name}:latest"
docker tag ${qs_dir} ${image}
docker push ${image}
# Set up the environment before testing
# Parameters
# 1 - application name
#
function processing() {
echo "Nothing to do in processing()..."
}

# Performs the 'helm install' command.
Expand All @@ -87,33 +105,7 @@ function provisionServer()
# * helm_install_timeout - the adjusted timeout for the helm install
#
function helmInstall() {
application="${1}"
helm_set_arg_prefix="${2}"
helm_install_timeout="${3}"

# Helm install, waiting for the pods to come up
helm_set_arguments=" --set ${helm_set_arg_prefix}build.enabled=false --set ${helm_set_arg_prefix}deploy.route.enabled=false --set ${helm_set_arg_prefix}image.name=${root_image_name}"

additional_arguments="No additional arguments"
if [ -n "${helm_set_arguments}" ]; then
additional_arguments="Additional arguments: ${helm_set_arguments}"
fi

echo "Performing Helm install and waiting for completion.... (${additional_arguments})"

# '--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 "ret: $?"
if [ "$?" != "0" ]; then
echo "Helm install failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
helmInstallFailed
fi
echo "Nothing to do in helmInstall()..."
}

# Commands to run once the Helm install has completed
Expand Down Expand Up @@ -150,16 +142,32 @@ function helmInstallFailed() {
echo ""
}

# Trigger a custom behaviour when it comes to
# forward ports
# Returns
# 0 - false
# 1 - true
#
function customPortForward() {
echo 0
}

# Port forward to test the quickstart
# Parameters
# 1 - application name
#
function portForward() {
application="${1}"
echo "Nothing to do in portForward()..."
}

kubectl port-forward service/${application} 8080:8080 &
kubectl_fwd_pid=$!
echo "${kubectl_fwd_pid}"
# Trigger a custom behaviour when it comes to
# running tests
# Returns
# 0 - false
# 1 - true
#
function customRunningTests() {
echo 0
}

# Running tests of the quickstart
Expand All @@ -169,35 +177,17 @@ function portForward() {
# 3 - extra maven argument for the verify target
#
function runningTests() {
application="${1}"
server_protocol="${2}"
extraMvnVerifyArguments="${3}"

route="localhost:8080"

mvnVerifyArguments="-Dserver.host=${server_protocol}://${route} "
if [ -n "${extraMvnVerifyArguments}" ]; then
mvnVerifyArguments="${mvnVerifyArguments} ${extraMvnVerifyArguments}"
fi
if [ "${QS_DEBUG_TESTS}" = "1" ]; then
mvnVerifyArguments="${mvnVerifyArguments} -Dmaven.failsafe.debug=true"
fi

echo "Verify Arguments: ${mvnVerifyArguments}"

mvn -B verify -Pintegration-testing ${mvnVerifyArguments}

test_status="$?"

if [ "$?" != "0" ]; then
test_status=1
echo "Tests failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
testsFailed
fi
echo "Nothing to do in portForward()..."
}

echo "${test_status}"
# Trigger a custom behaviour when it comes to
# running tests
# Returns
# 0 - false
# 1 - true
#
function customHelmUninstall() {
echo 0
}

# Performs the 'helm uninstall' command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,64 @@ installPrerequisites "${application}"
################################################################################################
# Provision server and push imagestream

provisionServer "${application}" "${qs_dir}"
customProvisionServer=$(customProvisionServer)
if [ "0" = "${customProvisionServer}" ]; then
echo "Building application and provisioning server image..."
mvn -B package -Popenshift wildfly:image -DskipTests

echo "Tagging image and pushing to registry..."
export root_image_name="localhost:5000/${application}"
export image="${root_image_name}:latest"
docker tag ${qs_dir} ${image}
docker push ${image}

echo "Creating docker file locally and pushing to registry at localhost:5000"
docker build -t "${image}" target
else
provisionServer "${application}" "${qs_dir}"
fi

################################################################################################

# helmInstall is from overridable-functions.sh
helmInstall "${application}" "${helm_set_arg_prefix}" "${helm_install_timeout}"
customProcessing=$(customProcessing)
if [ "0" = "${customProcessing}" ]; then
# Helm install, waiting for the pods to come up
helm_set_arguments=" --set ${helm_set_arg_prefix}build.enabled=false --set ${helm_set_arg_prefix}deploy.route.enabled=false --set ${helm_set_arg_prefix}image.name=${root_image_name}"

additional_arguments="No additional arguments"
if [ -n "${helm_set_arguments}" ]; then
additional_arguments="Additional arguments: ${helm_set_arguments}"
fi

echo "Performing Helm install and waiting for completion.... (${additional_arguments})"
# helmInstall is from overridable-functions.sh
helm_install_ret=$(helmInstall "${application}" "${helm_set_arguments}")

# For some reason the above sometimes becomes a multi-line string. actual The exit code will be
# on the last line
helm_install_ret=$(echo "${helm_install_ret}"| tail -n 1)

echo "ret: ${helm_install_ret}"
if [ "${helm_install_ret}" != "0" ]; then
echo "Helm install failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
helmInstallFailed
fi
else
processing
fi

echo "Performing Port Forward and waiting for completion...."
kubectl_fwd_pids=$(portForward "${application}")
echo "Process ID(s) of kubect port-forward: ${kubectl_fwd_pids}"
customPortForward=$(customPortForward)
if [ "0" = "${customPortForward}" ]; then
nohup kubectl port-forward service/${application} 8080:8080 > /dev/null 2>&1 &
kubectl_fwd_pids=$!
echo "Process ID of kubect port-forward: ${kubectl_fwd_pids}"
else
echo "Performing Port Forward and waiting for completion...."
kubectl_fwd_pids=$(portForward "${application}")
echo "Process ID(s) of kubect port-forward: ${kubectl_fwd_pids}"
fi

################################################################################################
# Run any post install
Expand All @@ -104,15 +152,47 @@ runPostHelmInstallCommands
echo "running the tests"
pwd

runningTests "${application}" "${server_protocol}" "$(getMvnVerifyExtraArguments)"
test_status=$?
customRunningTests=$(customRunningTests)
if [ "0" = "${customRunningTests}" ]; then
route="localhost:8080"

mvnVerifyArguments="-Dserver.host=${server_protocol}://${route} "
extraMvnVerifyArguments="$(getMvnVerifyExtraArguments)"
if [ -n "${extraMvnVerifyArguments}" ]; then
mvnVerifyArguments="${mvnVerifyArguments} ${extraMvnVerifyArguments}"
fi
if [ "${QS_DEBUG_TESTS}" = "1" ]; then
mvnVerifyArguments="${mvnVerifyArguments} -Dmaven.failsafe.debug=true"
fi

echo "Verify Arguments: ${mvnVerifyArguments}"

mvn -B verify -Pintegration-testing ${mvnVerifyArguments}

if [ "$?" != "0" ]; then
test_status=1
echo "Tests failed!"
echo "Dumping the application pod(s)"
kubectl logs deployment/"${application}"
testsFailed
fi
else
runningTests "${application}" "${server_protocol}" "$(getMvnVerifyExtraArguments)"
test_status=$?
fi

kill -9 ${kubectl_fwd_pids}

################################################################################################
# Helm uninstall
echo "Running Helm uninstall"
helmUninstall "${application}"

customHelmUninstall=$(customHelmUninstall)
if [ "0" = "${customHelmUninstall}" ]; then
helm uninstall "${application}" --wait --timeout=10m0s
else
helmUninstall "${application}"
fi

################################################################################################
# Clean pre-requisites (cleanPrerequisites is fromm overridable-functions.sh)
Expand Down
Loading

0 comments on commit 8f5d336

Please sign in to comment.