Skip to content

Commit

Permalink
add grafana agent
Browse files Browse the repository at this point in the history
  • Loading branch information
slamdev committed Aug 15, 2022
1 parent 7a4e1ab commit e9fe43f
Show file tree
Hide file tree
Showing 13 changed files with 543 additions and 0 deletions.
12 changes: 12 additions & 0 deletions charts/grafana-agent/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v2
name: grafana-agent
description: |-
Helm chart to deploy [grafana-agent](https://github.com/grafana/agent).
type: application
version: 0.0.1
appVersion: v0.26.1
home: https://github.com/slamdev/helm-charts/tree/master/charts/grafana-agent
icon: https://grafana.com/static/assets/internal/grafana_logo-web-white-text.svg
maintainers:
- name: slamdev
email: [email protected]
60 changes: 60 additions & 0 deletions charts/grafana-agent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# grafana-agent

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

Helm chart to deploy [grafana-agent](https://github.com/grafana/agent).

**Homepage:** <https://github.com/slamdev/helm-charts/tree/master/charts/grafana-agent>

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| slamdev | <[email protected]> | |

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| additionalResources | list | `[]` | list of additional resources to create (are processed via `tpl` function) |
| affinity | object | `{}` | affinity for scheduler pod assignment |
| args[0] | string | `"--config.file=/grafana-agent.yaml"` | |
| conf | string | `"server:\n log_level: info"` | grafana-agent config to provision inside of the container |
| containerPorts | list | `[{"containerPort":12345,"name":"http"},{"containerPort":12346,"name":"grpc"}]` | ports exposed by container |
| env | list | `[{"name":"HOSTNAME","valueFrom":{"fieldRef":{"fieldPath":"spec.nodeName"}}},{"name":"POD_NAME","valueFrom":{"fieldRef":{"fieldPath":"metadata.name"}}},{"name":"POD_IP","valueFrom":{"fieldRef":{"fieldPath":"status.podIP"}}}]` | additional environment variables for the deployment |
| fullnameOverride | string | `""` | full name of the chart. |
| image.pullPolicy | string | `"IfNotPresent"` | image pull policy |
| image.repository | string | `"grafana/grafana-agent"` | image repository |
| image.tag | string | `""` | image tag (chart's appVersion value will be used if not set) |
| imagePullSecrets | list | `[]` | image pull secret for private images |
| livenessProbe.httpGet.path | string | `"/http-metrics/-/ready"` | path for liveness probe |
| livenessProbe.httpGet.port | string | `"http"` | port for liveness probe |
| nameOverride | string | `""` | override name of the chart |
| nodeSelector | object | `{}` | node for scheduler pod assignment |
| podAnnotations | object | `{}` | annotations to add to the pod |
| podSecurityContext | object | `{}` | specifies security settings for a pod |
| readinessProbe.httpGet.path | string | `"/http-metrics/-/ready"` | path for readiness probe |
| readinessProbe.httpGet.port | string | `"http"` | port for readiness probe |
| resources | object | `{}` | custom resource configuration |
| securityContext | object | `{}` | specifies security settings for a container |
| service.annotations | object | `{}` | service annotations |
| service.ports | list | `[{"name":"http","port":12345,"targetPort":"http"},{"name":"grpc","port":12346,"targetPort":"grpc"}]` | service ports |
| service.type | string | `"ClusterIP"` | service type |
| serviceAccount.annotations | object | `{}` | annotations to add to the service account |
| serviceAccount.create | bool | `false` | specifies whether a service account should be created |
| serviceAccount.name | string | `nil` | the name of the service account to use; if not set and create is true, a name is generated using the fullname template |
| startupProbe.httpGet.path | string | `"/http-metrics/-/ready"` | path for startup probe |
| startupProbe.httpGet.port | string | `"http"` | port for startup probe |
| tolerations | list | `[]` | tolerations for scheduler pod assignment |
| volumeMounts | list | `[]` | additional volume mounts |
| volumes | list | `[]` | additional volumes |
| workload.annotations | object | `{}` | annotations to add to the workload |
| workload.daemonSetSpec.updateStrategy | object | `{}` | an update strategy to replace existing DaemonSet pods with new pods |
| workload.deploymentSpec.replicas | int | `1` | number of desired pods |
| workload.deploymentSpec.strategy | object | `{}` | the deployment strategy to use to replace existing pods with new ones. |
| workload.kind | string | `"deployment"` | can be deployment, statefulSet or daemonSet |
| workload.labels | object | `{}` | labels to add to the workload |
| workload.statefulSetSpec.podManagementPolicy | string | `"OrderedReady"` | controls how pods are created during initial scale up |
| workload.statefulSetSpec.replicas | int | `1` | number of desired pods |
| workload.statefulSetSpec.updateStrategy | object | `{}` | indicates the StatefulSetUpdateStrategy that will be employed to update Pods in the StatefulSet when a revision is made to Template |
| workload.statefulSetSpec.volumeClaimTemplates | object | `{}` | a list of claims that pods are allowed to reference |
15 changes: 15 additions & 0 deletions charts/grafana-agent/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
1. Get the application URL by running these commands:
{{- if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "grafana-agent.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "grafana-agent.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "grafana-agent.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "grafana-agent.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80
{{- end }}
80 changes: 80 additions & 0 deletions charts/grafana-agent/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "grafana-agent.name" -}}
{{- 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 "grafana-agent.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 -}}

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

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "grafana-agent.serviceAccountName" -}}
{{- if .Values.serviceAccount.create -}}
{{ default (include "grafana-agent.fullname" .) .Values.serviceAccount.name }}
{{- else -}}
{{ default "default" .Values.serviceAccount.name }}
{{- end -}}
{{- end -}}

{{/*
Create the tag for the docker image to use
*/}}
{{- define "grafana-agent.tag" -}}
{{- .Values.image.tag | default .Chart.AppVersion -}}
{{- end -}}

{{/*
grafana-agent.rawResource will create a resource template that can be
merged with each item in `.Values.additionalResources`.
*/}}
{{- define "grafana-agent.rawResource" -}}
metadata:
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
{{- end }}
72 changes: 72 additions & 0 deletions charts/grafana-agent/templates/_pod.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{{- define "grafana-agent.pod" -}}
metadata:
labels:
{{- include "grafana-agent.selectorLabels" . | nindent 4 }}
annotations:
checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
{{- with .Values.podAnnotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 4 }}
{{- end }}
serviceAccountName: {{ include "grafana-agent.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 4 }}
containers:
- name: {{ .Chart.Name }}
{{- with .Values.args }}
args:
{{- toYaml . | nindent 8 }}
{{- end }}
securityContext:
{{- toYaml .Values.securityContext | nindent 8 }}
image: "{{ .Values.image.repository }}:{{ include "grafana-agent.tag" . }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.containerPorts }}
ports:
{{- toYaml . | nindent 8 }}
{{- end }}
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 8 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 8 }}
startupProbe:
{{- toYaml .Values.startupProbe | nindent 8 }}
resources:
{{- toYaml .Values.resources | nindent 8 }}
{{- with .Values.env }}
env:
{{- toYaml . | nindent 8 }}
{{- end }}
volumeMounts:
- name: {{ include "grafana-agent.fullname" . }}
mountPath: /grafana-agent.yaml
subPath: grafana-agent.yaml
{{- with .Values.volumeMounts }}
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: {{ include "grafana-agent.fullname" . }}
configMap:
name: {{ include "grafana-agent.fullname" . }}
defaultMode: 0644
{{- with .Values.volumes }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 4 }}
{{- end }}

{{- end -}}
5 changes: 5 additions & 0 deletions charts/grafana-agent/templates/additional-resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{- $template := fromYaml (include "grafana-agent.rawResource" .) -}}
{{- range $i, $t := .Values.additionalResources }}
---
{{ toYaml (merge (tpl $t $ | fromYaml) $template) -}}
{{- end }}
10 changes: 10 additions & 0 deletions charts/grafana-agent/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "grafana-agent.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
data:
grafana-agent.yaml: |-
{{ .Values.conf | nindent 4 }}
24 changes: 24 additions & 0 deletions charts/grafana-agent/templates/daemonset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if eq .Values.workload.kind "daemonSet" }}
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: {{ include "grafana-agent.fullname" . }}
namespace: {{ .Release.Namespace }}
{{- with .Values.workload.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
{{- .Values.workload.labels | toYaml . | nindent 4 }}
spec:
{{- with .Values.workload.daemonSetSpec.updateStrategy }}
updateStrategy:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- include "grafana-agent.selectorLabels" . | nindent 6 }}
template:
{{- include "grafana-agent.pod" . | nindent 4 }}
{{- end }}
25 changes: 25 additions & 0 deletions charts/grafana-agent/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if eq .Values.workload.kind "deployment" }}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "grafana-agent.fullname" . }}
namespace: {{ .Release.Namespace }}
{{- with .Values.workload.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
{{- .Values.workload.labels | toYaml . | nindent 4 }}
spec:
replicas: {{ .Values.workload.deploymentSpec.replicas }}
{{- with .Values.workload.deploymentSpec.strategy }}
strategy:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- include "grafana-agent.selectorLabels" . | nindent 6 }}
template:
{{- include "grafana-agent.pod" . | nindent 4 }}
{{- end }}
19 changes: 19 additions & 0 deletions charts/grafana-agent/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "grafana-agent.fullname" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
{{- with .Values.service.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
type: {{ .Values.service.type }}
{{- with .Values.service.ports }}
ports:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
{{- include "grafana-agent.selectorLabels" . | nindent 4 }}
13 changes: 13 additions & 0 deletions charts/grafana-agent/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "grafana-agent.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end -}}
34 changes: 34 additions & 0 deletions charts/grafana-agent/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- if eq .Values.workload.kind "statefulSet" }}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "grafana-agent.fullname" . }}
namespace: {{ .Release.Namespace }}
{{- with .Values.workload.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
{{- .Values.workload.labels | toYaml . | nindent 4 }}
spec:
replicas: {{ .Values.workload.statefulSetSpec.replicas }}
{{- with .Values.workload.statefulSetSpec.updateStrategy }}
updateStrategy:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.workload.statefulSetSpec.podManagementPolicy }}
podManagementPolicy:
{{- toYaml . | nindent 4 }}
{{- end }}
selector:
matchLabels:
{{- include "grafana-agent.selectorLabels" . | nindent 6 }}
serviceName: {{ include "grafana-agent.fullname" . }}
template:
{{- include "grafana-agent.pod" . | nindent 4 }}
{{- with .Values.workload.statefulSetSpec.volumeClaimTemplates }}
volumeClaimTemplates:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit e9fe43f

Please sign in to comment.