From 3e3a53d4652b9bf178d80655a32d4a4116ddb371 Mon Sep 17 00:00:00 2001
From: Vincent DU <vdu@takima.fr>
Date: Fri, 24 Nov 2023 15:58:21 +0100
Subject: [PATCH] change config

---
 dist/cdb/templates/api/api-config.yaml        |  8 +++
 dist/cdb/templates/api/api-deployment.yaml    | 67 ++++++++++++++++++
 dist/cdb/templates/api/api-ingress.yaml       | 20 ++++++
 dist/cdb/templates/api/api-service.yaml       | 13 ++++
 dist/cdb/templates/database/pg-config.yaml    |  9 +++
 .../templates/database/pg-credentials.yaml    | 10 +++
 .../cdb/templates/database/pg-deployment.yaml | 60 ++++++++++++++++
 dist/cdb/templates/database/pg-service.yaml   | 14 ++++
 dist/cdb/templates/front/front-config.yaml    |  8 +++
 .../cdb/templates/front/front-deployment.yaml | 68 +++++++++++++++++++
 dist/cdb/templates/front/front-ingress.yaml   | 20 ++++++
 dist/cdb/templates/front/front-service.yaml   | 13 ++++
 templates/api/api-config.yaml                 |  2 +-
 templates/database/pg-config.yaml             |  2 +-
 templates/front/front-config.yaml             |  2 +-
 15 files changed, 313 insertions(+), 3 deletions(-)
 create mode 100644 dist/cdb/templates/api/api-config.yaml
 create mode 100644 dist/cdb/templates/api/api-deployment.yaml
 create mode 100644 dist/cdb/templates/api/api-ingress.yaml
 create mode 100644 dist/cdb/templates/api/api-service.yaml
 create mode 100644 dist/cdb/templates/database/pg-config.yaml
 create mode 100644 dist/cdb/templates/database/pg-credentials.yaml
 create mode 100644 dist/cdb/templates/database/pg-deployment.yaml
 create mode 100644 dist/cdb/templates/database/pg-service.yaml
 create mode 100644 dist/cdb/templates/front/front-config.yaml
 create mode 100644 dist/cdb/templates/front/front-deployment.yaml
 create mode 100644 dist/cdb/templates/front/front-ingress.yaml
 create mode 100644 dist/cdb/templates/front/front-service.yaml

diff --git a/dist/cdb/templates/api/api-config.yaml b/dist/cdb/templates/api/api-config.yaml
new file mode 100644
index 0000000..f0b12ce
--- /dev/null
+++ b/dist/cdb/templates/api/api-config.yaml
@@ -0,0 +1,8 @@
+---
+# Source: cdb/templates/api/api-config.yaml
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: api-config
+data:
+  db-endpoint: "pg-service.vdu:5432"
diff --git a/dist/cdb/templates/api/api-deployment.yaml b/dist/cdb/templates/api/api-deployment.yaml
new file mode 100644
index 0000000..7143f52
--- /dev/null
+++ b/dist/cdb/templates/api/api-deployment.yaml
@@ -0,0 +1,67 @@
+---
+# Source: cdb/templates/api/api-deployment.yaml
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: api-deployment
+  labels:
+    app: api
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: api
+  template:
+    metadata:
+      labels:
+        app: api
+    spec:
+      securityContext:
+        runAsUser: 1001
+        runAsGroup: 1001
+      containers:
+        - name: api
+          image: registry.gitlab.com/takima-school/images/cdb/api:latest
+          ports:
+            - containerPort: 8080
+          readinessProbe:
+            httpGet:
+              port: 8080
+              path: /actuator/health/readiness
+            initialDelaySeconds: 5
+            periodSeconds: 5
+          livenessProbe:
+            httpGet:
+              port: 8080
+              path: /actuator/health/liveness
+            initialDelaySeconds: 300
+            periodSeconds: 300
+          startupProbe:
+            httpGet:
+              path: /actuator/health/startup
+              port: 8080
+            failureThreshold: 30
+            periodSeconds: 10
+          env:
+            - name: DB_ENDPOINT
+              valueFrom:
+                configMapKeyRef:
+                  name: api-config
+                  key: db-endpoint
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: pg-config
+                  key: db-name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: username
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: password
+      imagePullSecrets:
+        - name: takima-school-registry
diff --git a/dist/cdb/templates/api/api-ingress.yaml b/dist/cdb/templates/api/api-ingress.yaml
new file mode 100644
index 0000000..88d0fba
--- /dev/null
+++ b/dist/cdb/templates/api/api-ingress.yaml
@@ -0,0 +1,20 @@
+---
+# Source: cdb/templates/api/api-ingress.yaml
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  annotations:
+    kubernetes.io/ingress.class: nginx
+  name: api-ingress
+spec:
+  rules:
+    - host: api.vdu.takima.school
+      http:
+        paths:
+          - backend:
+              service:
+                name: api-service
+                port:
+                  number: 80
+            path: /
+            pathType: Prefix
diff --git a/dist/cdb/templates/api/api-service.yaml b/dist/cdb/templates/api/api-service.yaml
new file mode 100644
index 0000000..239b25d
--- /dev/null
+++ b/dist/cdb/templates/api/api-service.yaml
@@ -0,0 +1,13 @@
+---
+# Source: cdb/templates/api/api-service.yaml
+apiVersion: v1
+kind: Service
+metadata:
+  name: api-service
+spec:
+  selector:
+    app: api
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
diff --git a/dist/cdb/templates/database/pg-config.yaml b/dist/cdb/templates/database/pg-config.yaml
new file mode 100644
index 0000000..fb1aa83
--- /dev/null
+++ b/dist/cdb/templates/database/pg-config.yaml
@@ -0,0 +1,9 @@
+---
+# Source: cdb/templates/database/pg-config.yaml
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: pg-config
+data:
+  db-name: "pg-db"
+  db_path: "/var/lib/postgresql/data/pgdata"
diff --git a/dist/cdb/templates/database/pg-credentials.yaml b/dist/cdb/templates/database/pg-credentials.yaml
new file mode 100644
index 0000000..99902a3
--- /dev/null
+++ b/dist/cdb/templates/database/pg-credentials.yaml
@@ -0,0 +1,10 @@
+---
+# Source: cdb/templates/database/pg-credentials.yaml
+apiVersion: v1
+kind: Secret
+metadata:
+  name: pg-credentials
+type: Opaque
+data:
+  username: YWRtaW4=
+  password: MWYyZDFlMmU2N2Rm
diff --git a/dist/cdb/templates/database/pg-deployment.yaml b/dist/cdb/templates/database/pg-deployment.yaml
new file mode 100644
index 0000000..d04a566
--- /dev/null
+++ b/dist/cdb/templates/database/pg-deployment.yaml
@@ -0,0 +1,60 @@
+---
+# Source: cdb/templates/database/pg-deployment.yaml
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: pg-deployment
+  labels:
+    app: pg
+spec:
+  replicas: 3
+  selector:
+    matchLabels:
+      app: pg
+  template:
+    metadata:
+      labels:
+        app: pg
+    spec:
+      containers:
+        - name: pg
+          image: registry.gitlab.com/takima-school/proxy/postgres:latest
+          ports:
+            - containerPort: 5432
+          resources:
+            requests:
+              memory: "64Mi"
+              cpu: "250m"
+            limits:
+              memory: "128Mi"
+              cpu: "500m"
+          env:
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  name: pg-config
+                  key: db-name
+            - name: POSTGRES_USER
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: username
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                secretKeyRef:
+                  name: pg-credentials
+                  key: password
+            - name: PGDATA
+              valueFrom:
+                configMapKeyRef:
+                  name: pg-config  # Nom du configmap
+                  key: pg_path     # nom de la clef dans le configMap contenant path ou installer la db dans le volume persistant
+          volumeMounts:
+            - mountPath: /var/lib/postgresql/data
+              name: pg-data
+      imagePullSecrets:
+        - name: takima-school-registry
+      volumes:
+        - name: pg-data
+          persistentVolumeClaim:
+            claimName: pg-db
diff --git a/dist/cdb/templates/database/pg-service.yaml b/dist/cdb/templates/database/pg-service.yaml
new file mode 100644
index 0000000..2bb0f67
--- /dev/null
+++ b/dist/cdb/templates/database/pg-service.yaml
@@ -0,0 +1,14 @@
+---
+# Source: cdb/templates/database/pg-service.yaml
+apiVersion: v1
+kind: Service
+metadata:
+  name: pg-service
+spec:
+  type: ClusterIP
+  selector:
+    app: pg
+  ports:
+    - protocol: TCP
+      port: 5432
+      targetPort: 5432
diff --git a/dist/cdb/templates/front/front-config.yaml b/dist/cdb/templates/front/front-config.yaml
new file mode 100644
index 0000000..2ce9975
--- /dev/null
+++ b/dist/cdb/templates/front/front-config.yaml
@@ -0,0 +1,8 @@
+---
+# Source: cdb/templates/front/front-config.yaml
+apiVersion: v1  
+kind: ConfigMap  
+metadata:  
+  name: cdb-front  
+data:  
+  API_URL: "http://api.vdu.takima.school"
diff --git a/dist/cdb/templates/front/front-deployment.yaml b/dist/cdb/templates/front/front-deployment.yaml
new file mode 100644
index 0000000..35940ad
--- /dev/null
+++ b/dist/cdb/templates/front/front-deployment.yaml
@@ -0,0 +1,68 @@
+---
+# Source: cdb/templates/front/front-deployment.yaml
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: cdb-front
+  labels:
+    app: front
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: front
+  template:
+    metadata:
+      labels:
+        app: front
+    spec:
+      imagePullSecrets:
+        - name: takima-school-registry
+      securityContext:
+        runAsUser: 101
+        runAsGroup: 101
+
+      containers:
+      - name: front
+        image: registry.gitlab.com/takima-school/images/cdb/www:latest
+        imagePullPolicy: Always
+        ports:
+          - containerPort: 8080
+        resources:
+          requests:
+            memory: "32M"
+            cpu: "0.1"
+          limits:
+            memory: "128M"
+            cpu: "1"
+        startupProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          initialDelaySeconds: 3
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 5
+        livenessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 3
+          successThreshold: 1
+          failureThreshold: 3
+        readinessProbe:
+          httpGet:
+            path: /health
+            port: 8080
+          periodSeconds: 1
+          successThreshold: 1
+          failureThreshold: 3
+        securityContext:
+          allowPrivilegeEscalation: false
+        
+        env: 
+          - name: API_URL
+            valueFrom:
+              configMapKeyRef:
+                name: cdb-front
+                key: API_URL
diff --git a/dist/cdb/templates/front/front-ingress.yaml b/dist/cdb/templates/front/front-ingress.yaml
new file mode 100644
index 0000000..659aaf4
--- /dev/null
+++ b/dist/cdb/templates/front/front-ingress.yaml
@@ -0,0 +1,20 @@
+---
+# Source: cdb/templates/front/front-ingress.yaml
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+ annotations:
+   kubernetes.io/ingress.class: nginx
+ name: cdb-front
+spec:
+  rules:
+  - host: www.vdu.takima.school
+    http:
+      paths:
+      - backend:
+          service:
+            name: cdb-front
+            port:
+              number: 80
+        path: /
+        pathType: Prefix
diff --git a/dist/cdb/templates/front/front-service.yaml b/dist/cdb/templates/front/front-service.yaml
new file mode 100644
index 0000000..20e7f1c
--- /dev/null
+++ b/dist/cdb/templates/front/front-service.yaml
@@ -0,0 +1,13 @@
+---
+# Source: cdb/templates/front/front-service.yaml
+apiVersion: v1
+kind: Service
+metadata:
+  name: cdb-front
+spec:
+  selector:
+    app: front
+  ports:
+    - protocol: TCP
+      port: 80
+      targetPort: 8080
diff --git a/templates/api/api-config.yaml b/templates/api/api-config.yaml
index 075bf82..aec0929 100644
--- a/templates/api/api-config.yaml
+++ b/templates/api/api-config.yaml
@@ -2,7 +2,7 @@
 apiVersion: v1
 kind: ConfigMap
 metadata:
-  name: {{ .Values.api.name }}-config
+  name: api-config
 data:
   db-endpoint: "{{ .Values.pg.service.name }}.{{ .Values.namespace }}:{{ .Values.pg.service.port }}"
 {{- end }}
diff --git a/templates/database/pg-config.yaml b/templates/database/pg-config.yaml
index 3418d4f..1312401 100644
--- a/templates/database/pg-config.yaml
+++ b/templates/database/pg-config.yaml
@@ -1,7 +1,7 @@
 apiVersion: v1
 kind: ConfigMap
 metadata:
-  name: {{ .Values.pg.name }}-config
+  name: pg-config
 data:
   db-name: "{{ .Values.pg.name }}-db"
   db_path: "{{ .Values.pg.path }}/pgdata"
diff --git a/templates/front/front-config.yaml b/templates/front/front-config.yaml
index da89df7..ba8778b 100644
--- a/templates/front/front-config.yaml
+++ b/templates/front/front-config.yaml
@@ -8,7 +8,7 @@
 apiVersion: v1  
 kind: ConfigMap  
 metadata:  
-  name: {{ .Values.name }}-front  
+  name: front-config
 data:  
   API_URL: {{ $apiUrl }}  
 {{- end }}
\ No newline at end of file
-- 
GitLab