Skip to content

Commit

Permalink
wip(charts): mapcache uses a statefulset when using local cache [pack…
Browse files Browse the repository at this point in the history
… mapcache]
  • Loading branch information
robinbourianes-kalisio committed Feb 8, 2022
1 parent 51d4fad commit 5311d99
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
2 changes: 2 additions & 0 deletions charts/mapcache/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- if not (hasKey .Values "localCache") }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand Down Expand Up @@ -67,3 +68,4 @@ spec:
{{- if .Values.extraVolumes }}
{{- include "common.tplvalues.render" ( dict "value" .Values.extraVolumes "context" $ ) | nindent 8 }}
{{- end }}
{{- end }}
119 changes: 119 additions & 0 deletions charts/mapcache/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{{- if hasKey .Values "localCache" }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "common.names.fullname" . }}
namespace: {{ .Release.Namespace }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
replicas: {{ .Values.replicaCount }}
serviceName: {{ include "common.names.fullname" . }}
selector:
matchLabels: {{- include "common.labels.matchLabels" . | nindent 6 }}
template:
metadata:
labels: {{- include "common.labels.standard" . | nindent 8 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 8 }}
{{- end }}
spec:
initContainers:
{{- if .Values.envsubstConfig }}
{{- include "common.envsubstConfig.renderInitContainer" ( dict "args" .Values.envsubstConfig "context" $ ) | nindent 8 }}
{{- end }}
# seed local caches
# script runs with root privileges, so we fix permissions after that
{{- if .Values.localCache.seedLayers }}
- name: seed-local-cache
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
command:
- sh
- -c
- if [ $(hostname | awk -F '-' '{ print $NF }') -eq 0 ]; then for LAYER in {{ .Values.localCache.seedLayers }}; do echo "Seeding layer $LAYER ..." && mapcache_seed -c /etc/mapcache/mapcache.xml -t $LAYER -z {{ .Values.localCache.fromZ }},{{ .Values.localCache.toZ }} -n 8; done; fi
volumeMounts:
- mountPath: /etc/mapcache
readOnly: true
name: mapcache-config
- mountPath: /mnt/data
name: local-cache
- name: rclone-local-cache
image: rclone/rclone
command:
- sh
- -c
- if [ $(hostname | awk -F '-' '{ print $NF }') -eq 0 ]; then cd /cache && tar -cf /scratch/{{ .Release.Namespace }}-mapcache-local-cache.tar . && rclone copy /scratch/{{ .Release.Namespace }}-mapcache-local-cache.tar kaptain:helm-volatile --progress; else cd /cache && rclone copy kaptain:helm-volatile/{{ .Release.Namespace }}-mapcache-local-cache.tar /scratch --progress && tar xf /scratch/{{ .Release.Namespace }}-mapcache-local-cache.tar; fi
volumeMounts:
- mountPath: /cache
name: local-cache
- mountPath: /scratch
name: scratch-space
- mountPath: /config/rclone/rclone.conf
name: rclone-config
subPath: rclone.conf
readOnly: true
{{- end }}
# fix permissions on volume where is located local cache
# www-data:www-data as numeric ids is 33:33
- name: fix-local-cache-owner
image: busybox
command: [ 'chown', '-R', '33:33', '/cache' ]
volumeMounts:
- mountPath: /cache
name: local-cache
{{- if .Values.initContainers }}
{{- include "common.tplvalues.render" ( dict "value" .Values.initContainers "context" $ ) | nindent 8 }}
{{- end }}
containers:
- name: {{ include "common.names.name" . }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: HTTP_PROXY
- name: HTTPS_PROXY
- name: NO_PROXY
ports:
- name: {{ include "common.names.name" . }}
containerPort: 80
resources:
{{- toYaml .Values.resources | nindent 12 }}
volumeMounts:
- mountPath: /etc/mapcache
readOnly: true
name: mapcache-config
- mountPath: /mnt/data
name: local-cache
volumes:
- name: mapcache-config
{{- if .Values.envsubstConfig }}
emptyDir: {}
{{- else if .Values.configVolume }}
{{- include "common.tplvalues.render" ( dict "value" .Values.configVolume "context" $ ) | nindent 10 }}
{{- end }}
{{- if .Values.envsubstConfig }}
{{- include "common.envsubstConfig.renderVolume" ( dict "args" .Values.envsubstConfig "context" $ ) | nindent 8 }}
{{- end }}
{{- if .Values.localCache.seedLayers }}
- name: rclone-config
secret:
secretName: {{ .Release.Namespace }}-rclone-config
- name: scratch-space
emptyDir: {}
{{- end }}
{{- if .Values.extraVolumes }}
{{- include "common.tplvalues.render" ( dict "value" .Values.extraVolumes "context" $ ) | nindent 8 }}
{{- end }}
volumeClaimTemplates:
- metadata:
name: local-cache
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: {{ .Values.localCache.size }}
{{- end }}

0 comments on commit 5311d99

Please sign in to comment.