Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
jgwest committed Dec 5, 2024
1 parent 0a7bdac commit c945ed5
Show file tree
Hide file tree
Showing 3 changed files with 186 additions and 24 deletions.
8 changes: 8 additions & 0 deletions scripts/openshiftci-presubmit-all-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ set -e
# Do not show token in CI log
set +x

# Get path containing the current script, usually (repo path)/scripts
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )


# show commands
set -x
export CI="prow"
Expand All @@ -24,3 +28,7 @@ export KUBECONFIG=$TMP_DIR/kubeconfig
# Run e2e test
make test-e2e

# Run Rollouts E2E tests
cd "$SCRIPT_DIR"

# "$SCRIPT_DIR/run-rollouts-e2e-tests.sh"
52 changes: 32 additions & 20 deletions scripts/run-kuttl-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,36 @@ trap unexpectedError INT
mkdir -p $WORK_DIR/results || exit 1
mkdir -p $DIR/results || exit 1

case "$testsuite" in
"parallel")
header "Running $testsuite tests"
run_parallel $2
;;
"sequential")
header "Running $testsuite tests"
run_sequential $2
;;
"all")
header "Running $testsuite tests"
run_parallel
run_sequential
;;
*)
echo "USAGE: $0 (parallel|sequential|all)" >&2
exit 1
esac
# Get path containing the current script, usually (repo path)/scripts
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

# Run Rollouts E2E tests
cd "$SCRIPT_DIR"

"$SCRIPT_DIR/run-rollouts-e2e-tests.sh"





# case "$testsuite" in
# "parallel")
# header "Running $testsuite tests"
# run_parallel $2
# ;;
# "sequential")
# header "Running $testsuite tests"
# run_sequential $2
# ;;
# "all")
# header "Running $testsuite tests"
# run_parallel
# run_sequential
# ;;
# *)
# echo "USAGE: $0 (parallel|sequential|all)" >&2
# exit 1
# esac

(( failed )) && fail_test "$testsuite tests failed"
success $testsuite
# (( failed )) && fail_test "$testsuite tests failed"
# success $testsuite
150 changes: 146 additions & 4 deletions scripts/run-rollouts-e2e-tests.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,156 @@
#!/bin/bash

# The goal of this script is to run the Argo Rollouts operator tests from the argo-rollouts-manager repo against gitops-operator:
# - Runs the (cluster-scoped) E2E tests of the Argo Rollouts operator
# - Runs the cluster-scoped/namespace-scoped E2E tests of the Argo Rollouts operator
# - Runs the upstream E2E tests from the argo-rollouts repo

set -ex

function wait_until_pods_running() {
echo -n "Waiting until all pods in namespace $1 are up"

# Wait for there to be only a single Pod line in 'oc get pods' (there should be no more 'terminating' pods, etc)
timeout="true"
for i in {1..30}; do
local num_pods="$(oc get pods --no-headers -n $1 | wc -l 2>/dev/null)"

# Check the number of lines
if [[ "$num_lines" == "1" ]]; then
echo "Waiting for a single Pod entry in Namespace '$1': $num_pods"
sleep 5
else
timeout="false"
break
fi
done
if [ "$timeout" == "true" ]; then
echo -e "\n\nERROR: timeout waiting for expected number of pods"
return 1
fi

for i in {1..150}; do # timeout after 5 minutes
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
# write it to tempfile
TempFile=$(mktemp)
oc get pods --no-headers -n $1 2>/dev/null >$TempFile

# All pods must be running
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
local all_ready=1
while read pod; do
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
# All containers must be ready
[[ -z ${status[0]} ]] && all_ready=0 && break
[[ -z ${status[1]} ]] && all_ready=0 && break
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
done <${TempFile}
if ((all_ready)); then
echo -e "\nAll pods are up:\n${pods}"
return 0
fi
fi
echo -n "."
sleep 2
done
echo -e "\n\nERROR: timeout waiting for pods to come up\n${pods}"
return 1
}

function enable_rollouts_cluster_scoped_namespaces() {

# This functions add this env var to operator:
# - CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES="argo-rollouts,test-rom-ns-1,rom-ns-1"

if ! [ -z $NON_OLM ]; then
oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES="argo-rollouts,test-rom-ns-1,rom-ns-1"

elif [ -z $CI ]; then

oc patch -n openshift-gitops-operator subscription openshift-gitops-operator \
--type merge --patch '{"spec": {"config": {"env": [{"name": "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES", "value": "argo-rollouts,test-rom-ns-1,rom-ns-1"}]}}}'

else

oc patch -n openshift-gitops-operator subscription `subscription=gitops-operator- && oc get subscription --all-namespaces | grep $subscription | head -1 | awk '{print $2}'` \
--type merge --patch '{"spec": {"config": {"env": [{"name": "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES", "value": "argo-rollouts,test-rom-ns-1,rom-ns-1"}]}}}'
fi

# Loop to wait until CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES is added to the OpenShift GitOps Operator Deployment
for i in {1..30}; do
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES to be set"
break
else
echo "Waiting for CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES to be set"
sleep 5
fi
done

# Verify the variable is set
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES is set."
else
echo "ERROR: CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES was never set."
exit 1
fi

# Deployment is correct, now wait for Pods to start
wait_until_pods_running "openshift-gitops-operator"

}

function disable_rollouts_cluster_scope_namespaces() {

# Remove the env var we previously added to operator

if ! [ -z $NON_OLM ]; then

oc set env deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES=null

elif [ -z $CI ]; then

oc patch -n openshift-gitops-operator subscription openshift-gitops-operator \
--type json --patch '[{"op": "remove", "path": "/spec/config"}]'
else

oc patch -n openshift-gitops-operator subscription `subscription=gitops-operator- && oc get subscription --all-namespaces | grep $subscription | head -1 | awk '{print $2}'` \
--type json --patch '[{"op": "remove", "path": "/spec/config"}]'
fi


# Loop to wait until CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES is removed from the OpenShift GitOps Operator Deplyoment
for i in {1..30}; do
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "Waiting for CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES to be removed"
sleep 5
else
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES has been removed."
break
fi
done

# Verify it has been removed.
if oc get deployment openshift-gitops-operator-controller-manager -n openshift-gitops-operator -o jsonpath='{.spec.template.spec.containers[0].env}' | grep -q '{"name":"CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES","value":"argo-rollouts,test-rom-ns-1,rom-ns-1"}'; then
echo "ERROR: CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES was not successfully removed."
exit 1
else
echo "CLUSTER_SCOPED_ARGO_ROLLOUTS_NAMESPACES was successfuly removed."
fi

# Wait for Pods to reflect the removal of the env var
wait_until_pods_running "openshift-gitops-operator"
}


enable_rollouts_cluster_scoped_namespaces

trap disable_rollouts_cluster_scope_namespaces EXIT



ROLLOUTS_TMP_DIR=$(mktemp -d)

cd $ROLLOUTS_TMP_DIR
Expand Down Expand Up @@ -68,6 +213,3 @@ git checkout $TARGET_OPENSHIFT_ROUTE_ROLLOUT_PLUGIN_COMMIT

make test-e2e




0 comments on commit c945ed5

Please sign in to comment.