Skip to content

Commit c7fd18e

Browse files
committed
Add scripts to run the upgrade tests
Signed-off-by: Romain Arnaud <[email protected]>
1 parent 4922441 commit c7fd18e

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

ci/hack/plnsvc_upgrade_tests.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env bash
2+
3+
#quit if exit status of any cmd is a non-zero value
4+
set -o errexit
5+
set -o nounset
6+
set -o pipefail
7+
8+
usage() {
9+
echo "
10+
Usage:
11+
$0 [options]
12+
13+
Run Pipeline Service upgrade tests on the cluster referenced by KUBECONFIG.
14+
15+
Using the 'main' branch as the baseline, it will deploy Pipeline Service,
16+
upgrade to your current branch, and downgrade back to 'main', testing the
17+
service at every step along the way.
18+
19+
Optional arguments:
20+
-k, --kubeconfig KUBECONFIG
21+
kubeconfig to the cluster to test.
22+
The current context will be used.
23+
Default value: \$KUBECONFIG"
24+
# -f, --from VERSION
25+
# Branch, SHA or tag of the base version.
26+
# Default: main.
27+
# -t, --to VERSION
28+
# Branch, SHA or tag of the new version.
29+
# Default: Current commit.
30+
echo "\
31+
-d, --debug
32+
Activate tracing/debug mode.
33+
-h, --help
34+
Display this message.
35+
36+
Example:
37+
$0 --kubeconfig mykubeconfig.yaml
38+
"
39+
}
40+
41+
parse_args() {
42+
KUBECONFIG="${KUBECONFIG:-$HOME/.kube/config}"
43+
FROM_VERSION="main"
44+
TO_VERSION=$(git branch --show-current)
45+
while [[ $# -gt 0 ]]; do
46+
case $1 in
47+
-k | --kubeconfig)
48+
shift
49+
KUBECONFIG="$1"
50+
;;
51+
# -f | --from)
52+
# shift
53+
# FROM_VERSION="$1"
54+
# ;;
55+
# -t | --to)
56+
# shift
57+
# TO_VERSION="$1"
58+
# ;;
59+
-d | --debug)
60+
DEBUG="--debug"
61+
set -x
62+
;;
63+
-h | --help)
64+
usage
65+
exit 0
66+
;;
67+
*)
68+
echo "Unknown argument: $1"
69+
usage
70+
exit 1
71+
;;
72+
esac
73+
shift
74+
done
75+
DEBUG="${DEBUG:-}"
76+
}
77+
78+
init() {
79+
SCRIPT_DIR=$(
80+
cd "$(dirname "$0")" >/dev/null
81+
pwd
82+
)
83+
PROJECT_DIR=$(
84+
cd "$SCRIPT_DIR/../.." >/dev/null
85+
pwd
86+
)
87+
export KUBECONFIG
88+
}
89+
90+
run_for(){
91+
OPTS=""
92+
case "$1" in
93+
from)
94+
VERSION="$FROM_VERSION"
95+
;;
96+
to)
97+
VERSION="$TO_VERSION"
98+
OPTS="--use-current-branch"
99+
;;
100+
esac
101+
echo
102+
git checkout "$VERSION"
103+
echo "[Deploying $VERSION]"
104+
# shellcheck disable=SC2086
105+
"$PROJECT_DIR/developer/openshift/dev_setup.sh" $OPTS $DEBUG
106+
107+
echo
108+
echo "[Testing $VERSION]"
109+
# shellcheck disable=SC2086
110+
"$PROJECT_DIR/operator/test/test.sh" $DEBUG
111+
}
112+
113+
on_exit(){
114+
git checkout -f "$TO_VERSION"
115+
[ "$STASH" == "1" ] || git stash pop
116+
}
117+
118+
main() {
119+
parse_args "$@"
120+
init
121+
122+
trap on_exit EXIT
123+
124+
STASH="$(git stash | grep -c "No local changes to save" || true)"
125+
126+
run_for "from"
127+
run_for "to"
128+
run_for "from"
129+
}
130+
131+
if [ "${BASH_SOURCE[0]}" == "$0" ]; then
132+
main "$@"
133+
fi

0 commit comments

Comments
 (0)