Skip to content

Commit

Permalink
Merge pull request #2039 from zanac1986/fix-promtail-refactor
Browse files Browse the repository at this point in the history
[promtail] Refactor
  • Loading branch information
zanhsieh committed Dec 5, 2022
2 parents fa992c3 + 8c9b62c commit f1fbb63
Show file tree
Hide file tree
Showing 12 changed files with 170 additions and 173 deletions.
2 changes: 1 addition & 1 deletion charts/promtail/Chart.yaml
Expand Up @@ -3,7 +3,7 @@ name: promtail
description: Promtail is an agent which ships the contents of local logs to a Loki instance
type: application
appVersion: 2.7.0
version: 6.7.0
version: 6.7.1
home: https://grafana.com/loki
sources:
- https://github.com/grafana/loki
Expand Down
2 changes: 1 addition & 1 deletion charts/promtail/README.md
@@ -1,6 +1,6 @@
# promtail

![Version: 6.7.0](https://img.shields.io/badge/Version-6.7.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.7.0](https://img.shields.io/badge/AppVersion-2.7.0-informational?style=flat-square)
![Version: 6.7.1](https://img.shields.io/badge/Version-6.7.1-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.7.0](https://img.shields.io/badge/AppVersion-2.7.0-informational?style=flat-square)

Promtail is an agent which ships the contents of local logs to a Loki instance

Expand Down
88 changes: 45 additions & 43 deletions charts/promtail/templates/_helpers.tpl
Expand Up @@ -2,33 +2,33 @@
Expand the name of the chart.
*/}}
{{- define "promtail.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- 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).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "promtail.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

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

{{/*
Common labels
Expand All @@ -54,38 +54,40 @@ app.kubernetes.io/instance: {{ .Release.Name }}
Create the name of the service account
*/}}
{{- define "promtail.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "promtail.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "promtail.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
The service name to connect to Loki. Defaults to the same logic as "loki.fullname"
*/}}
{{- define "loki.serviceName" -}}
{{- if .Values.loki.serviceName -}}
{{- .Values.loki.serviceName -}}
{{- else if .Values.loki.fullnameOverride -}}
{{- .Values.loki.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default "loki" .Values.loki.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if .Values.loki.serviceName }}
{{- .Values.loki.serviceName }}
{{- else if .Values.loki.fullnameOverride }}
{{- .Values.loki.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default "loki" .Values.loki.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/* Configure enableServiceLinks in pod */}}
{{/*
Configure enableServiceLinks in pod
*/}}
{{- define "promtail.enableServiceLinks" -}}
{{- if semverCompare ">=1.13-0" .Capabilities.KubeVersion.GitVersion -}}
{{- if or (.Values.enableServiceLinks) (eq (.Values.enableServiceLinks | toString) "<nil>") -}}
enableServiceLinks: true
{{- else -}}
enableServiceLinks: false
{{- end -}}
{{- end -}}
{{- end -}}
{{- if semverCompare ">=1.13-0" .Capabilities.KubeVersion.GitVersion }}
{{- if or (.Values.enableServiceLinks) (eq (.Values.enableServiceLinks | toString) "<nil>") }}
{{- printf "enableServiceLinks: true" }}
{{- else }}
{{- printf "enableServiceLinks: false" }}
{{- end }}
{{- end }}
{{- end }}
200 changes: 100 additions & 100 deletions charts/promtail/templates/_pod.tpl
@@ -1,118 +1,118 @@
{{/*
Pod template used in Daemonset and Deployment
*/}}
{{- define "promtail.podTemplate" }}
metadata:
labels:
{{- include "promtail.selectorLabels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- define "promtail.podTemplate" -}}
metadata:
labels:
{{- include "promtail.selectorLabels" . | nindent 4 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 4 }}
{{- end }}
annotations:
checksum/config: {{ include (print .Template.BasePath "/secret.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
serviceAccountName: {{ include "promtail.serviceAccountName" . }}
{{- include "promtail.enableServiceLinks" . | nindent 2 }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
{{- with .Values.initContainer }}
initContainers:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 4 }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 4 }}
containers:
- name: promtail
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "-config.file=/etc/promtail/promtail.yaml"
{{- with .Values.extraArgs }}
{{- toYaml . | nindent 8 }}
{{- end }}
annotations:
checksum/config: {{ include (print .Template.BasePath "/secret.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
volumeMounts:
- name: config
mountPath: /etc/promtail
{{- with .Values.defaultVolumeMounts }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ include "promtail.serviceAccountName" . }}
{{ include "promtail.enableServiceLinks" . }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
{{- with .Values.initContainer }}
initContainers:
{{- with .Values.extraVolumeMounts }}
{{- toYaml . | nindent 8 }}
{{- end }}
env:
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- with .Values.extraEnvFrom }}
envFrom:
{{- toYaml . | nindent 8 }}
{{- end }}
ports:
- name: http-metrics
containerPort: {{ .Values.config.serverPort }}
protocol: TCP
{{- range $key, $values := .Values.extraPorts }}
- name: {{ .name | default $key }}
containerPort: {{ $values.containerPort }}
protocol: {{ $values.protocol | default "TCP" }}
{{- end }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: promtail
image: "{{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args:
- "-config.file=/etc/promtail/promtail.yaml"
{{- with .Values.extraArgs }}
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: config
mountPath: /etc/promtail
{{- with .Values.defaultVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.extraVolumeMounts }}
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
{{- with .Values.extraEnv }}
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with .Values.extraEnvFrom }}
envFrom:
{{- toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http-metrics
containerPort: {{ .Values.config.serverPort }}
protocol: TCP
{{- range $key, $values := .Values.extraPorts }}
- name: {{ .name | default $key }}
containerPort: {{ $values.containerPort }}
protocol: {{ $values.protocol | default "TCP" }}
{{- end }}
securityContext:
{{- toYaml .Values.containerSecurityContext | nindent 12 }}
{{- with .Values.livenessProbe }}
livenessProbe:
{{- tpl (toYaml .) $ | nindent 12 }}
{{- end }}
{{- with .Values.readinessProbe }}
readinessProbe:
{{- tpl (toYaml .) $ | nindent 12 }}
{{- end }}
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.deployment.enabled }}
{{- range $name, $values := .Values.extraContainers }}
- name: {{ $name }}
{{ toYaml $values | nindent 10 }}
{{- toYaml .Values.containerSecurityContext | nindent 8 }}
{{- with .Values.livenessProbe }}
livenessProbe:
{{- tpl (toYaml .) $ | nindent 8 }}
{{- end }}
{{- with .Values.readinessProbe }}
readinessProbe:
{{- tpl (toYaml .) $ | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- if .Values.deployment.enabled }}
{{- range $name, $values := .Values.extraContainers }}
- name: {{ $name }}
{{ toYaml $values | nindent 6 }}
{{- end }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 4 }}
{{- end }}
volumes:
- name: config
{{- if .Values.configmap.enabled }}
configMap:
name: {{ include "promtail.fullname" . }}
{{- else }}
secret:
secretName: {{ include "promtail.fullname" . }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: config
{{- if .Values.configmap.enabled }}
configMap:
name: {{ include "promtail.fullname" . }}
{{- else }}
secret:
secretName: {{ include "promtail.fullname" . }}
{{- end }}
{{- with .Values.defaultVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.defaultVolumes }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.extraVolumes }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/promtail/templates/daemonset.yaml
@@ -1,4 +1,4 @@
{{- if .Values.daemonset.enabled -}}
{{- if .Values.daemonset.enabled }}
apiVersion: apps/v1
kind: DaemonSet
metadata:
Expand All @@ -17,5 +17,5 @@ spec:
updateStrategy:
{{- toYaml .Values.updateStrategy | nindent 4 }}
template:
{{- include "promtail.podTemplate" . -}}
{{- end -}}
{{- include "promtail.podTemplate" . | nindent 4 }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/promtail/templates/deployment.yaml
@@ -1,4 +1,4 @@
{{- if .Values.deployment.enabled -}}
{{- if .Values.deployment.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
Expand All @@ -18,5 +18,5 @@ spec:
matchLabels:
{{- include "promtail.selectorLabels" . | nindent 6 }}
template:
{{- include "promtail.podTemplate" . -}}
{{- end -}}
{{- include "promtail.podTemplate" . | nindent 4 }}
{{- end }}

0 comments on commit f1fbb63

Please sign in to comment.