From d929f2c4ebc78cd0fabfe13209e2fac16c5c197d 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 14:26:51 +0200 Subject: [PATCH] test tpl --- templates/_helpers.tpl | 53 ++++++++++++++++++++++++++ templates/api/api-config.yaml | 2 +- templates/api/api-deployment.yaml | 16 ++++---- templates/api/api-ingress.yaml | 4 +- templates/api/api-service.yaml | 4 +- templates/database/pg-config.yaml | 2 +- templates/database/pg-credentials.yaml | 2 +- templates/database/pg-deployment.yaml | 16 ++++---- templates/database/pg-service.yaml | 6 +-- templates/front/front-config.yaml | 2 +- templates/front/front-deployment.yaml | 10 ++--- templates/front/front-ingress.yaml | 4 +- templates/front/front-service.yaml | 4 +- values.yaml | 4 +- 14 files changed, 91 insertions(+), 38 deletions(-) create mode 100644 templates/_helpers.tpl diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000..e27fd56 --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,53 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "MyAppCtx.name" -}} +{{- default .Chart.Name | trunc 63 | trimSuffix "-" }} +{{- end }} + + +{{/* +Application image tag +We select by default the Chart appVersion or an override in values +*/}} +{{- define "MyAppCtx.imageTag" }} +{{- $name := default .Chart.AppVersion .Values.image.tag }} +{{- printf "%s" $name }} +{{- end }} + + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "MyAppCtx.fullname" }} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-"}} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "MyAppCtx.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "MyAppCtx.labels" -}} +helm.sh/chart: {{ include "MyAppCtx.chart" . }} +{{ include "MyAppCtx.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "MyAppCtx.selectorLabels" -}} +app.kubernetes.io/name: {{ include "MyAppCtx.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/templates/api/api-config.yaml b/templates/api/api-config.yaml index b20aafd..1a3ee02 100644 --- a/templates/api/api-config.yaml +++ b/templates/api/api-config.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: api-config + name: {{ include "MyAppCtx.fullname" . }}-api-config data: DB_ENDPOINT: "postgres:5432" DB_NAME: "{{ .Values.name }}-db" diff --git a/templates/api/api-deployment.yaml b/templates/api/api-deployment.yaml index dd06696..706f493 100644 --- a/templates/api/api-deployment.yaml +++ b/templates/api/api-deployment.yaml @@ -2,18 +2,18 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: api + name: {{ include "MyAppCtx.fullname" . }}-api labels: - app: api + app: {{ include "MyAppCtx.fullname" . }}-api spec: replicas: {{ .Values.api.replicaCount }} selector: matchLabels: - app: api + app: {{ include "MyAppCtx.fullname" . }}-api template: metadata: labels: - app: api + app: {{ include "MyAppCtx.fullname" . }}-api spec: securityContext: runAsUser: 1001 @@ -60,21 +60,21 @@ spec: - name: DB_ENDPOINT valueFrom: configMapKeyRef: - name: api-config + name: {{ include "MyAppCtx.fullname" . }}-api-config key: DB_ENDPOINT - name: POSTGRES_DB valueFrom: configMapKeyRef: - name: api-config + name: {{ include "MyAppCtx.fullname" . }}-api-config key: DB_NAME - name: POSTGRES_USER valueFrom: secretKeyRef: - name: pg-credentials # Nom du secret + name: {{ include "MyAppCtx.fullname" . }}-pg-credentials # Nom du secret key: pg_username # nom de la clef dans le config map - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: - name: pg-credentials # Nom du secret + name: {{ include "MyAppCtx.fullname" . }}-pg-credentials # Nom du secret key: pg_password {{- end}} \ No newline at end of file diff --git a/templates/api/api-ingress.yaml b/templates/api/api-ingress.yaml index 57a8b3a..e9ddd5f 100644 --- a/templates/api/api-ingress.yaml +++ b/templates/api/api-ingress.yaml @@ -4,7 +4,7 @@ kind: Ingress metadata: annotations: kubernetes.io/ingress.class: nginx - name: api + name: {{ include "MyAppCtx.fullname" . }}-api spec: rules: - host: {{ .Values.api.ingress.host }} @@ -12,7 +12,7 @@ spec: paths: - backend: service: - name: api + name: {{ include "MyAppCtx.fullname" . }}-api port: number: 80 path: / diff --git a/templates/api/api-service.yaml b/templates/api/api-service.yaml index 2cc25a0..6b99ea6 100644 --- a/templates/api/api-service.yaml +++ b/templates/api/api-service.yaml @@ -2,10 +2,10 @@ apiVersion: v1 kind: Service metadata: - name: api + name: {{ include "MyAppCtx.fullname" . }}-api spec: selector: - app: api + app: {{ include "MyAppCtx.fullname" . }}-api ports: - protocol: TCP port: 80 diff --git a/templates/database/pg-config.yaml b/templates/database/pg-config.yaml index f768aee..7c118c9 100644 --- a/templates/database/pg-config.yaml +++ b/templates/database/pg-config.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: - name: pg-config + name: {{ include "MyAppCtx.fullname" . }}-pg-config data: db_name: "{{ .Values.name }}-db" db_path: "/var/lib/postgresql/data/pgdata" diff --git a/templates/database/pg-credentials.yaml b/templates/database/pg-credentials.yaml index a440561..176354b 100644 --- a/templates/database/pg-credentials.yaml +++ b/templates/database/pg-credentials.yaml @@ -2,7 +2,7 @@ apiVersion: v1 kind: Secret metadata: - name: pg-credentials + name: {{ include "MyAppCtx.fullname" . }}-pg-credentials type: Opaque data: pg_username: {{ .Values.database.credentials.username }} diff --git a/templates/database/pg-deployment.yaml b/templates/database/pg-deployment.yaml index 37727b0..d6d5524 100644 --- a/templates/database/pg-deployment.yaml +++ b/templates/database/pg-deployment.yaml @@ -2,18 +2,18 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: pg-database + name: {{ include "MyAppCtx.fullname" . }}-database labels: - app: pg + app: {{ include "MyAppCtx.fullname" . }}-pg spec: replicas: {{ .Values.database.replicaCount }} selector: matchLabels: - app: pg + app: {{ include "MyAppCtx.fullname" . }}-pg template: metadata: labels: - app: pg + app: {{ include "MyAppCtx.fullname" . }}-pg spec: containers: - name: postgres @@ -24,22 +24,22 @@ spec: - name: POSTGRES_DB valueFrom: configMapKeyRef: - name: pg-config # Nom du configmap + name: {{ include "MyAppCtx.fullname" . }}-pg-config # Nom du configmap key: db_name # nom de la clef dans le config map contenant le nom de la DB - name: PGDATA valueFrom: configMapKeyRef: - name: pg-config # Nom du configmap + name: {{ include "MyAppCtx.fullname" . }}-pg-config # Nom du configmap key: db_path # nom de la clef dans le configMap contenant path ou installer la db dans le volume persistant - name: POSTGRES_USER valueFrom: secretKeyRef: - name: pg-credentials # Nom du secret + name: {{ include "MyAppCtx.fullname" . }}-pg-credentials # Nom du secret key: pg_username # nom de la clef dans le secret - name: POSTGRES_PASSWORD valueFrom: secretKeyRef: - name: pg-credentials # Nom du secret + name: {{ include "MyAppCtx.fullname" . }}-pg-credentials # Nom du secret key: pg_password # nom de la clef dans le secret contenant le password imagePullSecrets: - name: takima-school-registry diff --git a/templates/database/pg-service.yaml b/templates/database/pg-service.yaml index 8fdacbe..91fb92d 100644 --- a/templates/database/pg-service.yaml +++ b/templates/database/pg-service.yaml @@ -2,13 +2,13 @@ apiVersion: v1 kind: Service metadata: - name: postgres + name: {{ include "MyAppCtx.fullname" . }}-service labels: - app: pg + app: {{ include "MyAppCtx.fullname" . }}-pg spec: type: ClusterIP ports: - port: 5432 selector: - app: pg + app: {{ include "MyAppCtx.fullname" . }}-pg {{- end}} \ No newline at end of file diff --git a/templates/front/front-config.yaml b/templates/front/front-config.yaml index da89df7..f5f5015 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: {{ include "MyAppCtx.fullname" . }}-front data: API_URL: {{ $apiUrl }} {{- end }} \ No newline at end of file diff --git a/templates/front/front-deployment.yaml b/templates/front/front-deployment.yaml index fa7c697..fe164b0 100644 --- a/templates/front/front-deployment.yaml +++ b/templates/front/front-deployment.yaml @@ -2,18 +2,18 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ .Values.name }}-front + name: {{ include "MyAppCtx.fullname" . }}-front labels: - app: front + app: {{ include "MyAppCtx.fullname" . }}-front spec: replicas: {{ .Values.front.replicaCount }} selector: matchLabels: - app: front + app: {{ include "MyAppCtx.fullname" . }}-front template: metadata: labels: - app: front + app: {{ include "MyAppCtx.fullname" . }}-front spec: imagePullSecrets: - name: takima-school-registry @@ -63,6 +63,6 @@ spec: - name: API_URL valueFrom: configMapKeyRef: - name: {{ .Values.name }}-front + name: {{ include "MyAppCtx.fullname" . }}-front key: API_URL {{- end }} \ No newline at end of file diff --git a/templates/front/front-ingress.yaml b/templates/front/front-ingress.yaml index 8513bb5..4a3bb59 100644 --- a/templates/front/front-ingress.yaml +++ b/templates/front/front-ingress.yaml @@ -4,7 +4,7 @@ kind: Ingress metadata: annotations: kubernetes.io/ingress.class: nginx - name: {{ .Values.name }}-front + name: {{ include "MyAppCtx.fullname" . }}-front spec: rules: - host: {{ .Values.front.ingress.host }} @@ -12,7 +12,7 @@ spec: paths: - backend: service: - name: {{ .Values.name }}-front + name: {{ include "MyAppCtx.fullname" . }}-front port: number: 80 path: / diff --git a/templates/front/front-service.yaml b/templates/front/front-service.yaml index 8031d1a..3179499 100644 --- a/templates/front/front-service.yaml +++ b/templates/front/front-service.yaml @@ -2,10 +2,10 @@ apiVersion: v1 kind: Service metadata: - name: {{ .Values.name }}-front + name: {{ include "MyAppCtx.fullname" . }}-front spec: selector: - app: front + app: {{ include "MyAppCtx.fullname" . }}-front ports: - protocol: TCP port: 80 diff --git a/values.yaml b/values.yaml index 3de0c5f..764c382 100644 --- a/values.yaml +++ b/values.yaml @@ -2,7 +2,7 @@ # This is a YAML-formatted file. # Declare variables to be passed into your templates. # We have only done front for now -name: cdb +nameOverride: computer-db database: enabled: true @@ -19,7 +19,7 @@ api: image: repository: registry.gitlab.com/takima-school/images/cdb/api tag: latest - replicaCount: 2 + replicaCount: 1 ingress: tlsEnabled: true host: api.lherve.takima.school -- GitLab