From 8f5d33646ebfadcd8d55dc14a3bb34676abc6fa1 Mon Sep 17 00:00:00 2001 From: Manuel Finelli Date: Tue, 17 Dec 2024 11:28:58 +0000 Subject: [PATCH] ToSqueeze: Addressed Kabir's review --- .../kubernetes/core/overridable-functions.sh | 126 ++++++++---------- .../core/run-quickstart-test-on-kubernetes.sh | 98 ++++++++++++-- .../overridable-functions.sh | 73 ++++------ 3 files changed, 171 insertions(+), 126 deletions(-) diff --git a/.github/workflows/scripts/kubernetes/core/overridable-functions.sh b/.github/workflows/scripts/kubernetes/core/overridable-functions.sh index fc3e021799..6802d43279 100644 --- a/.github/workflows/scripts/kubernetes/core/overridable-functions.sh +++ b/.github/workflows/scripts/kubernetes/core/overridable-functions.sh @@ -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 # @@ -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. @@ -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 @@ -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 @@ -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. diff --git a/.github/workflows/scripts/kubernetes/core/run-quickstart-test-on-kubernetes.sh b/.github/workflows/scripts/kubernetes/core/run-quickstart-test-on-kubernetes.sh index 6515f5d5f3..6dc52479c5 100755 --- a/.github/workflows/scripts/kubernetes/core/run-quickstart-test-on-kubernetes.sh +++ b/.github/workflows/scripts/kubernetes/core/run-quickstart-test-on-kubernetes.sh @@ -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 @@ -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) diff --git a/.github/workflows/scripts/kubernetes/qs-overrides/ejb-txn-remote-call/overridable-functions.sh b/.github/workflows/scripts/kubernetes/qs-overrides/ejb-txn-remote-call/overridable-functions.sh index 9d81fed485..5d3b53337a 100644 --- a/.github/workflows/scripts/kubernetes/qs-overrides/ejb-txn-remote-call/overridable-functions.sh +++ b/.github/workflows/scripts/kubernetes/qs-overrides/ejb-txn-remote-call/overridable-functions.sh @@ -1,16 +1,3 @@ -# 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 - -# Installs any prerequisites before doing the Helm install. -# The current directory is the quickstart directory. -# 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}" # The fill microprofile-reactive-messaging-kafka name results in names of generated resources which are too long for @@ -18,12 +5,6 @@ function applicationName() { echo "ejb-txn-remote-call" } - -# Installs any prerequisites before doing the Helm install. -# The current directory is the quickstart directory -# -# Parameters -# 1 - application name function installPrerequisites() { application="${1}" @@ -68,6 +49,10 @@ function installPrerequisites() cd $CURRENT_FOLDER || return } +function customProvisionServer() { + echo 1 +} + function provisionServer() { application="${1}" @@ -101,25 +86,11 @@ function provisionServer() { cd .. } -function helmInstall() { - echo "helmInstall() nothing to do" - #helm_set_arguments="$2" - - # TODO https://issues.redhat.com/browse/WFLY-18574 remove this when persistence is working - # This seems to work with my postgresql.yaml :fingers_crossed - # helm_set_arguments="${helm_set_arguments} --set postgresql.primary.persistence.enabled=false" - - # Don't quote ${helm_set_arguments} as it breaks the command when empty, and seems to work without - #helm install client -f charts/client.yaml wildfly/wildfly --wait --timeout="${helm_install_timeout}" ${helm_set_arguments} - #echo "$?" - # TODO: should we check when the build is done? - #helm install server -f charts/server.yaml wildfly/wildfly --wait --timeout="${helm_install_timeout}" ${helm_set_arguments} - #echo "$?" - # TODO: should we check when the build is done? - - # Make sure that view permissions are granted to the default system account. - # kubectl policy add-role-to-user view system:serviceaccount:$(oc project -q):default -n $(oc project -q) +function customProcessing() { + echo 1 +} +function processing() { seconds=60 kubectl create -f client/client-cr.yaml @@ -157,10 +128,14 @@ function helmInstall() { done } -# Port forward to test the quickstart -# Parameters -# 1 - application name -# +function helmInstall() { + echo "Nothing to do in processing()..." +} + +function customPortForward() { + echo 1 +} + function portForward() { seconds=60 @@ -208,11 +183,10 @@ function portForward() { echo "${kubectl_fwd_pid_client} ${kubectl_fwd_pid_server}" } -# Running tests of the quickstart -# Parameters -# 1 - server protocol -# 2 - extra maven argument for the verify target -# +function customRunningTests() { + echo 1 +} + function runningTests() { application="${1}" server_protocol="${2}" @@ -278,9 +252,10 @@ function runningTests() { return "${result}" } -# Performs the 'helm uninstall' command. -# Parameters -# 1 - application name +function customHelmUninstall() { + return 0 +} + function helmUninstall() { echo "helmUninstall() nothing to do" }