From 447c6d8cfb66e276fd6170758185ed992ed4998e 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 11:34:39 +0200
Subject: [PATCH] new boilerplate

---
 .gitignore                      |  1 +
 .idea/.gitignore                |  8 ++++++
 .idea/ch3-gitops.iml            |  9 +++++++
 .idea/misc.xml                  |  6 +++++
 .idea/modules.xml               |  8 ++++++
 .idea/vcs.xml                   |  6 +++++
 templates/front-config.yaml     |  6 ++---
 templates/front-deployment.yaml | 44 +++++++++++++++++++++++++++------
 templates/front-ingress.yaml    | 21 ++++++----------
 templates/front-service.yaml    |  6 ++---
 values.yaml                     | 41 +++++++++---------------------
 11 files changed, 100 insertions(+), 56 deletions(-)
 create mode 100644 .gitignore
 create mode 100644 .idea/.gitignore
 create mode 100644 .idea/ch3-gitops.iml
 create mode 100644 .idea/misc.xml
 create mode 100644 .idea/modules.xml
 create mode 100644 .idea/vcs.xml

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7773828
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+dist/
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/ch3-gitops.iml b/.idea/ch3-gitops.iml
new file mode 100644
index 0000000..d6ebd48
--- /dev/null
+++ b/.idea/ch3-gitops.iml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..639900d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectRootManager">
+    <output url="file://$PROJECT_DIR$/out" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..4c34d1d
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/ch3-gitops.iml" filepath="$PROJECT_DIR$/.idea/ch3-gitops.iml" />
+    </modules>
+  </component>
+</project>
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="" vcs="Git" />
+  </component>
+</project>
\ No newline at end of file
diff --git a/templates/front-config.yaml b/templates/front-config.yaml
index 3a3c126..da89df7 100644
--- a/templates/front-config.yaml
+++ b/templates/front-config.yaml
@@ -1,6 +1,6 @@
 {{- if .Values.front.enabled }}  
   {{- $apiUrl := "" }}  
-  {{- if .Values.api.ingress.tls.enabled }}  
+  {{- if .Values.api.ingress.tlsEnabled }}  
     {{- $apiUrl = printf "https://%s" .Values.api.ingress.host | quote }}  
   {{- else }}  
     {{- $apiUrl = printf "http://%s" .Values.api.ingress.host | quote }}  
@@ -8,7 +8,7 @@
 apiVersion: v1  
 kind: ConfigMap  
 metadata:  
-  name: front-config  
+  name: {{ .Values.name }}-front  
 data:  
   API_URL: {{ $apiUrl }}  
-{{- end }}
+{{- end }}
\ No newline at end of file
diff --git a/templates/front-deployment.yaml b/templates/front-deployment.yaml
index f6f7376..9f5e41d 100644
--- a/templates/front-deployment.yaml
+++ b/templates/front-deployment.yaml
@@ -2,7 +2,7 @@
 apiVersion: apps/v1
 kind: Deployment
 metadata:
-  name: front
+  name: {{ .Values.name }}-front
   labels:
     app: front
 spec:
@@ -16,20 +16,50 @@ spec:
         app: front
     spec:
       imagePullSecrets:
-        - name: auth-master3-registry
+        - name: takima-school-registry
+      securityContext:
+        runAsUser: 101
+        runAsGroup: 101
+
       containers:
       - name: front
         image: {{ .Values.front.image.repository }}:{{ .Values.front.image.tag }}
+        imagePullPolicy: Always
         ports:
-        - containerPort: 80
+          - containerPort: 8080
         resources:
           requests:
-            memory: "100Mi"
+            memory: "32M"
             cpu: "0.1"
           limits:
-            memory: "300Mi"
-            cpu: "0.5"
-        env:
+            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:
diff --git a/templates/front-ingress.yaml b/templates/front-ingress.yaml
index 158e1cf..8513bb5 100644
--- a/templates/front-ingress.yaml
+++ b/templates/front-ingress.yaml
@@ -1,14 +1,10 @@
 {{- if .Values.front.enabled }}
-{{- if .Values.front.ingress.enabled }}
 apiVersion: networking.k8s.io/v1
 kind: Ingress
 metadata:
-  annotations:
-    kubernetes.io/ingress.class: nginx
-{{- if .Values.front.ingress.tls.enabled }}
-    cert-manager.io/cluster-issuer: letsencrypt-prod
-{{- end }}
-  name: front
+ annotations:
+   kubernetes.io/ingress.class: nginx
+ name: {{ .Values.name }}-front
 spec:
   rules:
   - host: {{ .Values.front.ingress.host }}
@@ -16,16 +12,15 @@ spec:
       paths:
       - backend:
           service:
-            name: {{ .Values.front.serviceName }}
+            name: {{ .Values.name }}-front
             port:
-              number: {{ .Values.front.servicePort }}
+              number: 80
         path: /
         pathType: Prefix
-{{- if .Values.front.ingress.tls.enabled }}
+  {{- if .Values.front.ingress.tlsEnabled }}
   tls:
   - hosts:
       - {{ .Values.front.ingress.host }}
-    secretName: front-tls
-    {{- end }} 
-{{- end }}
+    secretName: app-wildcard
+  {{- end }}
 {{- end }}
\ No newline at end of file
diff --git a/templates/front-service.yaml b/templates/front-service.yaml
index 6c89a72..8031d1a 100644
--- a/templates/front-service.yaml
+++ b/templates/front-service.yaml
@@ -2,12 +2,12 @@
 apiVersion: v1
 kind: Service
 metadata:
-  name: {{ .Values.front.serviceName }}
+  name: {{ .Values.name }}-front
 spec:
   selector:
     app: front
   ports:
     - protocol: TCP
-      port: {{ .Values.front.servicePort }}
-      targetPort: 80
+      port: 80
+      targetPort: 8080
 {{- end }}
\ No newline at end of file
diff --git a/values.yaml b/values.yaml
index e4e8cf6..35b966b 100644
--- a/values.yaml
+++ b/values.yaml
@@ -1,44 +1,25 @@
 # Default values for CDB app.
 # This is a YAML-formatted file.
 # Declare variables to be passed into your templates.
-
-## The global properties are used to configure multiple charts at once.
-## Extended documentation at doc/charts/globals.md
+# We have only done front for now
+name: cdb
 
 api:
   enabled: true
+  image:
+    repository: registry.gitlab.com/takima-school/images/cdb/api
+    tag: latest
+  replicaCount: 1
   ingress:
-    tls:
-      enable: false
+    tlsEnabled: false
     host: api.to-replace.takima.school
 
 front:
   enabled: true
   image:
-    repository: registry.master3.takima.io/guide/kubernetes-resources/front
+    repository: registry.gitlab.com/takima-school/images/cdb/www
     tag: latest
-  serviceName: front
-  servicePort: 80
-  replicaCount: 3
+  replicaCount: 1
   ingress:
-    enabled: true
-    host: www.to-replace.takima.school
-    tls:
-      enabled: false
-
-db:
-  enabled: true
-  image:
-    repository: registry.master3.takima.io/guide/kubernetes-resources/db
-    tag: latest
-  name: "cdb-db"
-  path: "/var/lib/postgresql/data/pgdata"
-  serviceName: db
-  servicePort: 5432
-  pvc:
-    storageClass: gp2
-    size: 512Mi
-  credentials:
-    user: cdb
-    pwd: cdb123
-
+    tlsEnabled: false
+    host: www.to-replace.takima.school
\ No newline at end of file
-- 
GitLab