Skip to content

Commit 6c561f3

Browse files
committed
refactor: Renaming function in chart and adding doc
1 parent 079591b commit 6c561f3

File tree

8 files changed

+59
-41
lines changed

8 files changed

+59
-41
lines changed

infra/templates/_helpers.tpl

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
{{/*
1+
{{ /*
22
Expand the name of the chart.
3-
*/}}
4-
{{- define "goweb.name" -}}
3+
*/ }}
4+
{{- define "app.name" -}}
55
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
66
{{- end }}
77

8-
{{/*
8+
{{ /*
99
Create a default fully qualified app name.
1010
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
1111
If release name contains chart name it will be used as a full name.
12-
*/}}
13-
{{- define "goweb.fullname" -}}
12+
*/ }}
13+
{{- define "app.fullname" -}}
1414
{{- if .Values.fullnameOverride }}
1515
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
1616
{{- else }}
@@ -23,39 +23,39 @@ If release name contains chart name it will be used as a full name.
2323
{{- end }}
2424
{{- end }}
2525

26-
{{/*
26+
{{ /*
2727
Create chart name and version as used by the chart label.
28-
*/}}
29-
{{- define "goweb.chart" -}}
28+
*/ }}
29+
{{- define "app.chart" -}}
3030
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
3131
{{- end }}
3232

33-
{{/*
33+
{{ /*
3434
Ingress hosts
35-
*/}}
35+
*/ }}
3636
{{- define "ingress.hosts" -}}
3737
{{ range $count, $e := .Values.ingress.hosts -}}
3838
{{- if gt $count 0 }} || {{ end -}}
3939
Host(`{{ $e }}`)
4040
{{- end }}
4141
{{- end }}
4242

43-
{{/*
43+
{{ /*
4444
Common labels
45-
*/}}
46-
{{- define "goweb.labels" -}}
47-
helm.sh/chart: {{ include "goweb.chart" . }}
48-
{{ include "goweb.selectorLabels" . }}
45+
*/ }}
46+
{{- define "app.labels" -}}
47+
helm.sh/chart: {{ include "app.chart" . }}
48+
{{ include "app.selectorLabels" . }}
4949
{{- if .Chart.AppVersion }}
5050
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
5151
{{- end }}
5252
app.kubernetes.io/managed-by: {{ .Release.Service }}
5353
{{- end }}
5454

55-
{{/*
55+
{{ /*
5656
Selector labels
57-
*/}}
58-
{{- define "goweb.selectorLabels" -}}
59-
app.kubernetes.io/name: {{ include "goweb.name" . }}
57+
*/ }}
58+
{{- define "app.selectorLabels" -}}
59+
app.kubernetes.io/name: {{ include "app.name" . }}
6060
app.kubernetes.io/instance: {{ .Release.Name }}
6161
{{- end }}

infra/templates/config_map.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
apiVersion: v1
44
kind: ConfigMap
55
metadata:
6-
name: {{ include "goweb.fullname" . }}
6+
name: {{ include "app.fullname" . }}
77
namespace: {{ .Values.namespace }}
88
labels:
9-
{{- include "goweb.labels" . | nindent 4 }}
9+
{{- include "app.labels" . | nindent 4 }}
1010
data:
1111
{{- toYaml .Values.Config | nindent 2 }}
1212
{{ end }}

infra/templates/deployment.yaml

+9-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
apiVersion: apps/v1
33
kind: Deployment
44
metadata:
5-
name: {{ include "goweb.fullname" . }}
5+
name: {{ include "app.fullname" . }}
66
namespace: {{ .Values.namespace }}
77
labels:
8-
{{- include "goweb.labels" . | nindent 4 }}
8+
{{- include "app.labels" . | nindent 4 }}
99
spec:
1010
selector:
1111
matchLabels:
12-
{{- include "goweb.selectorLabels" . | nindent 6 }}
12+
{{- include "app.selectorLabels" . | nindent 6 }}
1313
template:
1414
metadata:
1515
{{- with .Values.podAnnotations }}
@@ -20,12 +20,17 @@ spec:
2020
checksum/config: {{ toYaml . | sha256sum }}
2121
{{- end }}
2222
labels:
23-
{{- include "goweb.selectorLabels" . | nindent 8 }}
23+
{{- include "app.selectorLabels" . | nindent 8 }}
2424
spec:
2525
containers:
2626
- name: {{ .Chart.Name }}
2727
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
2828
imagePullPolicy: {{ .Values.image.pullPolicy }}
29+
{{- if .Values.config }}
30+
envFrom:
31+
- configMapRef:
32+
name: {{ include "app.fullname" . }}
33+
{{- end }}
2934
ports:
3035
- name: http
3136
containerPort: 1080

infra/templates/hpa.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
apiVersion: autoscaling/v1
44
kind: HorizontalPodAutoscaler
55
metadata:
6-
name: {{ include "goweb.fullname" . }}
6+
name: {{ include "app.fullname" . }}
77
namespace: {{ .Values.namespace }}
88
labels:
9-
{{- include "goweb.labels" . | nindent 4 }}
9+
{{- include "app.labels" . | nindent 4 }}
1010
spec:
1111
scaleTargetRef:
1212
apiVersion: apps/v1
1313
kind: Deployment
14-
name: {{ include "goweb.fullname" . }}
14+
name: {{ include "app.fullname" . }}
1515
minReplicas: {{ .Values.autoscaling.minReplicas }}
1616
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
1717
targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}

infra/templates/ingress.yaml

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
apiVersion: traefik.containo.us/v1alpha1
44
kind: IngressRoute
55
metadata:
6-
name: {{ include "goweb.fullname" . }}-http
6+
name: {{ include "app.fullname" . }}-http
77
namespace: {{ .Values.namespace }}
88
labels:
9-
{{- include "goweb.labels" . | nindent 4 }}
9+
{{- include "app.labels" . | nindent 4 }}
1010
spec:
1111
entryPoints:
1212
- http
@@ -16,18 +16,18 @@ spec:
1616
middlewares:
1717
- name: redirect
1818
services:
19-
- name: {{ include "goweb.fullname" . }}
19+
- name: {{ include "app.fullname" . }}
2020
namespace: {{ .Values.namespace }}
2121
port: {{ .Values.service.port }}
2222

2323
---
2424
apiVersion: traefik.containo.us/v1alpha1
2525
kind: IngressRoute
2626
metadata:
27-
name: {{ include "goweb.fullname" . }}-https
27+
name: {{ include "app.fullname" . }}-https
2828
namespace: {{ .Values.namespace }}
2929
labels:
30-
{{- include "goweb.labels" . | nindent 4 }}
30+
{{- include "app.labels" . | nindent 4 }}
3131
spec:
3232
entryPoints:
3333
- https
@@ -38,7 +38,7 @@ spec:
3838
- name: compress
3939
- name: ratelimit
4040
services:
41-
- name: {{ include "goweb.fullname" . }}
41+
- name: {{ include "app.fullname" . }}
4242
namespace: {{ .Values.namespace }}
4343
port: {{ .Values.service.port }}
4444
tls:

infra/templates/pdb.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
apiVersion: policy/v1beta1
44
kind: PodDisruptionBudget
55
metadata:
6-
name: {{ include "goweb.fullname" . }}
6+
name: {{ include "app.fullname" . }}
77
namespace: {{ .Values.namespace }}
88
labels:
9-
{{- include "goweb.labels" . | nindent 4 }}
9+
{{- include "app.labels" . | nindent 4 }}
1010
spec:
1111
minAvailable: {{ .Values.pod_disruption.minAvailable }}
1212
selector:
1313
matchLabels:
14-
{{- include "goweb.selectorLabels" . | nindent 6 }}
14+
{{- include "app.selectorLabels" . | nindent 6 }}
1515
{{- end -}}

infra/templates/service.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
apiVersion: v1
33
kind: Service
44
metadata:
5-
name: {{ include "goweb.fullname" . }}
5+
name: {{ include "app.fullname" . }}
66
namespace: {{ .Values.namespace }}
77
labels:
8-
{{- include "goweb.labels" . | nindent 4 }}
8+
{{- include "app.labels" . | nindent 4 }}
99
spec:
1010
type: {{ .Values.service.type }}
1111
ports:
@@ -14,4 +14,4 @@ spec:
1414
targetPort: http
1515
protocol: TCP
1616
selector:
17-
{{- include "goweb.selectorLabels" . | nindent 4 }}
17+
{{- include "app.selectorLabels" . | nindent 4 }}

infra/values.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
---
2+
3+
# namespace is the namespace of every object created
24
namespace: default
35

6+
# image is the configuration of image management
47
image:
58
repository: vibioh/goweb
69
pullPolicy: Always
710

11+
# podAnnotations is the map of annotations placed on the pod
812
podAnnotations:
913
prometheus.io/scrape: "true"
1014
prometheus.io/scheme: http
1115
prometheus.io/port: "1080"
1216

17+
# livenessProbePath is the path of liveness
1318
livenessProbePath: /health
19+
20+
# readinessProbePath is the path of readiness
1421
readinessProbePath: /health
1522

23+
# config is the map of env var passed to the pod
1624
config: {}
1725

26+
# resources are the requests and limits for defining the QoS
1827
resources:
1928
limits:
2029
cpu: 100m
@@ -23,19 +32,23 @@ resources:
2332
cpu: 100m
2433
memory: 64M
2534

35+
# service is the configuration map for the service
2636
service:
2737
type: ClusterIP
2838
port: 80
2939

40+
# ingress is the configuration of the Traefik's ingress, in any
3041
ingress:
3142
enabled: true
3243
hosts:
3344
- goweb.vibioh.fr
3445

46+
# pod_disruption is the configuration of the pod_disruption_budget, in any
3547
pod_disruption:
3648
enabled: true
3749
minAvailable: 1
3850

51+
# autoscaling is the configuration of the horizontal pod autoscaler, in any
3952
autoscaling:
4053
enabled: true
4154
minReplicas: 1

0 commit comments

Comments
 (0)