diff --git a/.github/operator-upgrade/action.yaml b/.github/operator-upgrade/action.yaml new file mode 100644 index 00000000..97d90126 --- /dev/null +++ b/.github/operator-upgrade/action.yaml @@ -0,0 +1,26 @@ +name: Operator Upgrade Test +description: Runs operator upgrade scenario +runs: + using: composite + steps: + - name: Checkout source + uses: actions/checkout@v3 + + - uses: actions/setup-go@main + with: + go-version-file: go.mod + check-latest: true + cache: true + + - name: Install all tools + uses: ./.github/tools-cache + + - uses: ./.github/compute-version + id: version + + - name: Run Operator Upgrade + shell: bash + run: | + ./tests/run-e2e.sh --ci + env: + VERSION: ${{ steps.version.outputs.version }} diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index bb892dbd..6b61cb6f 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -125,8 +125,64 @@ jobs: version: ${{ steps.version.outputs.version }} additional_tags: ${{ steps.additional_tags.outputs.result }} - e2e: + operator-upgrade: needs: [docs, golangci, fmt, vulnerability_detect, escapes_detect] + env: + KIND_VERSION: "0.15.0" + GO111MODULE: "on" + OPERATOR_IMAGE: "quay.io/sustainable_computing_io/kepler-operator" + KUBECONFIG: /tmp/.kube/config + KIND_WORKER_NODES: 2 + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + go-version-file: go.mod + + - name: Install Go + uses: actions/setup-go@main + with: + go-version-file: go.mod + + - name: Install all tools + uses: ./.github/tools-cache + + - name: use kepler action for kind cluster build + uses: sustainable-computing-io/kepler-action@v0.0.5 + with: + ebpfprovider: libbpf + cluster_provider: kind + env: + PROMETHEUS_ENABLE: "false" + + - name: Ensure cluster is able to run OLM bundles + run: make cluster-prereqs + + - name: Run operator upgrade test + uses: ./.github/operator-upgrade + + - name: Capture cluster state + if: always() + shell: bash + run: | + # Capture apiserver state + # TODO: enable this when we have oc installed as part of `make tools` + # oc adm inspect node --dest-dir cluster-state || true + # oc adm inspect -A statefulset --dest-dir cluster-state || true + # oc adm inspect -A deployment --dest-dir cluster-state || true + # oc adm inspect -A ns --dest-dir cluster-state || true + cp -r tmp/e2e cluster-state/ || true + + - name: Archive production artifacts + if: always() + uses: actions/upload-artifact@v3 + with: + name: cluster-state + path: cluster-state + + e2e: + needs: [docs, golangci, fmt, vulnerability_detect, escapes_detect, operator-upgrade] env: KIND_VERSION: "0.15.0" GO111MODULE: "on" @@ -172,7 +228,7 @@ jobs: - name: Run e2e tests run: | - ./tests/run-e2e.sh --ci + ./tests/run-e2e.sh --ci --no-upgrade env: VERSION: ${{ steps.version.outputs.version }} diff --git a/tests/run-e2e.sh b/tests/run-e2e.sh index 1fa7bcab..f1caeaa9 100755 --- a/tests/run-e2e.sh +++ b/tests/run-e2e.sh @@ -34,162 +34,180 @@ declare TEST_TIMEOUT="15m" # declare -a PORT_FORWARDED_PIDS=() cleanup() { - info "Cleaning up ..." - # shell check ignore word splitting when using jobs -p - # shellcheck disable=SC2046 - [[ -z "$(jobs -p)" ]] || kill $(jobs -p) || true + info "Cleaning up ..." + # shell check ignore word splitting when using jobs -p + # shellcheck disable=SC2046 + [[ -z "$(jobs -p)" ]] || kill $(jobs -p) || true - return 0 + return 0 } delete_olm_subscription() { - header "Delete Old Deployments" - - $CI_MODE && { - ok "skipping deletion of old deployment in CI mode" - return 0 - } - - kubectl delete -n "$OPERATORS_NS" csv --all || true - kubectl delete -n "$OPERATORS_NS" installplan,subscriptions,catalogsource \ - -l operators.coreos.com/$OPERATOR.operators= || true - kubectl delete -n "$OPERATORS_NS" installplan,subscriptions,catalogsource \ - -l operators.coreos.com/$OPERATOR.openshift-operators= || true - kubectl delete -n "$OPERATORS_NS" catalogsource $OLM_CATALOG || true + header "Delete Old Deployments" + + $CI_MODE && { + ok "skipping deletion of old deployment in CI mode" + return 0 + } + + kubectl delete -n "$OPERATORS_NS" csv --all || true + kubectl delete -n "$OPERATORS_NS" installplan,subscriptions,catalogsource \ + -l operators.coreos.com/$OPERATOR.operators= || true + kubectl delete -n "$OPERATORS_NS" installplan,subscriptions,catalogsource \ + -l operators.coreos.com/$OPERATOR.openshift-operators= || true + kubectl delete -n "$OPERATORS_NS" catalogsource $OLM_CATALOG || true } build_bundle() { - header "Build Operator Bundle" + header "Build Operator Bundle" - $NO_BUILDS && { - info "skipping building of images" - return 0 - } + $NO_BUILDS && { + info "skipping building of images" + return 0 + } - run make operator-build bundle bundle-build \ - OPERATOR_IMG="$OPERATOR_IMG" \ - BUNDLE_IMG="$BUNDLE_IMG" \ - VERSION="$VERSION" + run make operator-build bundle bundle-build \ + OPERATOR_IMG="$OPERATOR_IMG" \ + BUNDLE_IMG="$BUNDLE_IMG" \ + VERSION="$VERSION" } push_bundle() { - header "Push Operator Bundle Images" - $NO_BUILDS && { - info "skipping pushing images" - return 0 - } + header "Push Operator Bundle Images" + $NO_BUILDS && { + info "skipping pushing images" + return 0 + } - run make operator-push bundle-push \ - OPERATOR_IMG="$OPERATOR_IMG" \ - BUNDLE_IMG="$BUNDLE_IMG" \ - VERSION="$VERSION" + run make operator-push bundle-push \ + OPERATOR_IMG="$OPERATOR_IMG" \ + BUNDLE_IMG="$BUNDLE_IMG" \ + VERSION="$VERSION" } gather_olm() { - header "Gather OLM resources" + header "Gather OLM resources" - for x in $(kubectl api-resources --api-group=operators.coreos.com -o name); do - run kubectl get "$x" -n "$OPERATORS_NS" -o yaml | tee "$LOGS_DIR/$x.yaml" - done + for x in $(kubectl api-resources --api-group=operators.coreos.com -o name); do + run kubectl get "$x" -n "$OPERATORS_NS" -o yaml | tee "$LOGS_DIR/$x.yaml" + done } run_bundle_upgrade() { - header "Running Bundle Upgrade" - local -i ret=0 - - local replaced_version="" - replaced_version=$(yq ".spec.replaces| sub(\"$OPERATOR.v\"; \"\")" "$OPERATOR_CSV") - - local released_bundle="$OPERATOR_RELEASED_BUNDLE:$replaced_version" - - info "Running Released Bundle - $replaced_version" - run operator-sdk run bundle "$released_bundle" \ - --install-mode AllNamespaces --namespace "$OPERATORS_NS" || { - ret=$? - line 50 heavy - gather_olm || true - fail "Running Released Bundle failed" - return $ret - } - - info "Running Upgrade to new bundle" - run operator-sdk run bundle-upgrade "$BUNDLE_IMG" \ - --namespace "$OPERATORS_NS" --use-http || { - ret=$? - line 50 heavy - gather_olm || true - fail "Running Bundle Upgrade failed" - return $ret - - } - return 0 + header "Running Bundle Upgrade" + prune_images_if_ci + kind_load_images + delete_olm_subscription || true + build_bundle + push_bundle + + local -i ret=0 + + local replaced_version="" + replaced_version=$(yq ".spec.replaces| sub(\"$OPERATOR.v\"; \"\")" "$OPERATOR_CSV") + + local released_bundle="$OPERATOR_RELEASED_BUNDLE:$replaced_version" + + info "Running Released Bundle - $replaced_version" + run operator-sdk run bundle "$released_bundle" \ + --install-mode AllNamespaces --namespace "$OPERATORS_NS" || { + ret=$? + line 50 heavy + gather_olm || true + fail "Running Released Bundle failed" + return $ret + } + + info "Creating a new Kepler CR" + run kubectl apply -f config/samples/kepler.system_v1alpha1_kepler.yaml + + info "Waiting for Kepler CR to be created" + wait_until 10 10 "kepler to be available" condition_check "True" oc get kepler kepler \ + -o jsonpath="{.status.exporter.conditions[?(@.type=='Available')].status}" || { + fail "Kepler is not ready" + return 1 + } + + ok "Kepler is ready" + + info "Running Upgrade to new bundle" + run operator-sdk run bundle-upgrade "$BUNDLE_IMG" \ + --namespace "$OPERATORS_NS" --use-http || { + ret=$? + line 50 heavy + gather_olm || true + fail "Running Bundle Upgrade failed" + return $ret + } + wait_for_operator "$OPERATORS_NS" + return $ret } run_bundle() { - header "Running Bundle" - local -i ret=0 - - run operator-sdk run bundle "$BUNDLE_IMG" \ - --namespace "$OPERATORS_NS" --use-http || { - ret=$? - line 50 heavy - gather_olm || true - fail "Running Bundle failed" - return $ret - - } - return 0 + header "Running Bundle" + local -i ret=0 + + run operator-sdk run bundle "$BUNDLE_IMG" \ + --namespace "$OPERATORS_NS" --use-http || { + ret=$? + line 50 heavy + gather_olm || true + fail "Running Bundle failed" + return $ret + + } + return 0 } log_events() { - local ns="$1" - shift - kubectl get events -w \ - -o custom-columns=FirstSeen:.firstTimestamp,LastSeen:.lastTimestamp,Count:.count,From:.source.component,Type:.type,Reason:.reason,Message:.message \ - -n "$ns" | tee "$LOGS_DIR/$ns-events.log" + local ns="$1" + shift + kubectl get events -w \ + -o custom-columns=FirstSeen:.firstTimestamp,LastSeen:.lastTimestamp,Count:.count,From:.source.component,Type:.type,Reason:.reason,Message:.message \ + -n "$ns" | tee "$LOGS_DIR/$ns-events.log" } watch_operator_errors() { - local err_log="$1" - shift + local err_log="$1" + shift - kubectl logs -f -n "$OPERATORS_NS" "deploy/$OPERATOR_DEPLOY_NAME" | - grep -i error | tee "$err_log" + kubectl logs -f -n "$OPERATORS_NS" "deploy/$OPERATOR_DEPLOY_NAME" | + grep -i error | tee "$err_log" } # run_e2e takes an optional set of args to be passed to go test run_e2e() { - header "Running e2e tests" - - local error_log="$LOGS_DIR/operator-errors.log" - - log_events "$OPERATORS_NS" & - log_events "kepler-operator" & - watch_operator_errors "$error_log" & - - local ret=0 - run go test -v -failfast -timeout $TEST_TIMEOUT \ - ./tests/e2e/... "$@" \ - 2>&1 | tee "$LOGS_DIR/e2e.log" || ret=1 - - # terminate both log_events - { jobs -p | xargs -I {} -- pkill -TERM -P {}; } || true - wait - sleep 1 # wait for the Termiated logs to be written - - if [[ "$ret" -ne 0 ]]; then - # logging of errors may not be immediate, so it is better to read logs again - # than dumping the $error_log file - sleep 2 - info "Operator Error Logs" - line 50 - kubectl logs -n "$OPERATORS_NS" "deploy/$OPERATOR_DEPLOY_NAME" | - grep -i error | tee "$error_log" - line 50 - fi - - return $ret + header "Running e2e tests" + + local error_log="$LOGS_DIR/operator-errors.log" + + log_events "$OPERATORS_NS" & + log_events "kepler-operator" & + watch_operator_errors "$error_log" & + + local ret=0 + run go test -v -failfast -timeout $TEST_TIMEOUT \ + ./tests/e2e/... "$@" \ + 2>&1 | tee "$LOGS_DIR/e2e.log" || ret=1 + + # terminate both log_events + { jobs -p | xargs -I {} -- pkill -TERM -P {}; } || true + wait + sleep 1 # wait for the Termiated logs to be written + + if [[ "$ret" -ne 0 ]]; then + # logging of errors may not be immediate, so it is better to read logs again + # than dumping the $error_log file + sleep 2 + info "Operator Error Logs" + line 50 + kubectl logs -n "$OPERATORS_NS" "deploy/$OPERATOR_DEPLOY_NAME" | + grep -i error | tee "$error_log" + line 50 + fi + + return $ret } # NOTE: ARGS_PARSED will be set by parse_args to the number of args @@ -197,61 +215,61 @@ run_e2e() { declare -i ARGS_PARSED=0 parse_args() { - ### while there are args parse them - while [[ -n "${1+xxx}" ]]; do - ARGS_PARSED+=1 - case $1 in - -h | --help) - SHOW_USAGE=true - break - ;; # exit the loop - --) break ;; - --no-deploy) - NO_DEPLOY=true - shift - ;; - --no-upgrade) - NO_UPGRADE=true - shift - ;; - --no-builds) - NO_BUILDS=true - shift - ;; - --ci) - CI_MODE=true - shift - ;; - --image-base) - shift - IMG_BASE="$1" - shift - ARGS_PARSED+=1 - ;; - --ns) - shift - OPERATORS_NS=$1 - shift - ARGS_PARSED+=1 - ;; - *) return 1 ;; # show usage on everything else - esac - done - - return 0 + ### while there are args parse them + while [[ -n "${1+xxx}" ]]; do + ARGS_PARSED+=1 + case $1 in + -h | --help) + SHOW_USAGE=true + break + ;; # exit the loop + --) break ;; + --no-deploy) + NO_DEPLOY=true + shift + ;; + --no-upgrade) + NO_UPGRADE=true + shift + ;; + --no-builds) + NO_BUILDS=true + shift + ;; + --ci) + CI_MODE=true + shift + ;; + --image-base) + shift + IMG_BASE="$1" + shift + ARGS_PARSED+=1 + ;; + --ns) + shift + OPERATORS_NS=$1 + shift + ARGS_PARSED+=1 + ;; + *) return 1 ;; # show usage on everything else + esac + done + + return 0 } init_operator_img() { - OPERATOR_IMG="$IMG_BASE/$OPERATOR:$VERSION" - BUNDLE_IMG="$IMG_BASE/$OPERATOR-bundle:$VERSION" - declare -r OPERATOR_IMG BUNDLE_IMG + OPERATOR_IMG="$IMG_BASE/$OPERATOR:$VERSION" + BUNDLE_IMG="$IMG_BASE/$OPERATOR-bundle:$VERSION" + declare -r OPERATOR_IMG BUNDLE_IMG } print_usage() { - local scr - scr="$(basename "$0")" + local scr + scr="$(basename "$0")" - read -r -d '' help <<-EOF_HELP || true + read -r -d '' help <<-EOF_HELP || true 🔆 Usage: $scr $scr [OPTIONS] -- [GO TEST ARGS] @@ -283,184 +301,179 @@ print_usage() { EOF_HELP - echo -e "$help" - return 0 + echo -e "$help" + return 0 } init_logs_dir() { - rm -rf "$LOGS_DIR-prev" - mv "$LOGS_DIR" "$LOGS_DIR-prev" || true - mkdir -p "$LOGS_DIR" + rm -rf "$LOGS_DIR-prev" + mv "$LOGS_DIR" "$LOGS_DIR-prev" || true + mkdir -p "$LOGS_DIR" } restart_operator() { - header "Restart Operator deployment" + header "Restart Operator deployment" - ensure_deploy_img_is_always_pulled || return 1 - local deployment="deployment/$OPERATOR_DEPLOY_NAME" + ensure_deploy_img_is_always_pulled || return 1 + local deployment="deployment/$OPERATOR_DEPLOY_NAME" - info "scale down Operator" - run kubectl scale -n "$OPERATORS_NS" --replicas=0 "$deployment" - run kubectl wait -n "$OPERATORS_NS" --for=delete \ - pods -l app.kubernetes.io/component=manager --timeout=60s + info "scale down Operator" + run kubectl scale -n "$OPERATORS_NS" --replicas=0 "$deployment" + run kubectl wait -n "$OPERATORS_NS" --for=delete \ + pods -l app.kubernetes.io/component=manager --timeout=60s - update_crds + update_crds - info "scale up" - kubectl scale -n "$OPERATORS_NS" --replicas=1 "$deployment" - wait_for_operator "$OPERATORS_NS" + info "scale up" + kubectl scale -n "$OPERATORS_NS" --replicas=1 "$deployment" + wait_for_operator "$OPERATORS_NS" - ok "Operator deployment restarted" + ok "Operator deployment restarted" } update_crds() { - # try replacing any installed crds; failure is often because the - # CRDs are absent and in that case, try creating and fail if that fails + # try replacing any installed crds; failure is often because the + # CRDs are absent and in that case, try creating and fail if that fails - run kubectl apply --server-side --force-conflicts -k config/crd - run kubectl wait --for=condition=Established crds --all --timeout=120s + run kubectl apply --server-side --force-conflicts -k config/crd + run kubectl wait --for=condition=Established crds --all --timeout=120s - return 0 + return 0 } kind_load_image() { - local img="$1" + local img="$1" - run docker pull "$img" - run kind load docker-image "$img" - $CI_MODE && run docker image rm "$img" - return 0 + run docker pull "$img" + run kind load docker-image "$img" + $CI_MODE && run docker image rm "$img" + return 0 } kind_load_images() { - header "Load Images" - while read -r img; do - kind_load_image "$img" - done < <(yq -r .spec.relatedImages[].image "$OPERATOR_CSV") - prune_images_if_ci - - info "loading additional images from $TEST_IMAGES_YAML" - while read -r img; do - kind_load_image "$img" - done < <(yq -r .images[].image "$TEST_IMAGES_YAML") - prune_images_if_ci - - return 0 + header "Load Images" + while read -r img; do + kind_load_image "$img" + done < <(yq -r .spec.relatedImages[].image "$OPERATOR_CSV") + prune_images_if_ci + + info "loading additional images from $TEST_IMAGES_YAML" + while read -r img; do + kind_load_image "$img" + done < <(yq -r .images[].image "$TEST_IMAGES_YAML") + prune_images_if_ci + + return 0 } prune_images_if_ci() { - header "Prune Images" - $CI_MODE || { - info "skipping pruning of docker images when not in CI mode" - return 0 - } - # NOTE: ci runs out of disk space at times, hence run images - info "pruning docker images and volumes" - run df -h - run docker images - run docker system prune -a -f --volumes - run df -h + header "Prune Images" + $CI_MODE || { + info "skipping pruning of docker images when not in CI mode" + return 0 + } + # NOTE: ci runs out of disk space at times, hence run images + info "pruning docker images and volumes" + run df -h + run docker images + run docker system prune -a -f --volumes + run df -h } deploy_operator() { - header "Build and Deploy Operator" - prune_images_if_ci - ensure_imgpullpolicy_always_in_yaml - kind_load_images - delete_olm_subscription || true - build_bundle - push_bundle - - if $NO_UPGRADE; then - run_bundle - else - run_bundle_upgrade - fi - wait_for_operator "$OPERATORS_NS" - prune_images_if_ci + header "Build and Deploy Operator" + prune_images_if_ci + ensure_imgpullpolicy_always_in_yaml + kind_load_images + delete_olm_subscription || true + build_bundle + push_bundle + run_bundle + wait_for_operator "$OPERATORS_NS" + prune_images_if_ci } ensure_imgpullpolicy_always_in_yaml() { - $CI_MODE && { - ok "skipping check of imagePullPolicy in deployment yaml" - return 0 - } - - local pull_policy - pull_policy=$(grep '\s\+imagePullPolicy:' "$OPERATOR_DEPLOY_YAML" | tr -d ' ' | cut -f2 -d:) - - [[ "$pull_policy" != "Always" ]] && { - info "Modify $OPERATOR_DEPLOY_YAML imagePullPolicy -> Always" - info " ❯ sed -e 's|imagePullPolicy: .*|imagePullPolicy: Always|g' -i $OPERATOR_DEPLOY_YAML" - warn "Deployment's imagePullPolicy must be Always instead of $pull_policy" - return 1 - } - - ok "Operator deployment yaml imagePullPolicy is Always" + $CI_MODE && { + ok "skipping check of imagePullPolicy in deployment yaml" + return 0 + } + + local pull_policy + pull_policy=$(grep '\s\+imagePullPolicy:' "$OPERATOR_DEPLOY_YAML" | tr -d ' ' | cut -f2 -d:) + + [[ "$pull_policy" != "Always" ]] && { + info "Modify $OPERATOR_DEPLOY_YAML imagePullPolicy -> Always" + info " ❯ sed -e 's|imagePullPolicy: .*|imagePullPolicy: Always|g' -i $OPERATOR_DEPLOY_YAML" + warn "Deployment's imagePullPolicy must be Always instead of $pull_policy" + return 1 + } + + ok "Operator deployment yaml imagePullPolicy is Always" } ensure_deploy_img_is_always_pulled() { - $CI_MODE && { - ok "skipping check of imagePullPolicy of Operator deployment" - return 0 - } - - local pull_policy - pull_policy=$(kubectl get deploy/$OPERATOR_DEPLOY_NAME \ - -n "$OPERATORS_NS" \ - -ojsonpath='{.spec.template.spec.containers[0].imagePullPolicy}') - - if [[ "$pull_policy" != "Always" ]]; then - info "Edit $OPERATOR_DEPLOY_YAML imagePullPolicy and redeploy" - info " ❯ sed -e 's|imagePullPolicy: .*|imagePullPolicy: Always|g' -i $OPERATOR_DEPLOY_YAML" - warn "Deployment's imagePullPolicy must be Always instead of $pull_policy" - return 1 - fi - ok "Operator deployment imagePullPolicy is Always" + $CI_MODE && { + ok "skipping check of imagePullPolicy of Operator deployment" + return 0 + } + + local pull_policy + pull_policy=$(kubectl get deploy/$OPERATOR_DEPLOY_NAME \ + -n "$OPERATORS_NS" \ + -ojsonpath='{.spec.template.spec.containers[0].imagePullPolicy}') + + if [[ "$pull_policy" != "Always" ]]; then + info "Edit $OPERATOR_DEPLOY_YAML imagePullPolicy and redeploy" + info " ❯ sed -e 's|imagePullPolicy: .*|imagePullPolicy: Always|g' -i $OPERATOR_DEPLOY_YAML" + warn "Deployment's imagePullPolicy must be Always instead of $pull_policy" + return 1 + fi + ok "Operator deployment imagePullPolicy is Always" } reject_invalid() { - local invalid_kepler='invalid-pre-test-kepler' + local invalid_kepler='invalid-pre-test-kepler' - # ensure that applying an invalid kepler will be rejected by the webhook - { - # NOTE: || true ignores pipefail so that non-zero exit code will not be reported - # when kubectl apply fails (as expected) - sed -e "s|name: kepler$|name: $invalid_kepler|g" \ - config/samples/kepler.system_v1alpha1_kepler.yaml | - kubectl apply -f- 2>&1 || true + # ensure that applying an invalid kepler will be rejected by the webhook + { + # NOTE: || true ignores pipefail so that non-zero exit code will not be reported + # when kubectl apply fails (as expected) + sed -e "s|name: kepler$|name: $invalid_kepler|g" \ + config/samples/kepler.system_v1alpha1_kepler.yaml | + kubectl apply -f- 2>&1 || true - } | tee /dev/stderr | - grep -q "BadRequest.* admission webhook .* denied the request" && return 0 + } | tee /dev/stderr | + grep -q "BadRequest.* admission webhook .* denied the request" && return 0 - kubectl delete kepler "$invalid_kepler" || true - return 1 + kubectl delete kepler "$invalid_kepler" || true + return 1 } # wait_for_operator requires the namespace where the operator is installed wait_for_operator() { - header "Waiting for Kepler Operator ($OPERATORS_NS) to be Ready" - local deployment="deploy/$OPERATOR_DEPLOY_NAME" + header "Waiting for Kepler Operator ($OPERATORS_NS) to be Ready" + local deployment="deploy/$OPERATOR_DEPLOY_NAME" - wait_until 30 10 "operator to run" \ - kubectl -n "$OPERATORS_NS" rollout status "$deployment" + wait_until 30 10 "operator to run" \ + kubectl -n "$OPERATORS_NS" rollout status "$deployment" - run kubectl wait -n "$OPERATORS_NS" --for=condition=Available \ - --timeout=300s "$deployment" + run kubectl wait -n "$OPERATORS_NS" --for=condition=Available \ + --timeout=300s "$deployment" - # NOTE: ensure that operator is actually ready by creating an invalid kepler - # and wait until the operator is able to reconcile - info "Ensure that webhooks are installed and working" + # NOTE: ensure that operator is actually ready by creating an invalid kepler + # and wait until the operator is able to reconcile + info "Ensure that webhooks are installed and working" - wait_until 30 10 "webhooks to be ready" reject_invalid + wait_until 30 10 "webhooks to be ready" reject_invalid - ok "Operator up and running" + ok "Operator up and running" } print_config() { - header "Test Configuration" - cat <<-EOF + header "Test Configuration" + cat <<-EOF image base: $IMG_BASE operator image: $OPERATOR_IMG bundle: $BUNDLE_IMG @@ -472,38 +485,46 @@ print_config() { Logs directory: $LOGS_DIR EOF - line 50 + line 50 +} + +deploy_and_run_e2e() { + if $NO_DEPLOY; then + restart_operator || die "restarting operator failed 🤕" + else + deploy_operator + fi + + local -i ret=0 + run_e2e "$@" || ret=$? + + info "e2e test - exit code: $ret" + line 50 heavy + return $ret } main() { - export PATH="$LOCAL_BIN:$PATH" - parse_args "$@" || die "parse args failed" - # eat up all the parsed args so that the rest can be passed to go test - shift $ARGS_PARSED - $SHOW_USAGE && { - print_usage - exit 0 - } - - cd "$PROJECT_ROOT" - - init_operator_img - init_logs_dir - print_config - - if $NO_DEPLOY; then - restart_operator || die "restarting operator failed 🤕" - else - deploy_operator - fi - - local -i ret=0 - run_e2e "$@" || ret=$? - - info "e2e test - exit code: $ret" - line 50 heavy - - return $ret + export PATH="$LOCAL_BIN:$PATH" + parse_args "$@" || die "parse args failed" + # eat up all the parsed args so that the rest can be passed to go test + shift $ARGS_PARSED + $SHOW_USAGE && { + print_usage + exit 0 + } + + cd "$PROJECT_ROOT" + + init_operator_img + init_logs_dir + print_config + + if $NO_UPGRADE; then + deploy_and_run_e2e "$@" || return 1 + else + run_bundle_upgrade || return 1 + fi + return 0 } main "$@"