@@ -5,22 +5,44 @@ scriptDir=$(dirname "$(readlink -f "$0")")
55source " ${scriptDir} /includes/cluster/common.sh"
66
77usage () {
8- echo " USAGE: deploy-subject [<test-dir>]"
8+ echo " USAGE: deploy-subject [flags] [ <test-dir>]"
99 echo " "
1010 echo " Deploys the subject to be tested."
1111 echo " "
1212 echo " <test-dir> - The test directory. If not provided, the current directory is used."
1313 echo " Expects this file to exist:"
1414 echo " test-plan.yaml - The test plan."
15+ echo " "
16+ echo " --no-upgrade - Skip the upgrade phase (if one is defined)."
17+ echo " --upgrade-only - Skip the initial deployment and only run the upgrade phase."
1518}
1619
1720# Argument parsing
18- if [ " ${1} " == " -h" ] || [ " ${1} " == " -help" ] || [ " ${1} " == " --help" ]; then
19- usage
20- exit 0
21- fi
21+ noUpgrade=false
22+ upgradeOnly=false
23+ testDir=" "
24+
25+ while [ $# -gt 0 ]; do
26+ case " $1 " in
27+ -h|-help|--help)
28+ usage
29+ exit 0
30+ ;;
31+ --no-upgrade)
32+ noUpgrade=true
33+ shift
34+ ;;
35+ --upgrade-only)
36+ upgradeOnly=true
37+ shift
38+ ;;
39+ * )
40+ testDir=" $1 "
41+ shift
42+ ;;
43+ esac
44+ done
2245
23- testDir=$1
2446if [ -z " ${testDir} " ]; then
2547 testDir=$( pwd)
2648elif [ ! -d " ${testDir} " ]; then
@@ -54,13 +76,13 @@ if [ -n "${releaseNamespace}" ]; then
5476 namespaceArg=(--namespace " ${releaseNamespace} " --create-namespace)
5577fi
5678
57- if [ " ${subjectType} " == " manifest" ]; then
79+ if [ " ${upgradeOnly} " != " true " ] && [ " ${ subjectType}" == " manifest" ]; then
5880 echo ; echo " ### Deploying manifest: ${subjectPath} "
5981 subjectPath=$( realpath " ${testDir} /${subjectPath} " )
6082 applyCommand=(kubectl apply -f " ${subjectPath} " " ${namespaceArg[@]} " " ${extraArgs[@]} " )
6183 echo " ${applyCommand[@]} "
6284 " ${applyCommand[@]} "
63- elif [ " ${subjectType} " == " terraform" ]; then
85+ elif [ " ${upgradeOnly} " != " true " ] && [ " ${ subjectType}" == " terraform" ]; then
6486 echo ; echo " ### Deploying via terraform: ${subjectPath} "
6587 subjectPath=$( realpath " ${testDir} /${subjectPath} " )
6688 initCommmand=(terraform -chdir=" ${subjectPath} " init)
@@ -69,7 +91,7 @@ elif [ "${subjectType}" == "terraform" ]; then
6991 applyCommand=(terraform -chdir=" ${subjectPath} " apply -auto-approve)
7092 echo " ${applyCommand[@]} "
7193 " ${applyCommand[@]} "
72- elif [ " ${subjectType} " == " helmfile" ]; then
94+ elif [ " ${upgradeOnly} " != " true " ] && [ " ${ subjectType}" == " helmfile" ]; then
7395 echo ; echo " ### Deploying via helmfile: ${subjectPath} "
7496 subjectPath=$( realpath " ${testDir} /${subjectPath} " )
7597 applyCommand=(helmfile apply -f " ${subjectPath} " " ${namespaceArg[@]} " " ${extraArgs[@]} " )
@@ -166,29 +188,39 @@ elif [ "${subjectType}" == "helm" ]; then
166188 fi
167189
168190 # Run the helm command
169- echo ; echo " ### Deploying Helm chart: ${chartName} "
170- helmCommand+=(" ${chartArg[@]} " " ${versionArg[@]} " " ${namespaceArg[@]} " " ${valuesArg[@]} " " ${extraArgs[@]} " )
171- echo " ${helmCommand[@]} "
172- " ${helmCommand[@]} "
191+ if [ " ${upgradeOnly} " != " true" ]; then
192+ echo ; echo " ### Deploying Helm chart: ${chartName} "
193+ helmCommand+=(" ${chartArg[@]} " " ${versionArg[@]} " " ${namespaceArg[@]} " " ${valuesArg[@]} " " ${extraArgs[@]} " )
194+ echo " ${helmCommand[@]} "
195+ " ${helmCommand[@]} "
196+ fi
173197fi
174198
175- # Run post-install options
176- postInstallFilesCount=$( yq eval ' .subject.postInstall.files | length - 1' " ${testPlan} " )
177- if [ " ${postInstallFilesCount} " -ge 0 ]; then
178- for i in $( seq 0 " ${postInstallFilesCount} " ) ; do
179- postInstallFile=$( yq eval " .subject.postInstall.files[${i} ]" " ${testPlan} " )
180- postInstallFile=$( realpath " ${testDir} /${postInstallFile} " )
181- if [ -f " ${postInstallFile} " ]; then
182- echo " #### Deploying Post-install manifest: ${postInstallFile} "
183- kubectl apply -f " ${postInstallFile} "
184- else
185- echo " Post-install file not found: ${postInstallFile} ."
186- exit 1
187- fi
188- done
199+ if [ " ${upgradeOnly} " != " true" ]; then
200+ # Optional delay after subject deployment
201+ sleep=$( yq eval " .subject.sleepAfter // \"\" " " ${testPlan} " )
202+ if [ -n " ${sleep} " ]; then
203+ sleep " ${sleep} "
204+ fi
205+
206+ # Run post-install options
207+ postInstallFilesCount=$( yq eval ' .subject.postInstall.files | length - 1' " ${testPlan} " )
208+ if [ " ${postInstallFilesCount} " -ge 0 ]; then
209+ for i in $( seq 0 " ${postInstallFilesCount} " ) ; do
210+ postInstallFile=$( yq eval " .subject.postInstall.files[${i} ]" " ${testPlan} " )
211+ postInstallFile=$( realpath " ${testDir} /${postInstallFile} " )
212+ if [ -f " ${postInstallFile} " ]; then
213+ echo " #### Deploying Post-install manifest: ${postInstallFile} "
214+ kubectl apply -f " ${postInstallFile} "
215+ else
216+ echo " Post-install file not found: ${postInstallFile} ."
217+ exit 1
218+ fi
219+ done
220+ fi
189221fi
190222
191- if [ " ${subjectType} " == " helm" ]; then
223+ if [ " ${noUpgrade} " != " true " ] && [ " ${ subjectType}" == " helm" ]; then
192224 upgradeValues=$( yq eval ' .subject.upgrade.values // ""' " ${testPlan} " )
193225 upgradeValuesFile=$( yq eval ' .subject.upgrade.valuesFile // ""' " ${testPlan} " )
194226 upgradeVersion=$( yq eval ' .subject.upgrade.version // ""' " ${testPlan} " )
@@ -237,5 +269,11 @@ if [ "${subjectType}" == "helm" ]; then
237269 done
238270 echo " ${helmUpgradeCommand[@]} "
239271 " ${helmUpgradeCommand[@]} "
272+
273+ # Optional delay after subject upgrade
274+ sleep=$( yq eval " .subject.upgrade.sleepAfter // \"\" " " ${testPlan} " )
275+ if [ -n " ${sleep} " ]; then
276+ sleep " ${sleep} "
277+ fi
240278 fi
241- fi
279+ fi
0 commit comments