Skip to content

Commit 77711f4

Browse files
committed
ToSqueeze: Addressed Kabir's review
1 parent f1d722a commit 77711f4

File tree

3 files changed

+171
-126
lines changed

3 files changed

+171
-126
lines changed

.github/workflows/scripts/kubernetes/core/overridable-functions.sh

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ function cleanPrerequisites()
5353
echo "No prerequisites to clean for ${application}"
5454
}
5555

56+
# Trigger the custom behaviour when it comes to
57+
# provision the server and push the imagestream.
58+
# Returns
59+
# 0 - false
60+
# 1 - true
61+
#
62+
function customProvisionServer() {
63+
echo 0
64+
}
65+
5666
# Provision server and push imagestream
5767
# The current directory is the quickstart directory
5868
#
@@ -62,17 +72,25 @@ function cleanPrerequisites()
6272
#
6373
function provisionServer()
6474
{
65-
application="${1}"
66-
qs_dir="${2}"
75+
echo "Nothing to do in provisionServer()..."
76+
}
6777

68-
echo "Building application and provisioning server image..."
69-
mvn -B package -Popenshift wildfly:image -DskipTests
78+
# Trigger a custom behaviour when it comes to
79+
# setting up the environment
80+
# Returns
81+
# 0 - false
82+
# 1 - true
83+
#
84+
function customProcessing() {
85+
echo 0
86+
}
7087

71-
echo "Tagging image and pushing to registry..."
72-
export root_image_name="localhost:5000/${application}"
73-
export image="${root_image_name}:latest"
74-
docker tag ${qs_dir} ${image}
75-
docker push ${image}
88+
# Set up the environment before testing
89+
# Parameters
90+
# 1 - application name
91+
#
92+
function processing() {
93+
echo "Nothing to do in processing()..."
7694
}
7795

7896
# Performs the 'helm install' command.
@@ -87,33 +105,7 @@ function provisionServer()
87105
# * helm_install_timeout - the adjusted timeout for the helm install
88106
#
89107
function helmInstall() {
90-
application="${1}"
91-
helm_set_arg_prefix="${2}"
92-
helm_install_timeout="${3}"
93-
94-
# Helm install, waiting for the pods to come up
95-
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}"
96-
97-
additional_arguments="No additional arguments"
98-
if [ -n "${helm_set_arguments}" ]; then
99-
additional_arguments="Additional arguments: ${helm_set_arguments}"
100-
fi
101-
102-
echo "Performing Helm install and waiting for completion.... (${additional_arguments})"
103-
104-
# '--wait' waits until the pods are ready
105-
# `--timeout` sets the timeout for the wait.
106-
# https://helm.sh/docs/helm/helm_install/ has more details
107-
# Don't quote ${helm_set_arguments} since then it fails when there are none
108-
helm install "${application}" wildfly/wildfly -f charts/helm.yaml --wait --timeout=${helm_install_timeout} ${helm_set_arguments}
109-
110-
echo "ret: $?"
111-
if [ "$?" != "0" ]; then
112-
echo "Helm install failed!"
113-
echo "Dumping the application pod(s)"
114-
kubectl logs deployment/"${application}"
115-
helmInstallFailed
116-
fi
108+
echo "Nothing to do in helmInstall()..."
117109
}
118110

119111
# Commands to run once the Helm install has completed
@@ -150,16 +142,32 @@ function helmInstallFailed() {
150142
echo ""
151143
}
152144

145+
# Trigger a custom behaviour when it comes to
146+
# forward ports
147+
# Returns
148+
# 0 - false
149+
# 1 - true
150+
#
151+
function customPortForward() {
152+
echo 0
153+
}
154+
153155
# Port forward to test the quickstart
154156
# Parameters
155157
# 1 - application name
156158
#
157159
function portForward() {
158-
application="${1}"
160+
echo "Nothing to do in portForward()..."
161+
}
159162

160-
kubectl port-forward service/${application} 8080:8080 &
161-
kubectl_fwd_pid=$!
162-
echo "${kubectl_fwd_pid}"
163+
# Trigger a custom behaviour when it comes to
164+
# running tests
165+
# Returns
166+
# 0 - false
167+
# 1 - true
168+
#
169+
function customRunningTests() {
170+
echo 0
163171
}
164172

165173
# Running tests of the quickstart
@@ -169,35 +177,17 @@ function portForward() {
169177
# 3 - extra maven argument for the verify target
170178
#
171179
function runningTests() {
172-
application="${1}"
173-
server_protocol="${2}"
174-
extraMvnVerifyArguments="${3}"
175-
176-
route="localhost:8080"
177-
178-
mvnVerifyArguments="-Dserver.host=${server_protocol}://${route} "
179-
if [ -n "${extraMvnVerifyArguments}" ]; then
180-
mvnVerifyArguments="${mvnVerifyArguments} ${extraMvnVerifyArguments}"
181-
fi
182-
if [ "${QS_DEBUG_TESTS}" = "1" ]; then
183-
mvnVerifyArguments="${mvnVerifyArguments} -Dmaven.failsafe.debug=true"
184-
fi
185-
186-
echo "Verify Arguments: ${mvnVerifyArguments}"
187-
188-
mvn -B verify -Pintegration-testing ${mvnVerifyArguments}
189-
190-
test_status="$?"
191-
192-
if [ "$?" != "0" ]; then
193-
test_status=1
194-
echo "Tests failed!"
195-
echo "Dumping the application pod(s)"
196-
kubectl logs deployment/"${application}"
197-
testsFailed
198-
fi
180+
echo "Nothing to do in portForward()..."
181+
}
199182

200-
echo "${test_status}"
183+
# Trigger a custom behaviour when it comes to
184+
# running tests
185+
# Returns
186+
# 0 - false
187+
# 1 - true
188+
#
189+
function customHelmUninstall() {
190+
echo 0
201191
}
202192

203193
# Performs the 'helm uninstall' command.

.github/workflows/scripts/kubernetes/core/run-quickstart-test-on-kubernetes.sh

Lines changed: 89 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,64 @@ installPrerequisites "${application}"
8383
################################################################################################
8484
# Provision server and push imagestream
8585

86-
provisionServer "${application}" "${qs_dir}"
86+
customProvisionServer=$(customProvisionServer)
87+
if [ "0" = "${customProvisionServer}" ]; then
88+
echo "Building application and provisioning server image..."
89+
mvn -B package -Popenshift wildfly:image -DskipTests
90+
91+
echo "Tagging image and pushing to registry..."
92+
export root_image_name="localhost:5000/${application}"
93+
export image="${root_image_name}:latest"
94+
docker tag ${qs_dir} ${image}
95+
docker push ${image}
96+
97+
echo "Creating docker file locally and pushing to registry at localhost:5000"
98+
docker build -t "${image}" target
99+
else
100+
provisionServer "${application}" "${qs_dir}"
101+
fi
87102

88103
################################################################################################
89104

90-
# helmInstall is from overridable-functions.sh
91-
helmInstall "${application}" "${helm_set_arg_prefix}" "${helm_install_timeout}"
105+
customProcessing=$(customProcessing)
106+
if [ "0" = "${customProcessing}" ]; then
107+
# Helm install, waiting for the pods to come up
108+
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}"
109+
110+
additional_arguments="No additional arguments"
111+
if [ -n "${helm_set_arguments}" ]; then
112+
additional_arguments="Additional arguments: ${helm_set_arguments}"
113+
fi
114+
115+
echo "Performing Helm install and waiting for completion.... (${additional_arguments})"
116+
# helmInstall is from overridable-functions.sh
117+
helm_install_ret=$(helmInstall "${application}" "${helm_set_arguments}")
118+
119+
# For some reason the above sometimes becomes a multi-line string. actual The exit code will be
120+
# on the last line
121+
helm_install_ret=$(echo "${helm_install_ret}"| tail -n 1)
122+
123+
echo "ret: ${helm_install_ret}"
124+
if [ "${helm_install_ret}" != "0" ]; then
125+
echo "Helm install failed!"
126+
echo "Dumping the application pod(s)"
127+
kubectl logs deployment/"${application}"
128+
helmInstallFailed
129+
fi
130+
else
131+
processing
132+
fi
92133

93-
echo "Performing Port Forward and waiting for completion...."
94-
kubectl_fwd_pids=$(portForward "${application}")
95-
echo "Process ID(s) of kubect port-forward: ${kubectl_fwd_pids}"
134+
customPortForward=$(customPortForward)
135+
if [ "0" = "${customPortForward}" ]; then
136+
kubectl port-forward service/${application} 8080:8080 &
137+
kubectl_fwd_pids=$!
138+
echo "Process ID of kubect port-forward: ${kubectl_fwd_pid}"
139+
else
140+
echo "Performing Port Forward and waiting for completion...."
141+
kubectl_fwd_pids=$(portForward "${application}")
142+
echo "Process ID(s) of kubect port-forward: ${kubectl_fwd_pids}"
143+
fi
96144

97145
################################################################################################
98146
# Run any post install
@@ -104,15 +152,47 @@ runPostHelmInstallCommands
104152
echo "running the tests"
105153
pwd
106154

107-
runningTests "${application}" "${server_protocol}" "$(getMvnVerifyExtraArguments)"
108-
test_status=$?
155+
customRunningTests=$(customRunningTests)
156+
if [ "0" = "${customRunningTests}" ]; then
157+
route="localhost:8080"
158+
159+
mvnVerifyArguments="-Dserver.host=${server_protocol}://${route} "
160+
extraMvnVerifyArguments="$(getMvnVerifyExtraArguments)"
161+
if [ -n "${extraMvnVerifyArguments}" ]; then
162+
mvnVerifyArguments="${mvnVerifyArguments} ${extraMvnVerifyArguments}"
163+
fi
164+
if [ "${QS_DEBUG_TESTS}" = "1" ]; then
165+
mvnVerifyArguments="${mvnVerifyArguments} -Dmaven.failsafe.debug=true"
166+
fi
167+
168+
echo "Verify Arguments: ${mvnVerifyArguments}"
169+
170+
mvn -B verify -Pintegration-testing ${mvnVerifyArguments}
171+
172+
if [ "$?" != "0" ]; then
173+
test_status=1
174+
echo "Tests failed!"
175+
echo "Dumping the application pod(s)"
176+
kubectl logs deployment/"${application}"
177+
testsFailed
178+
fi
179+
else
180+
runningTests "${application}" "${server_protocol}" "$(getMvnVerifyExtraArguments)"
181+
test_status=$?
182+
fi
109183

110184
kill -9 ${kubectl_fwd_pids}
111185

112186
################################################################################################
113187
# Helm uninstall
114188
echo "Running Helm uninstall"
115-
helmUninstall "${application}"
189+
190+
customRunningTests=$(customHelmUninstall)
191+
if [ "0" = "${customRunningTests}" ]; then
192+
helm uninstall "${application}" --wait --timeout=10m0s
193+
else
194+
helmUninstall "${application}"
195+
fi
116196

117197
################################################################################################
118198
# Clean pre-requisites (cleanPrerequisites is fromm overridable-functions.sh)

0 commit comments

Comments
 (0)