Skip to content

Commit

Permalink
Create templates for database and observability configmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
nataliagranato committed May 27, 2024
1 parent 4e9d23a commit 8abe588
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 0 deletions.
File renamed without changes.
58 changes: 58 additions & 0 deletions charts/giropops-senhas-chart/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{{/*
Criar as nossas tags
*/}}
{{- define "app.labels" -}}
app: {{ .labels.app | quote }}
env: {{ .labels.env | quote }}
live: {{ .labels.live | quote }}
{{- end }}

{{/*
Definir os limites de recursos
*/}}
{{- define "app.resources" -}}
requests:
memory: {{ .resources.requests.memory }}
cpu: {{ .resources.requests.cpu }}
limits:
memory: {{ .resources.limits.memory }}
cpu: {{ .resources.limits.cpu }}
{{- end }}


{{/*
Definir as portas dos containers
*/}}
{{- define "app.ports" -}}
{{ range .ports }}
- containerPort: {{ .port }}
{{- end }}
{{- end }}


{{/*
Definindo os nossos configmaps
*/}}
{{- define "database.configmap" -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .component }}-db-config
data:
app-config.yaml: |
{{- toYaml .config | nindent 4 }}
{{- end }}


{{/*
Definindo os nossos configmaps
*/}}
{{- define "observability.configmap" -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ .component }}-observability-config
data:
app-config.json: |
{{ toJson .config }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- range $component, $config := .Values.databases }}
{{- $data := dict "component" $component "config" $config }}
{{- include "database.configmap" $data | nindent 0 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- range $component, $config := .Values.deployments }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ $component }}
labels:
{{- include "app.labels" $config | nindent 4 }}
spec:
replicas: {{ $config.replicas | default 2 }}
selector:
matchLabels:
app: {{ $config.labels.app }}
template:
metadata:
labels:
{{- include "app.labels" $config | nindent 8 }}
spec:
containers:
- name: {{ $component }}
image: {{ $config.image }}
ports:
{{- include "app.ports" $config | nindent 10 }}
resources:
{{- include "app.resources" $config | nindent 12 }}
---
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{- range $component, $config := .Values.services }}
{{- range $port := $config.ports }}
apiVersion: v1
kind: Service
metadata:
name: {{ $component }}-{{ $port.name }}
labels:
{{- include "app.labels" $config | nindent 4 }}
spec:
type: {{ $port.serviceType }}
ports:
- port: {{ $port.port }}
targetPort: {{ $port.targetPort }}
protocol: TCP
name: {{ $port.name }}
{{- if eq $port.serviceType "NodePort" }}
nodePort: {{ $port.nodePort }}
{{- end }}
selector:
app: {{ $config.labels.app }}
---
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- range $component, $config := .Values.observability }}
{{- $data := dict "component" $component "config" $config }}
{{- include "observability.configmap" $data | nindent 0 }}
{{- end }}
79 changes: 79 additions & 0 deletions charts/giropops-senhas-chart/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
deployments:
giropops-senhas:
name: "giropops-senhas"
image: "linuxtips/giropops-senhas:1.0"
replicas: "3"
ports:
- port: 5000
targetPort: 5000
name: "giropops-senhas-port"
serviceType: "NodePort"
NodePort: 32500
- port: 8088
targetPort: 8088
name: "giropops-senhas-metrics"
serviceType: "ClusterIP"
labels:
app: "giropops-senhas"
env: "labs"
live: "true"
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
redis:
name: "redis-helm"
image: "redis"
replicas: "1"
labels:
app: "redis"
env: "labs"
live: "true"
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
services:
giropops-senhas:
ports:
- port: 5000
targetPort: 5000
name: "app"
serviceType: "NodePort"
NodePort: 32500
- port: 8088
targetPort: 8088
name: "metrics"
serviceType: "ClusterIP"
labels:
app: "giropops-senhas"
env: "labs"
live: "true"
redis:
ports:
- port: 6379
targetPort: 6379
name: "service"
serviceType: "ClusterIP"
labels:
app: "redis"
env: "labs"
live: "true"
observability:
giropops-senhas:
logging: true
metrics:
enabled: true
path: "/metrics"
databases:
giropops-senhas:
mysql:
host: "mysql.svc.cluster.local"
port: 3306
name: "MyDB"

0 comments on commit 8abe588

Please sign in to comment.