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

Collect coverage #40

Merged
merged 2 commits into from
Sep 26, 2023
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ TODO
| autoscaling.maxReplicas | int | `100` | |
| autoscaling.minReplicas | int | `1` | |
| autoscaling.targetCPUUtilizationPercentage | int | `80` | |
| developer.enableCoverage | bool | `false` | |
| developer.enabled | bool | `true` | |
| developer.modulesToInstall | list | `[]` | |
| developer.sourcePath | string | `"/diracx_source"` | |
Expand Down
99 changes: 27 additions & 72 deletions diracx/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ spec:
- name: signing-key-mount
emptyDir:
sizeLimit: 5Mi
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
- name: coverage-data
persistentVolumeClaim:
claimName: pvc-coverage
{{- end }}

{{/* Define common volume mounts for reusability */}}
{{- $commonVolumeMounts := list }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/cs_store" "name" "cs-store-mount" "readOnly" false) }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/signing-key" "name" "signing-key-mount" "readOnly" false) }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/entrypoint.sh" "name" "container-entrypoint" "subPath" "entrypoint.sh") }}
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/diracx-coveragerc" "name" "container-entrypoint" "subPath" "coveragerc") }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" "/coverage-reports" "name" "coverage-data" "readOnly" false) }}
{{- end }}
{{- if and .Values.developer.enabled .Values.developer.modulesToInstall }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" .Values.developer.sourcePath "name" "diracx-code-mount" "readOnly" true) }}
{{- range $module := .Values.developer.modulesToInstall }}
{{- $commonVolumeMounts = append $commonVolumeMounts (dict "mountPath" (printf "%s/%s/src/%s.egg-info" $.Values.developer.sourcePath $module $module) "name" (printf "%s-editable-install" (lower $module)) "readOnly" false) }}
{{- end }}
{{- end }}

initContainers:
- name: init-cs
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
Expand All @@ -69,23 +91,7 @@ spec:
{{- with (first .Values.dex.config.staticClients) }}
- "--idp-client-id={{ .id }}"
{{- end }}
volumeMounts:
- mountPath: /cs_store
name: cs-store-mount
readOnly: false
{{- if and .Values.developer.enabled .Values.developer.modulesToInstall }}
- mountPath: {{ .Values.developer.sourcePath }}
name: diracx-code-mount
readOnly: true
{{- range $module := .Values.developer.modulesToInstall }}
- mountPath: "{{ $.Values.developer.sourcePath }}/{{ $module }}/src/{{ $module }}.egg-info"
name: {{ lower $module }}-editable-install
readOnly: false
{{- end }}
{{- end }}
- name: container-entrypoint
mountPath: /entrypoint.sh
subPath: entrypoint.sh
volumeMounts: {{ toYaml $commonVolumeMounts | nindent 10 }}
- name: init-cs-user
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
command: ["bash", "/entrypoint.sh"]
Expand All @@ -97,23 +103,7 @@ spec:
- "--vo=diracAdmin"
- "--user-group=admin"
- "--sub=EgVsb2NhbA"
volumeMounts:
- mountPath: /cs_store
name: cs-store-mount
readOnly: false
{{- if and .Values.developer.enabled .Values.developer.modulesToInstall }}
- mountPath: {{ .Values.developer.sourcePath }}
name: diracx-code-mount
readOnly: true
{{- range $module := .Values.developer.modulesToInstall }}
- mountPath: "{{ $.Values.developer.sourcePath }}/{{ $module }}/src/{{ $module }}.egg-info"
name: {{ lower $module }}-editable-install
readOnly: false
{{- end }}
{{- end }}
- name: container-entrypoint
mountPath: /entrypoint.sh
subPath: entrypoint.sh
volumeMounts: {{ toYaml $commonVolumeMounts | nindent 10 }}
- name: init-signing-key
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
command: [/dockerMicroMambaEntrypoint.sh]
Expand All @@ -125,29 +115,13 @@ spec:
- "-b4096"
- "-mPEM"
- "-f/signing-key/rs256.key"
volumeMounts:
- mountPath: /signing-key/
name: signing-key-mount
readOnly: false
volumeMounts: {{ toYaml $commonVolumeMounts | nindent 10 }}
{{- if .Values.diracx.manageSQLSchema }}
- name: create-sql-db-schema
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
command: ["bash", "/entrypoint.sh"]
args: ["python", "-m", "diracx.db", "init-sql"]
volumeMounts:
{{- if and .Values.developer.enabled .Values.developer.modulesToInstall }}
- mountPath: {{ .Values.developer.sourcePath }}
name: diracx-code-mount
readOnly: true
{{- range $module := .Values.developer.modulesToInstall }}
- mountPath: "{{ $.Values.developer.sourcePath }}/{{ $module }}/src/{{ $module }}.egg-info"
name: {{ lower $module }}-editable-install
readOnly: false
{{- end }}
{{- end }}
- name: container-entrypoint
mountPath: /entrypoint.sh
subPath: entrypoint.sh
volumeMounts: {{ toYaml $commonVolumeMounts | nindent 10 }}
envFrom:
- secretRef:
name: diracx-init-mysql-secrets
Expand Down Expand Up @@ -184,26 +158,7 @@ spec:
- "--reload-dir={{ .Values.developer.sourcePath }}"
{{- end }}
{{- end }}
volumeMounts:
- mountPath: /cs_store
name: cs-store-mount
readOnly: true
- mountPath: /signing-key/
name: signing-key-mount
readOnly: true
{{- if and .Values.developer.enabled .Values.developer.modulesToInstall }}
- mountPath: {{ .Values.developer.sourcePath }}
name: diracx-code-mount
readOnly: true
{{- range $module := .Values.developer.modulesToInstall }}
- mountPath: "{{ $.Values.developer.sourcePath }}/{{ $module }}/src/{{ $module }}.egg-info"
name: {{ lower $module }}-editable-install
readOnly: false
{{- end }}
{{- end }}
- name: container-entrypoint
mountPath: /entrypoint.sh
subPath: entrypoint.sh
volumeMounts: {{ toYaml $commonVolumeMounts | nindent 12 }}
envFrom:
# - configMapRef:
# name: diracx-env-config
Expand Down
46 changes: 46 additions & 0 deletions diracx/templates/diracx-container-entrypoint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,50 @@ data:
pip install {{- range $moduleName := .Values.developer.modulesToInstall }} -e {{ $.Values.developer.sourcePath }}/{{ $moduleName }} {{- end }}
{{- end }}

{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
SITE_PACKAGES_DIR=$(python -m sysconfig | grep platlib | head -n 1 | cut -d '=' -f 2 | cut -d '"' -f 2)
echo "Enabling coverage using pth file in SITE_PACKAGES_DIR=${SITE_PACKAGES_DIR}"
echo 'import coverage; coverage.process_startup()' > "${SITE_PACKAGES_DIR}/coverage.pth"
export COVERAGE_PROCESS_START=/diracx-coveragerc
{{- end }}

exec "$@"
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
coveragerc: |
[run]
data_file=/coverage-reports/coverage
relative_files=True
parallel=True
sigterm=True
omit =
*/diracx/client/*
{{- end }}
---
{{/* If we're collecting coverage we also need a volume to store it in */}}
{{- if and .Values.developer.enabled .Values.developer.enableCoverage }}
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-coverage
spec:
storageClassName: ""
accessModes:
- ReadWriteMany
capacity:
storage: 2Gi
hostPath:
path: /coverage-reports
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-coverage
spec:
storageClassName: ""
volumeName: pv-coverage
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Gi
{{ end }}
1 change: 1 addition & 0 deletions diracx/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ developer:
# Path from which to mount source of DIRACX
sourcePath: /diracx_source
modulesToInstall: []
enableCoverage: false
# If set, mount the CS stored localy instead of initializing a default one
# localCSPath: /local_cs_store

Expand Down
46 changes: 42 additions & 4 deletions run_demo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,23 @@ function check_hostname(){
fi
}

usage="${0##*/} [-h|--help] [--exit-when-done] [--] <diracx_src_dir> [other source directories]"
usage="${0##*/} [-h|--help] [--exit-when-done] [--enable-coverage] [--set-value key=value] [--] [source directories]"
usage+="\n\n"
usage+=" -h|--help: Print this help message and exit\n"
usage+=" --exit-when-done: Exit after the demo has been started (it will be left running in the background)\n"
usage+=" --enable-coverage: Enable coverage reporting\n"
usage+=" --set-value: Set a value in the Helm values file. This can be used to override the default values.\n"
usage+=" For example, to enable coverage reporting pass: --set-value developer.enableCoverage=true\n"
usage+=" source directories: A list of directories containing Python packages to mount in the demo cluster.\n"

# Parse command-line switches
exit_when_done=0
declare -a helm_arguments=()
enable_coverage=0
while [ -n "${1:-}" ]; do case $1 in
# Print a brief usage summary and exit
-h|--help|-\?)
printf 'Usage: %s\n' "$usage"
printf 'Usage: %b\n' "$usage"
exit ;;

# # Unbundle short options
Expand All @@ -74,7 +83,25 @@ while [ -n "${1:-}" ]; do case $1 in
--exit-when-done)
exit_when_done=1;
shift
break ;;
continue ;;

--enable-coverage)
helm_arguments+=("--set")
helm_arguments+=("developer.enableCoverage=true")
enable_coverage=1
shift
continue ;;

--set-value)
shift
if [[ -z "${1:-}" ]]; then
printf "%b Error: --set-value requires an argument\n" ${SKULL_EMOJI}
exit 1
fi
helm_arguments+=("--set")
helm_arguments+=("${1}")
shift
continue ;;

# Double-dash: Terminate option parsing
--)
Expand Down Expand Up @@ -186,6 +213,16 @@ if [ ${#pkg_dirs[@]} -gt 0 ]; then
sed "s@{{ hostPaths }}@ - hostPath: ${pkg_dir}\n containerPath: /diracx_source/$(basename "${pkg_dir}")\n{{ hostPaths }}@g" "${demo_dir}/demo_cluster_conf.yaml.bak" > "${demo_dir}/demo_cluster_conf.yaml"
done
fi
# If coverage is enabled mount .demo/coverage-reports into the cluster
if [[ ${enable_coverage} ]]; then
rm -rf "${demo_dir}/coverage-reports"
mkdir -p "${demo_dir}/coverage-reports"
# Make sure the directory is writable by the container
chmod 777 "${demo_dir}/coverage-reports"
mv "${demo_dir}/demo_cluster_conf.yaml" "${demo_dir}/demo_cluster_conf.yaml.bak"
sed "s@{{ hostPaths }}@ - hostPath: ${demo_dir}/coverage-reports\n containerPath: /coverage-reports\n{{ hostPaths }}@g" "${demo_dir}/demo_cluster_conf.yaml.bak" > "${demo_dir}/demo_cluster_conf.yaml"
fi
# Cleanup the "{{ hostPaths }}" part of the template and make sure things look reasonable
mv "${demo_dir}/demo_cluster_conf.yaml" "${demo_dir}/demo_cluster_conf.yaml.bak"
sed "s@{{ hostPaths }}@@g" "${demo_dir}/demo_cluster_conf.yaml.bak" > "${demo_dir}/demo_cluster_conf.yaml"
if grep '{{' "${demo_dir}/demo_cluster_conf.yaml"; then
Expand Down Expand Up @@ -229,7 +266,8 @@ printf "%b Waiting for ingress controller to be created...\n" ${UNICORN_EMOJI}

# Install the DiracX chart
printf "%b Installing DiracX...\n" ${UNICORN_EMOJI}
if ! "${demo_dir}/helm" install diracx-demo "${script_dir}/diracx" --values "${demo_dir}/values.yaml"; then
helm_arguments+=("--values" "${demo_dir}/values.yaml")
if ! "${demo_dir}/helm" install diracx-demo "${script_dir}/diracx" "${helm_arguments[@]}"; then
printf "%b Error using helm DiracX\n" ${WARN_EMOJI}
echo "Failed to run \"helm install\"" >> "${demo_dir}/.failed"
else
Expand Down