From 8e1c38c0b93cbf5144a30d990a1bea29c0fcb0f0 Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Wed, 30 Mar 2022 11:19:17 +0200
Subject: [PATCH] add chart templates

---
 chart/Chart.yaml                              |  6 +-
 chart/templates/deployment-back.yaml          | 44 +++++++++++++++
 chart/templates/deployment-celery-worker.yaml | 55 +++++++++++++++++++
 chart/templates/deployment-client.yaml        | 37 +++++++++++++
 chart/templates/ingress.yaml                  | 42 ++++++++++++++
 chart/templates/service-back.yaml             | 16 ++++++
 chart/templates/service-client.yaml           | 16 ++++++
 chart/values.yaml                             | 41 ++++++++++++++
 8 files changed, 254 insertions(+), 3 deletions(-)
 create mode 100644 chart/templates/deployment-back.yaml
 create mode 100644 chart/templates/deployment-celery-worker.yaml
 create mode 100644 chart/templates/deployment-client.yaml
 create mode 100644 chart/templates/ingress.yaml
 create mode 100644 chart/templates/service-back.yaml
 create mode 100644 chart/templates/service-client.yaml

diff --git a/chart/Chart.yaml b/chart/Chart.yaml
index a2af8586..73b3ac56 100644
--- a/chart/Chart.yaml
+++ b/chart/Chart.yaml
@@ -24,6 +24,6 @@ appVersion: 2.1.0
 
 # list dependencies
 dependencies:
-#- name: rabbitmq
-#  version: "8.30"
-#  repository: "https://charts.bitnami.com/bitnami"
+- name: rabbitmq
+  version: "8.30"
+  repository: "https://charts.bitnami.com/bitnami"
diff --git a/chart/templates/deployment-back.yaml b/chart/templates/deployment-back.yaml
new file mode 100644
index 00000000..28c1f0fb
--- /dev/null
+++ b/chart/templates/deployment-back.yaml
@@ -0,0 +1,44 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ printf "%s-%s" .Release.Name "back" }}
+  labels:
+    {{- include "chart.labels" . | nindent 4 }}
+    app: back
+spec:
+  selector:
+    matchLabels:
+      {{- include "chart.selectorLabels" . | nindent 6 }}
+      app: back
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+    {{- with .Values.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+      labels:
+        {{- include "chart.selectorLabels" . | nindent 8 }}
+        app: back
+    spec:
+      {{- with .Values.imagePullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      securityContext:
+        {{- toYaml .Values.podSecurityContext | nindent 8 }}
+      containers:
+      - name: back
+        image: {{ printf "%s/%s/%s:%s" .Values.CI_REGISTRY_IMAGE .Release.Name "backend" .Values.image.tag }}
+        securityContext:
+          {{- toYaml .Values.securityContext | nindent 12 }}
+        resources:
+          {{- toYaml .Values.back.resources | nindent 12 }}
+        volumeMounts:
+          - mountPath: /code/data_persistent
+            name: data-files
+      volumes:
+        - name: data-files
+          persistentVolumeClaim:
+            claimName: {{ printf "%s-data-files" .Release.Name }}
\ No newline at end of file
diff --git a/chart/templates/deployment-celery-worker.yaml b/chart/templates/deployment-celery-worker.yaml
new file mode 100644
index 00000000..aefca8bd
--- /dev/null
+++ b/chart/templates/deployment-celery-worker.yaml
@@ -0,0 +1,55 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ printf "%s-%s" .Release.Name "celery" }}
+  labels:
+    {{- include "chart.labels" . | nindent 4 }}
+    app: celery-worker
+spec:
+  selector:
+    matchLabels:
+      {{- include "chart.selectorLabels" . | nindent 6 }}
+      app: celery-worker
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+    {{- with .Values.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+      labels:
+        {{- include "chart.selectorLabels" . | nindent 8 }}
+        app: celery-worker
+    spec:
+      {{- with .Values.imagePullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      securityContext:
+        {{- toYaml .Values.podSecurityContext | nindent 8 }}
+      containers:
+      - name: celery
+        image: {{ printf "%s/%s/%s:%s" .Values.CI_REGISTRY_IMAGE .Release.Name "backend" .Values.image.tag }}
+        securityContext:
+          {{- toYaml .Values.securityContext | nindent 12 }}
+        command:
+          - "celery"
+          - "-A"
+          - "jass"
+          - "worker"
+          {{- if .Values.celery.concurrency }}
+          - "--concurrency={{ .Values.celery.concurrency }}"
+          {{- end }}
+          {{- if .Values.celery.maxTasksPerChild }}
+          - "--max-tasks-per-child={{ .Values.celery.maxTasksPerChild }}"
+          {{- end }}
+        resources:
+          {{- toYaml .Values.celery.resources | nindent 12 }}
+        volumeMounts:
+          - mountPath: /code/data_persistent
+            name: data-files
+      volumes:
+        - name: data-files
+          persistentVolumeClaim:
+            claimName: {{ printf "%s-data-files" .Release.Name }}
\ No newline at end of file
diff --git a/chart/templates/deployment-client.yaml b/chart/templates/deployment-client.yaml
new file mode 100644
index 00000000..63f6ca92
--- /dev/null
+++ b/chart/templates/deployment-client.yaml
@@ -0,0 +1,37 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: {{ printf "%s-%s" .Release.Name "client" }}
+  labels:
+    {{- include "chart.labels" . | nindent 4 }}
+    app: client
+spec:
+  selector:
+    matchLabels:
+      {{- include "chart.selectorLabels" . | nindent 6 }}
+      app: client
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+    {{- with .Values.podAnnotations }}
+      annotations:
+        {{- toYaml . | nindent 8 }}
+    {{- end }}
+      labels:
+        {{- include "chart.selectorLabels" . | nindent 8 }}
+        app: client
+    spec:
+      {{- with .Values.imagePullSecrets }}
+      imagePullSecrets:
+        {{- toYaml . | nindent 8 }}
+      {{- end }}
+      securityContext:
+        {{- toYaml .Values.podSecurityContext | nindent 8 }}
+      containers:
+      - name: nginx
+        image: {{ printf "%s/%s/%s:%s" .Values.CI_REGISTRY_IMAGE .Release.Name "client-static-serve" .Values.image.tag }}
+        securityContext:
+          {{- toYaml .Values.client.securityContext | nindent 12 }}
+        resources:
+          {{- toYaml .Values.client.resources | nindent 12 }}
\ No newline at end of file
diff --git a/chart/templates/ingress.yaml b/chart/templates/ingress.yaml
new file mode 100644
index 00000000..e28543b0
--- /dev/null
+++ b/chart/templates/ingress.yaml
@@ -0,0 +1,42 @@
+{{- if .Values.ingress.enabled -}}
+{{- $fullName := include "chart.fullname" . -}}
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  name: {{ $fullName }}
+  labels:
+    {{- include "chart.labels" . | nindent 4 }}
+  {{- with .Values.ingress.annotations }}
+  annotations:
+    {{- toYaml . | nindent 4 }}
+  {{- end }}
+spec:
+  {{- if .Values.ingress.tls }}
+  tls:
+    {{- range .Values.ingress.tls }}
+    - hosts:
+        {{- range .hosts }}
+        - {{ . | quote }}
+        {{- end }}
+      secretName: {{ .secretName }}
+    {{- end }}
+  {{- end }}
+  rules:
+    - host: {{ .Values.ingress.host.name | quote }}
+      http:
+        paths:
+          - path: /api/*
+            pathType: Prefix
+            backend:
+              service:
+                name: {{ printf "%s-%s" .Release.Name "back" }}
+                port:
+                  number: 8080
+          - path: /
+            pathType: Prefix
+            backend:
+              service:
+                name: {{ printf "%s-%s" .Release.Name "client" }}
+                port:
+                  number: 8080
+  {{- end }}
diff --git a/chart/templates/service-back.yaml b/chart/templates/service-back.yaml
new file mode 100644
index 00000000..2bbb2077
--- /dev/null
+++ b/chart/templates/service-back.yaml
@@ -0,0 +1,16 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ printf "%s-%s" .Release.Name "back" }}
+  labels:
+    {{- include "chart.labels" . | nindent 4 }}
+    app: back
+spec:
+  type: ClusterIP
+  ports:
+    - name: server
+      port: 8080
+      targetPort: 8080
+  selector:
+    {{- include "chart.selectorLabels" . | nindent 4 }}
+    app: back
diff --git a/chart/templates/service-client.yaml b/chart/templates/service-client.yaml
new file mode 100644
index 00000000..1fd4de45
--- /dev/null
+++ b/chart/templates/service-client.yaml
@@ -0,0 +1,16 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: {{ printf "%s-%s" .Release.Name "client" }}
+  labels:
+    {{- include "chart.labels" . | nindent 4 }}
+    app: client
+spec:
+  type: ClusterIP
+  ports:
+    - name: server
+      port: 8080
+      targetPort: 8080
+  selector:
+    {{- include "chart.selectorLabels" . | nindent 4 }}
+    app: client
diff --git a/chart/values.yaml b/chart/values.yaml
index 44b4e943..0e2c186d 100644
--- a/chart/values.yaml
+++ b/chart/values.yaml
@@ -49,6 +49,47 @@ ingress:
   host:
     name: chart-example.local
 
+celery:
+  resources:
+    requests:
+      memory: 4Gi
+      cpu: 1000m
+    limits:
+      memory: 4Gi
+      cpu: 2000m
+  concurrency: 1
+  maxTasksPerChild: 1
+
+back:
+  resources:
+    requests:
+      memory: 2Gi
+      cpu: 1000m
+    limits:
+      memory: 4Gi
+      cpu: 2000m
+
 data:
   size: 50Gi
   storageClassName: isilon
+
+client:
+  securityContext:
+    runAsNonRoot: true
+    runAsUser: 101
+    runAsGroup: 101
+  resources:
+    requests:
+      memory: 256Mi
+      cpu: 500m
+    limits:
+      memory: 512Mi
+      cpu: 1000m
+
+rabbitmq:
+  rbac:
+    create: false
+  persistence:
+    size: 1Gi
+  clustering:
+    enabled: false
-- 
GitLab