From 718245fe3e972fa09dd229b51ca41241c52e7d88 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lo=C3=AFc=20Herv=C3=A9?= <lherve@takima.fr>
Date: Wed, 28 Jun 2023 12:11:40 +0200
Subject: [PATCH] helm ok

---
 templates/{ => api}/api-config.yaml         |  4 +++-
 templates/{ => api}/api-deployment.yaml     |  6 ++++--
 templates/{ => api}/api-ingress.yaml        |  8 +++++---
 templates/{ => api}/api-service.yaml        |  4 +++-
 templates/{ => database}/pg-config.yaml     |  4 +++-
 templates/database/pg-credentials.yaml      | 10 ++++++++++
 templates/{ => database}/pg-deployment.yaml |  6 ++++--
 templates/{ => database}/pg-service.yaml    |  4 +++-
 templates/{ => front}/front-config.yaml     |  0
 templates/{ => front}/front-deployment.yaml |  0
 templates/{ => front}/front-ingress.yaml    |  0
 templates/{ => front}/front-service.yaml    |  0
 templates/pg-credentials.yaml               |  8 --------
 values.yaml                                 | 14 ++++++++++++--
 14 files changed, 47 insertions(+), 21 deletions(-)
 rename templates/{ => api}/api-config.yaml (56%)
 rename templates/{ => api}/api-deployment.yaml (92%)
 rename templates/{ => api}/api-ingress.yaml (68%)
 rename templates/{ => api}/api-service.yaml (66%)
 rename templates/{ => database}/pg-config.yaml (57%)
 create mode 100644 templates/database/pg-credentials.yaml
 rename templates/{ => database}/pg-deployment.yaml (87%)
 rename templates/{ => database}/pg-service.yaml (71%)
 rename templates/{ => front}/front-config.yaml (100%)
 rename templates/{ => front}/front-deployment.yaml (100%)
 rename templates/{ => front}/front-ingress.yaml (100%)
 rename templates/{ => front}/front-service.yaml (100%)
 delete mode 100644 templates/pg-credentials.yaml

diff --git a/templates/api-config.yaml b/templates/api/api-config.yaml
similarity index 56%
rename from templates/api-config.yaml
rename to templates/api/api-config.yaml
index 8f6b212..b20aafd 100644
--- a/templates/api-config.yaml
+++ b/templates/api/api-config.yaml
@@ -1,7 +1,9 @@
+{{- if .Values.api.enabled }}
 apiVersion: v1
 kind: ConfigMap
 metadata:
   name: api-config
 data:
   DB_ENDPOINT: "postgres:5432"
-  DB_NAME: "cdb-db"
+  DB_NAME: "{{ .Values.name }}-db"
+{{- end}}
diff --git a/templates/api-deployment.yaml b/templates/api/api-deployment.yaml
similarity index 92%
rename from templates/api-deployment.yaml
rename to templates/api/api-deployment.yaml
index ddccf57..dd06696 100644
--- a/templates/api-deployment.yaml
+++ b/templates/api/api-deployment.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.api.enabled }}
 apiVersion: apps/v1
 kind: Deployment
 metadata:
@@ -5,7 +6,7 @@ metadata:
   labels:
     app: api
 spec:
-  replicas: 1
+  replicas: {{ .Values.api.replicaCount }}
   selector:
     matchLabels:
       app: api
@@ -21,7 +22,7 @@ spec:
         - name: takima-school-registry
       containers:
       - name: api
-        image: registry.gitlab.com/takima-school/images/cdb/api:latest
+        image: {{ .Values.api.image.repository }}:{{ .Values.api.image.tag }}
         resources:
           requests:
             memory: "192M"
@@ -76,3 +77,4 @@ spec:
               secretKeyRef:
                 name: pg-credentials  # Nom du secret
                 key: pg_password 
+{{- end}}
\ No newline at end of file
diff --git a/templates/api-ingress.yaml b/templates/api/api-ingress.yaml
similarity index 68%
rename from templates/api-ingress.yaml
rename to templates/api/api-ingress.yaml
index c8f7f5c..57a8b3a 100644
--- a/templates/api-ingress.yaml
+++ b/templates/api/api-ingress.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.api.enabled }}
 apiVersion: networking.k8s.io/v1
 kind: Ingress
 metadata:
@@ -6,7 +7,7 @@ metadata:
  name: api
 spec:
   rules:
-  - host: api.lherve.takima.school
+  - host: {{ .Values.api.ingress.host }}
     http:
       paths:
       - backend:
@@ -18,5 +19,6 @@ spec:
         pathType: Prefix
   tls:
   - hosts:
-     - api.lherve.takima.school
-    secretName: app-wildcard
\ No newline at end of file
+     - {{ .Values.api.ingress.host }}
+    secretName: app-wildcard
+{{- end}}
\ No newline at end of file
diff --git a/templates/api-service.yaml b/templates/api/api-service.yaml
similarity index 66%
rename from templates/api-service.yaml
rename to templates/api/api-service.yaml
index ab7f8b9..2cc25a0 100644
--- a/templates/api-service.yaml
+++ b/templates/api/api-service.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.api.enabled }}
 apiVersion: v1
 kind: Service
 metadata:
@@ -8,4 +9,5 @@ spec:
   ports:
     - protocol: TCP
       port: 80
-      targetPort: 8080
\ No newline at end of file
+      targetPort: 8080
+{{- end }}
\ No newline at end of file
diff --git a/templates/pg-config.yaml b/templates/database/pg-config.yaml
similarity index 57%
rename from templates/pg-config.yaml
rename to templates/database/pg-config.yaml
index 7f993a8..f768aee 100644
--- a/templates/pg-config.yaml
+++ b/templates/database/pg-config.yaml
@@ -1,7 +1,9 @@
+{{- if .Values.database.enabled }}
 apiVersion: v1
 kind: ConfigMap
 metadata:
   name: pg-config
 data:
-  db_name: "cdb-db"
+  db_name: "{{ .Values.name }}-db"
   db_path: "/var/lib/postgresql/data/pgdata"
+{{- end}}
diff --git a/templates/database/pg-credentials.yaml b/templates/database/pg-credentials.yaml
new file mode 100644
index 0000000..a440561
--- /dev/null
+++ b/templates/database/pg-credentials.yaml
@@ -0,0 +1,10 @@
+{{- if .Values.database.enabled }}
+apiVersion: v1
+kind: Secret
+metadata:
+  name: pg-credentials
+type: Opaque
+data:
+  pg_username: {{ .Values.database.credentials.username }}
+  pg_password: {{ .Values.database.credentials.password }}
+{{- end }}
\ No newline at end of file
diff --git a/templates/pg-deployment.yaml b/templates/database/pg-deployment.yaml
similarity index 87%
rename from templates/pg-deployment.yaml
rename to templates/database/pg-deployment.yaml
index 08684fb..37727b0 100644
--- a/templates/pg-deployment.yaml
+++ b/templates/database/pg-deployment.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.database.enabled }}
 apiVersion: apps/v1
 kind: Deployment
 metadata:
@@ -5,7 +6,7 @@ metadata:
   labels:
     app: pg
 spec:
-  replicas: 1
+  replicas: {{ .Values.database.replicaCount }}
   selector:
     matchLabels:
       app: pg
@@ -16,7 +17,7 @@ spec:
     spec:
       containers:
       - name: postgres
-        image: registry.takima.io/school/proxy/postgres:latest
+        image: {{ .Values.database.image.repository }}:{{ .Values.database.image.tag }}
         ports:
         - containerPort: 80
         env:
@@ -42,3 +43,4 @@ spec:
                 key: pg_password     # nom de la clef dans le secret contenant le password
       imagePullSecrets:
       - name: takima-school-registry
+{{- end }}
\ No newline at end of file
diff --git a/templates/pg-service.yaml b/templates/database/pg-service.yaml
similarity index 71%
rename from templates/pg-service.yaml
rename to templates/database/pg-service.yaml
index db304c6..8fdacbe 100644
--- a/templates/pg-service.yaml
+++ b/templates/database/pg-service.yaml
@@ -1,3 +1,4 @@
+{{- if .Values.database.enabled }}
 apiVersion: v1
 kind: Service
 metadata:
@@ -9,4 +10,5 @@ spec:
   ports:
    - port: 5432
   selector:
-   app: pg
\ No newline at end of file
+   app: pg
+{{- end}}
\ No newline at end of file
diff --git a/templates/front-config.yaml b/templates/front/front-config.yaml
similarity index 100%
rename from templates/front-config.yaml
rename to templates/front/front-config.yaml
diff --git a/templates/front-deployment.yaml b/templates/front/front-deployment.yaml
similarity index 100%
rename from templates/front-deployment.yaml
rename to templates/front/front-deployment.yaml
diff --git a/templates/front-ingress.yaml b/templates/front/front-ingress.yaml
similarity index 100%
rename from templates/front-ingress.yaml
rename to templates/front/front-ingress.yaml
diff --git a/templates/front-service.yaml b/templates/front/front-service.yaml
similarity index 100%
rename from templates/front-service.yaml
rename to templates/front/front-service.yaml
diff --git a/templates/pg-credentials.yaml b/templates/pg-credentials.yaml
deleted file mode 100644
index 0e80e90..0000000
--- a/templates/pg-credentials.yaml
+++ /dev/null
@@ -1,8 +0,0 @@
-apiVersion: v1
-kind: Secret
-metadata:
-  name: pg-credentials
-type: Opaque
-data:
-  pg_username: YWRtaW4=   # user: admin
-  pg_password: dGVzdDEyMyo=  # pwd: test123*
diff --git a/values.yaml b/values.yaml
index 9b2f23c..3de0c5f 100644
--- a/values.yaml
+++ b/values.yaml
@@ -4,12 +4,22 @@
 # We have only done front for now
 name: cdb
 
+database:
+  enabled: true
+  image:
+   repository: registry.takima.io/school/proxy/postgres
+   tag: latest
+  replicaCount: 1
+  credentials:
+    username: YWRtaW4= # user: admin
+    password: dGVzdDEyMyo= # pwd: test123*
+
 api:
   enabled: true
   image:
     repository: registry.gitlab.com/takima-school/images/cdb/api
     tag: latest
-  replicaCount: 1
+  replicaCount: 2
   ingress:
     tlsEnabled: true
     host: api.lherve.takima.school
@@ -22,4 +32,4 @@ front:
   replicaCount: 1
   ingress:
     tlsEnabled: true
-    host: cdb.lherve.takima.school
\ No newline at end of file
+    host: www.lherve.takima.school
\ No newline at end of file
-- 
GitLab