Skip to content

Commit

Permalink
feat: add common.labels to each created resource
Browse files Browse the repository at this point in the history
  • Loading branch information
x-mass committed Feb 9, 2025
1 parent 911f199 commit 296adb9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 3 deletions.
11 changes: 9 additions & 2 deletions templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ Create a default PDB name
{{ include "mychart.fullname" . }}-pdb
{{- end -}}

{{/*
Generate image tag
*/}}
{{- define "mychart.image" -}}
{{ .Values.deployment.image.registry }}/{{ .Values.deployment.image.repository }}:{{ default "latest" .Values.deployment.image.tag }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "app.labels" -}}
{{- define "common.labels" -}}
app.kubernetes.io/name: {{ .Release.Name | quote }}
app.kubernetes.io/instance: {{ .Release.Name | quote }}
app.kubernetes.io/version: {{ default .Chart.AppVersion .Values.image.tag | quote }}
app.kubernetes.io/version: {{ include "mychart.image" . | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service | quote }}
{{- with .Values.additionalLabels }}
{{- toYaml . | nindent 4 }}
Expand Down
4 changes: 3 additions & 1 deletion templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ kind: Deployment
metadata:
name: {{ include "mychart.fullname.deployment" . }}
namespace: {{ .Values.deployment.namespace | default .Values.namespace | default "default" }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
replicas: {{ default 1 .Values.deployment.replicaCount }}
selector:
Expand All @@ -19,7 +21,7 @@ spec:
spec:
containers:
- name: {{ .Values.appName }}
image: {{ .Values.deployment.image.registry }}/{{ .Values.deployment.image.repository }}:{{ default "latest" .Values.deployment.image.tag }}
image: {{ include "mychart.image" . }}
imagePullPolicy: {{ default "IfNotPresent" .Values.deployment.image.pullPolicy }}
{{- with .Values.deployment.resources }}
resources:
Expand Down
2 changes: 2 additions & 0 deletions templates/hpa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: HorizontalPodAutoscaler
metadata:
name: {{ include "mychart.fullname.hpa" . }}
namespace: {{ .Values.autoscaling.namespace | default .Values.namespace | default "default" }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
Expand Down
2 changes: 2 additions & 0 deletions templates/ingress-route.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: IngressRoute
metadata:
name: {{ default (include "mychart.fullname" .) .Values.ingressRoute.name }}
namespace: {{ .Values.ingressRoute.namespace | default .Values.namespace | default "default" }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
entryPoints:
{{- toYaml .Values.ingressRoute.entryPoints | nindent 4 }}
Expand Down
2 changes: 2 additions & 0 deletions templates/pdb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: PodDisruptionBudget
metadata:
name: {{ include "mychart.fullname.pdb" . }}
namespace: {{ .Values.podDisruptionBudget.namespace | default .Values.namespace | default "default" }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
{{- with .Values.podDisruptionBudget.minAvailable }}
minAvailable: {{ . }}
Expand Down
2 changes: 2 additions & 0 deletions templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ kind: Secret
metadata:
name: {{ include "mychart.fullname" . }}-secrets
namespace: {{ .Values.secrets.namespace | default .Values.namespace | default "default" }}
labels:
{{- include "common.labels" . | nindent 4 }}
type: Opaque
data:
{{- range $key, $value := .Values.secrets.data }}
Expand Down
2 changes: 2 additions & 0 deletions templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ metadata:
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "common.labels" . | nindent 4 }}
spec:
selector:
app: {{ .Values.appName }}
Expand Down

0 comments on commit 296adb9

Please sign in to comment.