Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(helm): add lifecycle hooks to alloy container #1774

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion operations/helm/charts/alloy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ internal API changes are not present.
Unreleased
----------

### Enhancements

- Add lifecyle hook to the Helm chart. (@etiennep)
- Add terminationGracePeriodSeconds setting to the Helm chart. (@etiennep)

0.8.1 (2024-09-26)
------------------

Expand Down Expand Up @@ -118,4 +123,4 @@ Unreleased
- Introduce a Grafana Alloy Helm chart. The Grafana Alloy Helm chart is
backwards compatibile with the values.yaml from the `grafana-agent` Helm
chart. Review the Helm chart README for a description on how to migrate.
(@rfratto)
(@rfratto)
2 changes: 1 addition & 1 deletion operations/helm/charts/alloy/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: alloy
description: 'Grafana Alloy'
type: application
version: 0.8.1
version: 0.9.0
appVersion: 'v1.4.1'
icon: https://raw.githubusercontent.com/grafana/alloy/main/docs/sources/assets/alloy_icon_orange.svg

Expand Down
4 changes: 3 additions & 1 deletion operations/helm/charts/alloy/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Grafana Alloy Helm chart

![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![Version: 0.8.1](https://img.shields.io/badge/Version-0.8.1-informational?style=flat-square) ![AppVersion: v1.4.1](https://img.shields.io/badge/AppVersion-v1.4.1-informational?style=flat-square)
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![Version: 0.9.0](https://img.shields.io/badge/Version-0.9.0-informational?style=flat-square) ![AppVersion: v1.4.1](https://img.shields.io/badge/AppVersion-v1.4.1-informational?style=flat-square)

Helm chart for deploying [Grafana Alloy][] to Kubernetes.

Expand Down Expand Up @@ -45,6 +45,7 @@ useful if just using the default DaemonSet isn't sufficient.
| alloy.extraArgs | list | `[]` | Extra args to pass to `alloy run`: https://grafana.com/docs/alloy/latest/reference/cli/run/ |
| alloy.extraEnv | list | `[]` | Extra environment variables to pass to the Alloy container. |
| alloy.extraPorts | list | `[]` | Extra ports to expose on the Alloy container. |
| alloy.lifecycle | object | `{}` | Set lifecycle hooks for the Grafana Alloy container. |
| alloy.listenAddr | string | `"0.0.0.0"` | Address to listen for traffic on. 0.0.0.0 exposes the UI to other containers. |
| alloy.listenPort | int | `12345` | Port to listen for traffic on. |
| alloy.listenScheme | string | `"HTTP"` | Scheme is needed for readiness probes. If enabling tls in your configs, set to "HTTPS" |
Expand Down Expand Up @@ -93,6 +94,7 @@ useful if just using the default DaemonSet isn't sufficient.
| controller.podLabels | object | `{}` | Extra pod labels to add. |
| controller.priorityClassName | string | `""` | priorityClassName to apply to Grafana Alloy pods. |
| controller.replicas | int | `1` | Number of pods to deploy. Ignored when controller.type is 'daemonset'. |
| controller.terminationGracePeriodSeconds | string | `nil` | Termination grace period in seconds for the Grafana Alloy pods. The default value used by Kubernetes if unspecifed is 30 seconds. |
| controller.tolerations | list | `[]` | Tolerations to apply to Grafana Alloy pods. |
| controller.topologySpreadConstraints | list | `[]` | Topology Spread Constraints to apply to Grafana Alloy pods. |
| controller.type | string | `"daemonset"` | Type of controller to use for deploying Grafana Alloy in the cluster. Must be one of 'daemonset', 'deployment', or 'statefulset'. |
Expand Down
8 changes: 8 additions & 0 deletions operations/helm/charts/alloy/ci/lifecycle-hooks-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
controller:
type: deployment

alloy:
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 1"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
controller:
type: deployment
terminationGracePeriodSeconds: 20
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
resources:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with $values.lifecycle }}
lifecycle:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with $values.securityContext }}
securityContext:
{{- toYaml . | nindent 4 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ spec:
affinity:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- if .Values.controller.terminationGracePeriodSeconds }}
terminationGracePeriodSeconds: {{ .Values.controller.terminationGracePeriodSeconds | int }}
{{- end }}
{{- with .Values.controller.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 4 }}
Expand Down
12 changes: 12 additions & 0 deletions operations/helm/charts/alloy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ alloy:
# -- Resource requests and limits to apply to the Grafana Alloy container.
resources: {}

# -- Set lifecycle hooks for the Grafana Alloy container.
lifecycle: {}
# preStop:
# exec:
# command:
# - /bin/sleep
# - "10"

image:
# -- Grafana Alloy image registry (defaults to docker.io)
registry: "docker.io"
Expand Down Expand Up @@ -183,6 +191,10 @@ controller:
# -- Configures the DNS policy for the pod. https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy
dnsPolicy: ClusterFirst

# -- Termination grace period in seconds for the Grafana Alloy pods.
# The default value used by Kubernetes if unspecifed is 30 seconds.
terminationGracePeriodSeconds: null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have a default value? 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Kubernetes documentation, the default is 30s. https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/

I will add a note to the comment.


# -- Update strategy for updating deployed Pods.
updateStrategy: {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# Source: alloy/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: alloy
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: config
data:
config.alloy: |-
logging {
level = "info"
format = "logfmt"
}

discovery.kubernetes "pods" {
role = "pod"
}

discovery.kubernetes "nodes" {
role = "node"
}

discovery.kubernetes "services" {
role = "service"
}

discovery.kubernetes "endpoints" {
role = "endpoints"
}

discovery.kubernetes "endpointslices" {
role = "endpointslice"
}

discovery.kubernetes "ingresses" {
role = "ingress"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
# Source: alloy/templates/controllers/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: alloy
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
minReadySeconds: 10
selector:
matchLabels:
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: alloy
labels:
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
spec:
serviceAccountName: alloy
containers:
- name: alloy
image: docker.io/grafana/alloy:v1.4.1
imagePullPolicy: IfNotPresent
args:
- run
- /etc/alloy/config.alloy
- --storage.path=/tmp/alloy
- --server.http.listen-addr=0.0.0.0:12345
- --server.http.ui-path-prefix=/
- --stability.level=generally-available
env:
- name: ALLOY_DEPLOY_MODE
value: "helm"
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
ports:
- containerPort: 12345
name: http-metrics
readinessProbe:
httpGet:
path: /-/ready
port: 12345
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
lifecycle:
preStop:
exec:
command:
- /bin/sh
- -c
- sleep 1
volumeMounts:
- name: config
mountPath: /etc/alloy
- name: config-reloader
image: ghcr.io/jimmidyson/configmap-reload:v0.12.0
args:
- --volume-dir=/etc/alloy
- --webhook-url=http://localhost:12345/-/reload
volumeMounts:
- name: config
mountPath: /etc/alloy
resources:
requests:
cpu: 1m
memory: 5Mi
dnsPolicy: ClusterFirst
volumes:
- name: config
configMap:
name: alloy
119 changes: 119 additions & 0 deletions operations/helm/tests/lifecycle-hooks/alloy/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
# Source: alloy/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: alloy
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: rbac
rules:
# Rules which allow discovery.kubernetes to function.
- apiGroups:
- ""
- "discovery.k8s.io"
- "networking.k8s.io"
resources:
- endpoints
- endpointslices
- ingresses
- nodes
- nodes/proxy
- nodes/metrics
- pods
- services
verbs:
- get
- list
- watch
# Rules which allow loki.source.kubernetes and loki.source.podlogs to work.
- apiGroups:
- ""
resources:
- pods
- pods/log
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- "monitoring.grafana.com"
resources:
- podlogs
verbs:
- get
- list
- watch
# Rules which allow mimir.rules.kubernetes to work.
- apiGroups: ["monitoring.coreos.com"]
resources:
- prometheusrules
verbs:
- get
- list
- watch
- nonResourceURLs:
- /metrics
verbs:
- get
# Rules for prometheus.kubernetes.*
- apiGroups: ["monitoring.coreos.com"]
resources:
- podmonitors
- servicemonitors
- probes
verbs:
- get
- list
- watch
# Rules which allow eventhandler to work.
- apiGroups:
- ""
resources:
- events
verbs:
- get
- list
- watch
# needed for remote.kubernetes.*
- apiGroups: [""]
resources:
- "configmaps"
- "secrets"
verbs:
- get
- list
- watch
# needed for otelcol.processor.k8sattributes
- apiGroups: ["apps"]
resources: ["replicasets"]
verbs: ["get", "list", "watch"]
- apiGroups: ["extensions"]
resources: ["replicasets"]
verbs: ["get", "list", "watch"]
---
# Source: alloy/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: alloy
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: rbac
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: alloy
subjects:
- kind: ServiceAccount
name: alloy
namespace: default
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
# Source: alloy/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: alloy
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: networking
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
internalTrafficPolicy: Cluster
ports:
- name: http-metrics
port: 12345
targetPort: 12345
protocol: "TCP"
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# Source: alloy/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: alloy
namespace: default
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: rbac
Loading
Loading