Skip to content

Commit

Permalink
add labels templating
Browse files Browse the repository at this point in the history
  • Loading branch information
cesium147 committed Jan 23, 2023
1 parent 4a93dc9 commit e5f223b
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 53 deletions.
27 changes: 27 additions & 0 deletions charts/log-router/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,33 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- end -}}
{{- end -}}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "fluentd-router.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "fluentd-router.labels" -}}
helm.sh/chart: {{ include "fluentd-router.chart" . }}
{{ include "fluentd-router.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "fluentd-router.selectorLabels" -}}
app.kubernetes.io/name: {{ include "fluentd-router.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Set apiVersion based on .Capabilities.APIVersions
*/}}
Expand Down
5 changes: 1 addition & 4 deletions charts/log-router/templates/clusterrole.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ apiVersion: {{ template "rbacAPIVersion" . }}
kind: ClusterRole
metadata:
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- include "fluentd-router.labels" . | nindent 4 }}
{{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels | indent 4 }}
{{- end }}
Expand Down
11 changes: 3 additions & 8 deletions charts/log-router/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,15 @@ kind: DaemonSet
metadata:
name: {{ template "fluentd-router.fullname" . }}
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "fluentd-router.labels" . | nindent 4 }}
spec:
selector:
matchLabels:
app: {{ template "fluentd-router.name" . }}
release: {{ .Release.Name }}
{{- include "fluentd-router.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
app: {{ template "fluentd-router.name" . }}
release: {{ .Release.Name }}
{{- include "fluentd-router.selectorLabels" . | nindent 8 }}
annotations:
checksum/fluentd-extraenv: {{ toYaml .Values.fluentd.extraEnv | sha256sum }}
checksum/reloader-extraenv: {{ toYaml .Values.reloader.extraEnv | sha256sum }}
Expand Down
5 changes: 1 addition & 4 deletions charts/log-router/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ apiVersion: {{ template "rbacAPIVersion" . }}
kind: ClusterRoleBinding
metadata:
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- include "fluentd-router.labels" . | nindent 4 }}
{{- if .Values.extraLabels }}
{{ toYaml .Values.extraLabels | indent 4 }}
{{- end }}
Expand Down
7 changes: 2 additions & 5 deletions charts/log-router/templates/sa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- include "fluentd-router.labels" . | nindent 4 }}
name: {{ template "fluentd-router.fullname" . }}
{{- if .Values.rbac.serviceAccount.annotations }}
annotations: {{ toYaml .Values.rbac.serviceAccount.annotations | nindent 4 }}
Expand All @@ -19,4 +16,4 @@ metadata:
imagePullSecrets:
- name: {{ .Values.imagePullSecret}}
{{end}}
{{- end }}
{{- end }}
5 changes: 1 addition & 4 deletions charts/log-router/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ kind: Secret
metadata:
name: {{ template "fluentd-router.fullname" . }}
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "fluentd-router.labels" . | nindent 4 }}
annotations:
checksum/fluentd-extraenv: {{ toYaml .Values.fluentd.extraEnv | sha256sum }}
checksum/reloader-extraenv: {{ toYaml .Values.reloader.extraEnv | sha256sum }}
Expand Down
18 changes: 5 additions & 13 deletions charts/log-router/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ apiVersion: v1
kind: Service
metadata:
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- include "fluentd-router.labels" . | nindent 4 }}
metrics: fluentd
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "24231"
name: {{ template "fluentd-router.fullname" . }}
spec:
selector:
app: {{ template "fluentd-router.name" . }}
release: {{ .Release.Name }}
{{- include "fluentd-router.selectorLabels" . | nindent 4 }}
ports:
- port: 24231
name: prometheus
Expand All @@ -31,21 +27,17 @@ apiVersion: v1
kind: Service
metadata:
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
{{- include "fluentd-router.labels" . | nindent 4 }}
metrics: reloader
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: {{ .Values.metricsPort | quote }}
name: {{ template "fluentd-router.fullname" . }}-reloader
spec:
selector:
app: {{ template "fluentd-router.name" . }}
release: {{ .Release.Name }}
{{- include "fluentd-router.selectorLabels" . | nindent 4 }}
ports:
- port: {{ .Values.metricsPort }}
name: metrics
targetPort: metrics
{{- end }}
{{- end }}
20 changes: 6 additions & 14 deletions charts/log-router/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ kind: ServiceMonitor
metadata:
name: {{ template "fluentd-router.fullname" . }}
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "fluentd-router.labels" . | nindent 4 }}
spec:
jobLabel: app
jobLabel: {{ .Values.serviceMonitor.jobLabel | quote }}
selector:
matchLabels:
app: {{ template "fluentd-router.name" . }}
release: {{ .Release.Name }}
{{- include "fluentd-router.selectorLabels" . | nindent 6 }}
metrics: fluentd
endpoints:
- port: prometheus
Expand All @@ -28,16 +24,12 @@ kind: ServiceMonitor
metadata:
name: {{ template "fluentd-router.fullname" . }}-reloader
labels:
app: {{ template "fluentd-router.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
{{- include "fluentd-router.labels" . | nindent 4 }}
spec:
jobLabel: app
jobLabel: {{ .Values.serviceMonitor.jobLabel | quote }}
selector:
matchLabels:
app: {{ template "fluentd-router.name" . }}
release: {{ .Release.Name }}
{{- include "fluentd-router.selectorLabels" . | nindent 6 }}
metrics: reloader
endpoints:
- port: metrics
Expand Down
2 changes: 1 addition & 1 deletion charts/log-router/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ serviceMonitor:
enabled: false

# Job label for scrape target
jobLabel: app
jobLabel: app.kubernetes.io/name

# Scrape interval. If not set, the Prometheus default scrape interval is used.
interval: ""
Expand Down

0 comments on commit e5f223b

Please sign in to comment.