Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use certsuite executable from image everywhere in the batch operators test script #2574

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 63 additions & 12 deletions script/run-basic-batch-operators-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ wait_delete_namespace() {
with_retry() {
local \
max_retries=$1 \
timeout=$2 \
interval_sec=$2 \
retries=0 \
status=0 \
stderr='' \
Expand Down Expand Up @@ -171,7 +171,7 @@ with_retry() {
} >>"$LOG_FILE_PATH"

echo_color "$GREY" "Retry $retries/$max_retries: Waiting for a few seconds before the next attempt..."
sleep "$timeout"
sleep "$interval_sec"
done
echo_color "$GREY" "Maximum retries reached."
return 1
Expand Down Expand Up @@ -329,6 +329,14 @@ force_delete_namespace_if_present() {
return 0
fi

# If a namespace with this name does not exist, all is good, exit
if ! oc get namespace "$a_namespace"; then
return 0
fi

# Remove finalizers
remove_all_finalizers "$a_namespace" "namespace" "" || true

# Delete namespace
oc delete namespace "$a_namespace" --wait=false || true
with_retry 2 0 oc wait namespace "$a_namespace" --for=delete --timeout=5s || true
Expand Down Expand Up @@ -427,6 +435,36 @@ wait_pods_ok() {
done
}

remove_all_finalizers() {
local resource_name=$1
local resource_type=$2
local namespace=$3

echo "Removing finalizers from $resource_type/$resource_name..."

if [ "$resource_type" == "namespace" ]; then
# For namespaces, do not use the namespace argument
if oc get "$resource_type" "$resource_name" -o json |
jq 'del(.metadata.finalizers)' |
oc apply -f -; then
echo "Successfully removed finalizers from $resource_type/$resource_name."
else
echo "Failed to remove finalizers from $resource_type/$resource_name."
return 1
fi
else
# For other resource types, include the namespace argument
if oc get "$resource_type" "$resource_name" -n "$namespace" -o json |
jq 'del(.metadata.finalizers)' |
oc apply -f -; then
echo "Successfully removed finalizers from $resource_type/$resource_name."
else
echo "Failed to remove finalizers from $resource_type/$resource_name."
return 1
fi
fi
}

# Main

# Writing CatalogSource template
Expand Down Expand Up @@ -611,7 +649,24 @@ while IFS=, read -r package_name catalog_index; do
oc get pods -n "$ns" -o custom-columns=':.metadata.name,:.metadata.namespace,:.kind' | sed '/^ *$/d' | awk '{print " oc label " $3 " -n " $2 " " $1 " redhat-best-practices-for-k8s.com/generic=target "}' | bash || true
} >>"$LOG_FILE_PATH" 2>&1

# run certsuite container
# Get latest certsuite container image
echo_color "$BLUE" "Get latest certsuite executable from image: ${CERTSUITE_IMAGE_NAME}:${CERTSUITE_IMAGE_TAG}"
{
podman pull "${CERTSUITE_IMAGE_NAME}:${CERTSUITE_IMAGE_TAG}" || true
podman run --replace -d --name temp-container "${CERTSUITE_IMAGE_NAME}:${CERTSUITE_IMAGE_TAG}" || true
# sleep for a while to allow the container to come up and exit
sleep 2
podman cp temp-container:/usr/certsuite/certsuite . || true
podman rm -f temp-container || true
} >>"$LOG_FILE_PATH" 2>&1

if [ ! -f "./certsuite" ]; then
echo_color "$RED" "Could not download latest certsuite executable, continue"
report_failure "$status" "$ns" "$package_name" "Could not download latest certsuite, skipping test"
continue
fi

# Run certsuite container
echo_color "$BLUE" "run CNF suite"

config_dir="$(pwd)"/config
Expand All @@ -620,15 +675,11 @@ while IFS=, read -r package_name catalog_index; do
cp "$DOCKER_CONFIG" "$config_dir"/dockerconfig
cp "$config_yaml" "$config_dir"/certsuite_config.yaml

docker run --rm --network host \
-v "$config_dir":/usr/tnf/config:Z \
-v "$report_dir":/usr/tnf/output:Z \
${CERTSUITE_IMAGE_NAME}:${CERTSUITE_IMAGE_TAG} \
certsuite run \
--kubeconfig=/usr/tnf/config/kubeconfig \
--preflight-dockerconfig=/usr/tnf/config/dockerconfig \
--config-file=/usr/tnf/config/certsuite_config.yaml \
--output-dir=/usr/tnf/output \
./certsuite run \
--kubeconfig="$config_dir"/kubeconfig \
--preflight-dockerconfig="$config_dir"/dockerconfig \
--config-file="$config_dir"/certsuite_config.yaml \
--output-dir="$report_dir" \
--label-filter=all >>"$LOG_FILE_PATH" 2>&1 || {
report_failure "$status" "$ns" "$package_name" "CNF suite exited with errors"
continue
Expand Down
Loading