-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): initialize scripts to run e2e tests on ocp
- Loading branch information
1 parent
853f04f
commit 5904298
Showing
3 changed files
with
472 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
header() { | ||
local title="🔆🔆🔆 $* 🔆🔆🔆 " | ||
|
||
local len=40 | ||
if [[ ${#title} -gt $len ]]; then | ||
len=${#title} | ||
fi | ||
|
||
echo -e "\n\n \033[1m${title}\033[0m" | ||
echo -n "━━━━━" | ||
printf '━%.0s' $(seq "$len") | ||
echo "━━━━━━━" | ||
|
||
} | ||
|
||
info() { | ||
echo " 🔔 $*" | ||
} | ||
|
||
ok() { | ||
echo " ✅ $*" | ||
} | ||
|
||
warn() { | ||
echo " ⚠️ $*" | ||
} | ||
|
||
skip() { | ||
echo " 🙈 SKIP: $*" | ||
} | ||
|
||
die() { | ||
echo -e "\n ✋ $* " | ||
echo -e "──────────────────── ⛔️⛔️⛔️ ────────────────────────\n" | ||
exit 1 | ||
} | ||
|
||
line() { | ||
local len="$1" | ||
shift | ||
|
||
echo -n "────" | ||
printf '─%.0s' $(seq "$len") | ||
echo "────────" | ||
} | ||
|
||
# wait_for_operators_ready requires the namespace where the operator is installed | ||
wait_for_operators_ready() { | ||
local ns="$1" | ||
shift | ||
|
||
header "Wait for ObO to be Ready" | ||
|
||
local tries=30 | ||
while [[ $tries -gt 0 ]] && | ||
! kubectl -n "$ns" rollout status deploy/obo-prometheus-operator; do | ||
sleep 10 | ||
((tries--)) | ||
done | ||
|
||
kubectl wait -n "$ns" --for=condition=Available deploy/obo-prometheus-operator --timeout=300s | ||
kubectl wait -n "$ns" --for=condition=Available deploy/obo-prometheus-operator-admission-webhook --timeout=300s | ||
kubectl wait -n "$ns" --for=condition=Available deploy/observability-operator --timeout=300s | ||
|
||
ok "Obo up and running" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/usr/bin/env bash | ||
set -e -u -o pipefail | ||
|
||
trap cleanup INT | ||
|
||
# NOTE: install ObO and run e2e against the installation | ||
|
||
PROJECT_ROOT="$(git rev-parse --show-toplevel)" | ||
declare -r PROJECT_ROOT | ||
|
||
# shellcheck source=/dev/null | ||
source "$PROJECT_ROOT/test/lib/utils.bash" | ||
|
||
# NOTE: openshift-operators is the namespace used in subscription.yaml to install | ||
# obo, so this is harded coded for the test as well. | ||
declare -r OPERATORS_NS="openshift-operators" | ||
|
||
### Configuration | ||
declare NO_INSTALL=false | ||
declare NO_UNINSTALL=false | ||
declare SHOW_USAGE=false | ||
|
||
cleanup() { | ||
# NOTE: clears trap INT | ||
trap - INT | ||
|
||
# skip cleanup if user requested help | ||
$SHOW_USAGE && return 0 | ||
delete_obo | ||
} | ||
|
||
install_obo() { | ||
header "Install ObO" | ||
|
||
$NO_INSTALL && { | ||
skip "installation of obo " | ||
return 0 | ||
} | ||
|
||
# NOTE: catalog-src is added to "openshift-marketplace" namespace | ||
oc apply -f ./hack/olm/catalog-src.yaml | ||
|
||
# NOTE: obo gets installed to "openshift-operators" namespace | ||
oc apply -f ./hack/olm/subscription.yaml | ||
|
||
oc -n "$OPERATORS_NS" wait --for=condition=CatalogSourcesUnhealthy=False \ | ||
subscription.operators.coreos.com observability-operator | ||
|
||
ok "ObO subscription is ready" | ||
} | ||
|
||
delete_obo() { | ||
header "Deleting ObO subscription" | ||
|
||
$NO_UNINSTALL && { | ||
skip "uninstallation of obo" | ||
return 0 | ||
} | ||
|
||
oc delete -n "$OPERATORS_NS" csv \ | ||
-l operators.coreos.com/observability-operator."$OPERATORS_NS"= || true | ||
|
||
oc delete -n "$OPERATORS_NS" installplan,subscriptions \ | ||
-l operators.coreos.com/observability-operator."$OPERATORS_NS"= || true | ||
|
||
oc delete -f hack/olm/subscription.yaml || true | ||
oc delete -f hack/olm/catalog-src.yaml || true | ||
ok "uninstalled ObO" | ||
} | ||
|
||
parse_args() { | ||
### while there are args parse them | ||
while [[ -n "${1+xxx}" ]]; do | ||
case $1 in | ||
-h | --help) | ||
SHOW_USAGE=true | ||
break | ||
;; # exit the loop | ||
--no-install) | ||
NO_INSTALL=true | ||
shift | ||
;; | ||
--no-uninstall) | ||
NO_UNINSTALL=true | ||
shift | ||
;; | ||
*) return 1 ;; # show usage on everything else | ||
esac | ||
done | ||
return 0 | ||
} | ||
|
||
print_usage() { | ||
local scr | ||
scr="$(basename "$0")" | ||
|
||
read -r -d '' help <<-EOF_HELP || true | ||
Usage: | ||
$scr | ||
$scr --no-install | ||
$scr --no-uninstall | ||
$scr -h|--help | ||
Options: | ||
-h|--help show this help | ||
--no-install do not install OBO, useful for rerunning tests | ||
--no-uninstall do not uninstall OBO after test | ||
EOF_HELP | ||
|
||
echo -e "$help" | ||
return 0 | ||
} | ||
|
||
main() { | ||
parse_args "$@" || die "parse args failed" | ||
$SHOW_USAGE && { | ||
print_usage | ||
exit 0 | ||
} | ||
|
||
cd "$PROJECT_ROOT" | ||
install_obo | ||
wait_for_operators_ready "$OPERATORS_NS" | ||
|
||
local -i ret=0 | ||
./test/run-e2e.sh --no-deploy --ns "$OPERATORS_NS" || ret=1 | ||
delete_obo | ||
|
||
return $ret | ||
} | ||
|
||
main "$@" |
Oops, something went wrong.