Skip to content
60 changes: 54 additions & 6 deletions ml-testing-toolkit/chart-backend/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,55 @@ spec:
{{- if .Values.initContainers }}
{{- include "common.tplvalues.render" (dict "value" .Values.initContainers "context" $) | nindent 8 }}
{{- end }}
- name: copy-original-files
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- sh
- -c
- |
set -e
echo "Copying files to /tmp/stage"
mkdir -p /tmp/stage
cp -r -v /opt/app/spec_files/. /tmp/stage/ || { echo "Copy to /tmp/stage failed"; exit 1; }
echo "Setting permissions in /tmp/stage:"
chmod -R 644 /tmp/stage/* 2>/dev/null || true
find /tmp/stage -type d -exec chmod 755 {} \; 2>/dev/null || true
echo "Copying from /tmp/stage to /target"
cp -r -v /tmp/stage/. /target/ || { echo "Copy to /target failed"; exit 1; }
volumeMounts:
- name: spec-files
mountPath: /target
resources: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
- name: add-extra-specs
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- sh
- -c
- |
set -e
cd /opt/default_config
for FILE in *; do
CONTENT=$(cat "$FILE")
DEST="/opt/app/spec_files/${FILE//__/\/}"
mkdir -p "$(dirname "$DEST")"
if echo "$CONTENT" | grep -q '^"http'; then
URL=$(echo "$CONTENT" | tr -d '"')
echo "Downloading $URL to $DEST"
wget -q -O "$DEST" "$URL"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that recent version of TTK backend can download the config files on its own, so there is no need this to happen in the chart. We are trying to run all containers with read only file system to improve security and ensure stateless services.
See mojaloop/ml-testing-toolkit#332

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @kalinkrustev are there any config changes required for this to work? At what stage it downloads the files? If the root filesystem is readonly will the download work? The current mojaloop/values.yaml in the helm repo doesn't work with your latest change. The files are not downloaded.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you only need to include the new TTK backend image version in helm. The downloaded config is cached in memory and used directly and not saved to the disk.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additional PR to implement downloading mojaloop/ml-testing-toolkit#336

else
echo "Copying $FILE to $DEST"
cp "$FILE" "$DEST"
fi
done
volumeMounts:
- name: spec-files
mountPath: /opt/app/spec_files
- name: {{ include "ml-testing-toolkit-backend.fullname" . }}-volume-config-default
mountPath: /opt/default_config
{{- if .Values.image.pullSecrets }}
{{- include "common.images.renderPullSecrets" (dict "images" (list .Values.image) "context" $) | nindent 6 }}
{{- end }}
Expand Down Expand Up @@ -136,14 +185,12 @@ spec:
- name: {{ $serviceFullName }}-volume-extra-environments
mountPath: /opt/app/examples/environments/{{ $k }}
subPath: {{ $k }}
{{- end }}
{{- range $k, $v := .Values.config_files }}
- name: {{ $serviceFullName }}-volume-config-default
mountPath: /opt/app/spec_files/{{ $k | replace "__" "/" }}
subPath: {{ $k }}
{{- end }}
- name: release-cd-rc
mountPath: /home/ml-user/.release_cd
- name: spec-files # Added to mount merged files
mountPath: /opt/app/spec_files
readOnly: true
{{- if and .Values.config.mongodb.ssl.caSecret (hasKey .Values.config.mongodb.ssl.caSecret "name") (not (empty .Values.config.mongodb.ssl.caSecret.name)) }}
- name: mongo-ca
mountPath: /opt/app/mongo-ca
Expand Down Expand Up @@ -174,6 +221,8 @@ spec:
configMap:
name: release-cd-rc
optional: true
- name: spec-files
emptyDir: {}
{{- if and .Values.config.mongodb.ssl.caSecret (hasKey .Values.config.mongodb.ssl.caSecret "name") (not (empty .Values.config.mongodb.ssl.caSecret.name)) }}
- name: mongo-ca
secret:
Expand All @@ -182,7 +231,6 @@ spec:
- key: '{{ .Values.config.mongodb.ssl.caSecret.key }}'
path: mongo-ca.pem
{{- end }}

{{- if .Values.persistence.enabled }}
volumeClaimTemplates:
- metadata:
Expand Down