Skip to content

Instantly share code, notes, and snippets.

@cmltaWt0
Created May 14, 2024 17:30
Show Gist options
  • Save cmltaWt0/83365470a7457ac4851b34a813c79607 to your computer and use it in GitHub Desktop.
Save cmltaWt0/83365470a7457ac4851b34a813c79607 to your computer and use it in GitHub Desktop.
Open edx k8s helm
{{- $root := . -}}
{{- range $w := .Values.edxapp.celeryworkers.EDXAPP_CELERY_WORKERS }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "edx-base.fullname" $root }}-{{ $w.service_variant }}-{{ $w.queue | replace "_" "-" }}
labels:
{{ include "edx-base.labels" $root | indent 4 }}
spec:
{{- if $w.replicaCount }}
replicas: {{ $w.replicaCount }}
{{- else }}
replicas: {{ $root.Values.replicaCount }}
{{- end }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "edx-base.name" $root }}-{{ $w.service_variant }}-{{ $w.queue | replace "_" "-" }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "edx-base.name" $root }}-{{ $w.service_variant }}-{{ $w.queue | replace "_" "-" }}
app.kubernetes.io/instance: {{ $root.Release.Name }}
spec:
{{- with $root.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml $root | nindent 8 }}
{{- end }}
volumes:
- name: {{ include "edx-base.fullname" $root }}-edxapp-config
configMap:
name: {{ include "edx-base.fullname" $root }}-edxapp-config
{{- if $root.Values.edxapp.supervisor.enabled }}
- name: {{ include "edx-base.fullname" $root }}-supervisor-w-config
configMap:
name: {{ include "edx-base.fullname" $root }}-supervisor-cm
items:
- key: "worker.conf"
path: "worker.conf"
- name: {{ include "edx-base.fullname" $root }}-supervisor-w-script
configMap:
name: {{ include "edx-base.fullname" $root }}-supervisor-cm
items:
- key: "{{ $w.service_variant }}_core_{{ $w.queue }}.sh"
path: "{{ $w.service_variant }}_core_{{ $w.queue }}.sh"
defaultMode: 0777
{{- end }}
- name: {{ include "edx-base.fullname" $root }}-static
emptyDir: {}
initContainers:
- name: copy-staticfiles
image: "{{ $root.Values.edxapp.image.theme_repository }}:{{ $root.Values.edxapp.image.theme_tag }}-{{ $root.Values.edxapp.image.tag }}"
command:
- /bin/sh
- '-c'
- >
cp -r /edx/var/edxapp/staticfiles/* /static/ &&
cp -r /edx/var/edxapp/themes /static/
resources: {}
volumeMounts:
- name: {{ include "edx-base.fullname" $root }}-static
mountPath: /static
imagePullPolicy: {{ $root.Values.edxapp.image.pullPolicy }}
containers:
- name: {{ $root.Chart.Name }}-{{ $w.service_variant }}-{{ $w.queue | replace "_" "-" }}
image: "{{ $root.Values.edxapp.image.repository }}:{{ $root.Values.edxapp.image.tag }}"
imagePullPolicy: {{ $root.Values.edxapp.image.pullPolicy }}
envFrom:
- configMapRef:
name: {{ include "edx-base.fullname" $root }}-celeryworker-config
env:
- name: REDIS_HOST
valueFrom:
secretKeyRef:
name: {{ include "edx-base.fullname" $root }}-secrets
key: REDIS_HOST
- name: REDIS_PASSWORD
valueFrom:
secretKeyRef:
name: {{ include "edx-base.fullname" $root }}-secrets
key: REDIS_PASSWORD
- name: DJANGO_SETTINGS_MODULE
value: "{{ $w.service_variant }}.envs.production"
{{- if $root.Values.edxapp.supervisor.enabled }}
command:
- /usr/bin/supervisord
args:
- "-n"
- "-c"
- "/etc/supervisor/supervisord.conf"
{{- else }}
command:
- celery
- --app={{ $w.service_variant }}.celery:APP
- worker
- --loglevel=info
- --concurrency={{ $w.concurrency }}
{{- if $w.prefetch_multiplier }}
- "--prefetch-multiplier={{ $w.prefetch_multiplier }}"
{{- end }}
{{- if $w.max_tasks_per_child }}
- --maxtasksperchild
- "{{ $w.max_tasks_per_child }}"
{{- end }}
- --queues=edx.{{ $w.service_variant }}.core.{{ $w.queue }}
- --hostname=edx.{{ $w.service_variant }}.core.{{ $w.queue }}
{{- end }}
volumeMounts:
- name: {{ include "edx-base.fullname" $root }}-edxapp-config
mountPath: /config/
- name: {{ include "edx-base.fullname" $root }}-static
mountPath: /edx/var/edxapp/staticfiles
{{- if $root.Values.edxapp.supervisor.enabled }}
- name: {{ include "edx-base.fullname" $root }}-supervisor-w-config
mountPath: /etc/supervisor/conf.d/worker.conf
subPath: worker.conf
- name: {{ include "edx-base.fullname" $root }}-supervisor-w-script
mountPath: /edx/app/edxapp/edx-platform/worker.sh
subPath: {{ $w.service_variant }}_core_{{ $w.queue }}.sh
{{- end }}
resources:
{{- if $w.resources }}
{{- with $w.resources }}
{{- toYaml $w.resources | nindent 12 }}
{{- end }}
{{- else }}
{{- toYaml $root.Values.edxapp.celeryworkers.resources | nindent 12 }}
{{- end }}
{{- with $root.Values.edxapp.celeryworkers.nodeSelector }}
nodeSelector:
{{- toYaml $root.Values.edxapp.celeryworkers.nodeSelector | nindent 8 }}
{{- end }}
{{- with $root.Values.edxapp.celeryworkers.affinity }}
affinity:
{{- toYaml $root | nindent 8 }}
{{- end }}
{{- with $root.Values.edxapp.celeryworkers.tolerations }}
tolerations:
{{- toYaml $root | nindent 8 }}
{{- end }}
imagePullSecrets:
- name: {{ $root.Values.imageCredentials.name }}
{{- end }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment