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

[patch] Only register the start on the first sync in devopsdb #204

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,15 @@ spec:
if [[ -z $CONFIGMAP ]]; then
echo "Creating $SYNC_TIME_CM_NAME configmap"
oc create configmap $SYNC_TIME_CM_NAME --from-literal=sync_start=$(date +%s)
echo "Run register-start.py"
python3 /opt/app-root/src/register-start.py
fi
export SYNC_COMPLETE=$((oc get configmap $SYNC_TIME_CM_NAME -o json) | yq '.data.sync_complete')
if [[ -z "${SYNC_COMPLETE}" || "${SYNC_COMPLETE}" == "null" ]]; then
echo "Sync not complete yet."
else
echo "Sync called again but was already marked as completed once."
fi

echo "Run register-start.py"
python3 /opt/app-root/src/register-start.py


restartPolicy: Never
serviceAccountName: {{ $sa_name }}
Expand Down
34 changes: 23 additions & 11 deletions sub-charts/junitreporter/templates/10-postsync-report-starter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ metadata:
{{- end }}
rules:
- verbs:
- delete
- patch
- get
apiGroups:
- ""
resources:
Expand Down Expand Up @@ -151,6 +152,12 @@ spec:
configMapKeyRef:
name: {{ $time_cm }}
key: sync_start
- name: SYNC_COMPLETE
valueFrom:
configMapKeyRef:
name: {{ $time_cm }}
key: sync_complete
optional: true
- name: SYNC_TIME_CM_NAME
value: {{ $time_cm }}
volumeMounts:
Expand All @@ -165,19 +172,24 @@ spec:
trap 'echo "[ERROR] Error occurred at line $LINENO, exited with $?"; exit 1' ERR

export DEVOPS_MONGO_URI=$(cat /etc/mas/devops-uri/devops_mongo_uri)
# Compute elapsed time between pre-sync and post-sync
CURRENTTIME=$(date +%s)
ELAPSEDTIME=$(($CURRENTTIME-$SYNC_START))
echo "Elapsed time is ${ELAPSEDTIME}"

# Create junit xml for one testsuite of the parent argo app, and the testcase of sync
python3 /opt/app-root/src/junit-xml-generator.py --test-suite-name ${DEVOPS_SUITE_NAME} --test-cases Sync:$ELAPSEDTIME --output-dir ${JUNIT_OUTPUT_DIR}
if [[ -z "${SYNC_COMPLETE}" ]]; then
# Compute elapsed time between pre-sync and post-sync
CURRENTTIME=$(date +%s)
ELAPSEDTIME=$(($CURRENTTIME-$SYNC_START))
echo "Elapsed time is ${ELAPSEDTIME}"

# Create junit xml for one testsuite of the parent argo app, and the testcase of sync
python3 /opt/app-root/src/junit-xml-generator.py --test-suite-name ${DEVOPS_SUITE_NAME} --test-cases Sync:$ELAPSEDTIME --output-dir ${JUNIT_OUTPUT_DIR}

echo "Run save-junit-to-mongo.py"
python3 /opt/app-root/src/save-junit-to-mongo.py
echo "Run save-junit-to-mongo.py"
python3 /opt/app-root/src/save-junit-to-mongo.py

echo "Delete $SYNC_TIME_CM_NAME configmap"
oc delete configmap $SYNC_TIME_CM_NAME -n $NAMESPACE
echo "Patching $SYNC_TIME_CM_NAME configmap with sync_complete"
oc patch configmap $SYNC_TIME_CM_NAME -p '{"data":{"sync_start":"'$SYNC_START'","sync_complete":"'$CURRENTTIME'"}}'
else
echo "SYNC_COMPLETE already set in configmap $SYNC_TIME_CM_NAME, so nothing to do."
fi

restartPolicy: Never
serviceAccountName: {{ $sa_name }}
Expand Down
Loading