From af93f4a11ea3b4d65eef60ebeba552dcec8801ec Mon Sep 17 00:00:00 2001 From: openbob Date: Wed, 18 Jan 2023 18:00:07 +0000 Subject: [PATCH] Helm: Add Table Manager support to Loki helm chart (#8098) The Table Manager is a Loki component which takes care of creating a periodic table before its time period begins, and deleting it once its data time range exceeds the retention period. This PR is to add Table Manager support to the loki helm chart deployment as the current chart is based on the deprecated loki-simple-scalable chart that did not support Table Manager. Fixes #<6830> --- docs/sources/installation/helm/reference.md | 180 ++++++++++++++++++ .../table-manager/_helpers-table-manager.tpl | 32 ++++ .../deployment-table-manager.yaml | 112 +++++++++++ .../table-manager/service-table-manager.yaml | 30 +++ .../servicemonitor-table-manager.yaml | 57 ++++++ production/helm/loki/values.yaml | 62 ++++++ 6 files changed, 473 insertions(+) create mode 100644 production/helm/loki/templates/table-manager/_helpers-table-manager.tpl create mode 100644 production/helm/loki/templates/table-manager/deployment-table-manager.yaml create mode 100644 production/helm/loki/templates/table-manager/service-table-manager.yaml create mode 100644 production/helm/loki/templates/table-manager/servicemonitor-table-manager.yaml diff --git a/docs/sources/installation/helm/reference.md b/docs/sources/installation/helm/reference.md index ea3dbbdb0e..bf56020fcd 100644 --- a/docs/sources/installation/helm/reference.md +++ b/docs/sources/installation/helm/reference.md @@ -3145,6 +3145,186 @@ null
 []
 
+ + + + tableManager.affinity + string + Affinity for table-manager pods. Passed through `tpl` and, thus, to be configured as string +
+Hard node and soft zone anti-affinity
+
+ + + + tableManager.command + string + Command to execute instead of defined in Docker image +
+null
+
+ + + + tableManager.enabled + bool + Specifies whether the table-manager should be enabled +
+false
+
+ + + + tableManager.extraArgs + list + Additional CLI args for the table-manager +
+[]
+
+ + + + tableManager.extraContainers + list + Containers to add to the table-manager pods +
+[]
+
+ + + + tableManager.extraEnv + list + Environment variables to add to the table-manager pods +
+[]
+
+ + + + tableManager.extraEnvFrom + list + Environment variables from secrets or configmaps to add to the table-manager pods +
+[]
+
+ + + + tableManager.extraVolumeMounts + list + Volume mounts to add to the table-manager pods +
+[]
+
+ + + + tableManager.extraVolumes + list + Volumes to add to the table-manager pods +
+[]
+
+ + + + tableManager.image.registry + string + The Docker registry for the table-manager image. Overrides `loki.image.registry` +
+null
+
+ + + + tableManager.image.repository + string + Docker image repository for the table-manager image. Overrides `loki.image.repository` +
+null
+
+ + + + tableManager.image.tag + string + Docker image tag for the table-manager image. Overrides `loki.image.tag` +
+null
+
+ + + + tableManager.nodeSelector + object + Node selector for table-manager pods +
+{}
+
+ + + + tableManager.podAnnotations + object + Annotations for table-manager pods +
+{}
+
+ + + + tableManager.podLabels + object + Labels for table-manager pods +
+{}
+
+ + + + tableManager.priorityClassName + string + The name of the PriorityClass for table-manager pods +
+null
+
+ + + + tableManager.resources + object + Resource requests and limits for the table-manager +
+{}
+
+ + + + tableManager.serviceLabels + object + Labels for table-manager service +
+{}
+
+ + + + tableManager.terminationGracePeriodSeconds + int + Grace period to allow the table-manager to shutdown before it is killed +
+30
+
+ + + + tableManager.tolerations + list + Tolerations for table-manager pods +
+[]
+
diff --git a/production/helm/loki/templates/table-manager/_helpers-table-manager.tpl b/production/helm/loki/templates/table-manager/_helpers-table-manager.tpl new file mode 100644 index 0000000000..ff258321c1 --- /dev/null +++ b/production/helm/loki/templates/table-manager/_helpers-table-manager.tpl @@ -0,0 +1,32 @@ +{{/* +table-manager fullname +*/}} +{{- define "loki.tableManagerFullname" -}} +{{ include "loki.fullname" . }}-table-manager +{{- end }} + +{{/* +table-manager common labels +*/}} +{{- define "loki.tableManagerLabels" -}} +{{ include "loki.labels" . }} +app.kubernetes.io/component: table-manager +{{- end }} + +{{/* +table-manager selector labels +*/}} +{{- define "loki.tableManagerSelectorLabels" -}} +{{ include "loki.selectorLabels" . }} +app.kubernetes.io/component: table-manager +{{- end }} + +{{/* +table-manager priority class name +*/}} +{{- define "loki.tableManagerPriorityClassName" -}} +{{- $pcn := coalesce .Values.global.priorityClassName .Values.tableManager.priorityClassName -}} +{{- if $pcn }} +priorityClassName: {{ $pcn }} +{{- end }} +{{- end }} diff --git a/production/helm/loki/templates/table-manager/deployment-table-manager.yaml b/production/helm/loki/templates/table-manager/deployment-table-manager.yaml new file mode 100644 index 0000000000..f5529ebec6 --- /dev/null +++ b/production/helm/loki/templates/table-manager/deployment-table-manager.yaml @@ -0,0 +1,112 @@ +{{- if .Values.tableManager.enabled }} +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "loki.tableManagerFullname" . }} + labels: + {{- include "loki.tableManagerLabels" . | nindent 4 }} + {{- with .Values.loki.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + replicas: 1 + revisionHistoryLimit: {{ .Values.loki.revisionHistoryLimit }} + selector: + matchLabels: + {{- include "loki.tableManagerSelectorLabels" . | nindent 6 }} + template: + metadata: + annotations: + checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- with .Values.loki.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tableManager.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "loki.tableManagerSelectorLabels" . | nindent 8 }} + {{- with .Values.loki.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tableManager.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "loki.serviceAccountName" . }} + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- include "loki.tableManagerPriorityClassName" . | nindent 6 }} + securityContext: + {{- toYaml .Values.loki.podSecurityContext | nindent 8 }} + terminationGracePeriodSeconds: {{ .Values.tableManager.terminationGracePeriodSeconds }} + containers: + - name: table-manager + image: {{ include "loki.image" . }} + imagePullPolicy: {{ .Values.loki.image.pullPolicy }} + args: + - -config.file=/etc/loki/config/config.yaml + - -target=table-manager + {{- with .Values.tableManager.extraArgs }} + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: http-metrics + containerPort: 3100 + protocol: TCP + - name: grpc + containerPort: 9095 + protocol: TCP + {{- with .Values.tableManager.extraEnv }} + env: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with .Values.tableManager.extraEnvFrom }} + envFrom: + {{- toYaml . | nindent 12 }} + {{- end }} + securityContext: + {{- toYaml .Values.loki.containerSecurityContext | nindent 12 }} + readinessProbe: + {{- toYaml .Values.loki.readinessProbe | nindent 12 }} + livenessProbe: + {{- toYaml .Values.loki.livenessProbe | nindent 12 }} + volumeMounts: + - name: config + mountPath: /etc/loki/config + {{- with .Values.tableManager.extraVolumeMounts }} + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.tableManager.resources | nindent 12 }} + {{- if .Values.tableManager.extraContainers }} + {{- toYaml .Values.tableManager.extraContainers | nindent 8}} + {{- end }} + {{- with .Values.tableManager.affinity }} + affinity: + {{- tpl . $ | nindent 8 }} + {{- end }} + {{- with .Values.tableManager.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tableManager.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: config + {{- if .Values.loki.existingSecretForConfig }} + secret: + secretName: {{ .Values.loki.existingSecretForConfig }} + {{- else }} + configMap: + name: {{ include "loki.fullname" . }} + {{- end }} + {{- with .Values.tableManager.extraVolumes }} + {{- toYaml . | nindent 8 }} + {{- end }} +{{- end }} diff --git a/production/helm/loki/templates/table-manager/service-table-manager.yaml b/production/helm/loki/templates/table-manager/service-table-manager.yaml new file mode 100644 index 0000000000..46731204cc --- /dev/null +++ b/production/helm/loki/templates/table-manager/service-table-manager.yaml @@ -0,0 +1,30 @@ +{{- if .Values.tableManager.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "loki.fullname" . }}-table-manager + labels: + {{- include "loki.labels" . | nindent 4 }} + {{- with .Values.tableManager.serviceLabels }} + {{- toYaml . | nindent 4 }} + {{- end }} + app.kubernetes.io/component: table-manager + {{- with .Values.loki.serviceAnnotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + type: ClusterIP + ports: + - name: http-metrics + port: 3100 + targetPort: http-metrics + protocol: TCP + - name: grpc + port: 9095 + targetPort: grpc + protocol: TCP + selector: + {{- include "loki.selectorLabels" . | nindent 4 }} + app.kubernetes.io/component: table-manager +{{- end }} diff --git a/production/helm/loki/templates/table-manager/servicemonitor-table-manager.yaml b/production/helm/loki/templates/table-manager/servicemonitor-table-manager.yaml new file mode 100644 index 0000000000..09aa7279f1 --- /dev/null +++ b/production/helm/loki/templates/table-manager/servicemonitor-table-manager.yaml @@ -0,0 +1,57 @@ +{{- if .Values.tableManager.enabled }} +{{- with .Values.serviceMonitor }} +{{- if .enabled }} +apiVersion: monitoring.coreos.com/v1 +kind: ServiceMonitor +metadata: + name: {{ include "loki.tableManagerFullname" $ }} + {{- with .namespace }} + namespace: {{ . }} + {{- end }} + {{- with .annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} + labels: + {{- include "loki.tableManagerLabels" $ | nindent 4 }} + {{- with .labels }} + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- with .namespaceSelector }} + namespaceSelector: + {{- toYaml . | nindent 4 }} + {{- end }} + selector: + matchLabels: + {{- include "loki.tableManagerSelectorLabels" $ | nindent 6 }} + endpoints: + - port: http-metrics + {{- with .interval }} + interval: {{ . }} + {{- end }} + {{- with .scrapeTimeout }} + scrapeTimeout: {{ . }} + {{- end }} + {{- with .relabelings }} + relabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .metricRelabelings }} + metricRelabelings: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .scheme }} + scheme: {{ . }} + {{- end }} + {{- with .tlsConfig }} + tlsConfig: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .targetLabels }} + targetLabels: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} +{{- end }} +{{- end }} diff --git a/production/helm/loki/values.yaml b/production/helm/loki/values.yaml index 938467f84b..f93d11be8e 100644 --- a/production/helm/loki/values.yaml +++ b/production/helm/loki/values.yaml @@ -141,6 +141,10 @@ loki: {{ include "loki.rulerConfig" . }} + table_manager: + retention_deletes_enabled: false + retention_period: 0 + {{- with .Values.loki.memcached.results_cache }} query_range: align_queries_with_step: true @@ -689,6 +693,64 @@ write: # -- Selector for persistent disk selector: null +# Configuration for the table-manager +tableManager: + # -- Specifies whether the table-manager should be enabled + enabled: false + image: + # -- The Docker registry for the table-manager image. Overrides `loki.image.registry` + registry: null + # -- Docker image repository for the table-manager image. Overrides `loki.image.repository` + repository: null + # -- Docker image tag for the table-manager image. Overrides `loki.image.tag` + tag: null + # -- Command to execute instead of defined in Docker image + command: null + # -- The name of the PriorityClass for table-manager pods + priorityClassName: null + # -- Labels for table-manager pods + podLabels: {} + # -- Annotations for table-manager pods + podAnnotations: {} + # -- Labels for table-manager service + serviceLabels: {} + # -- Additional CLI args for the table-manager + extraArgs: [] + # -- Environment variables to add to the table-manager pods + extraEnv: [] + # -- Environment variables from secrets or configmaps to add to the table-manager pods + extraEnvFrom: [] + # -- Volume mounts to add to the table-manager pods + extraVolumeMounts: [] + # -- Volumes to add to the table-manager pods + extraVolumes: [] + # -- Resource requests and limits for the table-manager + resources: {} + # -- Containers to add to the table-manager pods + extraContainers: [] + # -- Grace period to allow the table-manager to shutdown before it is killed + terminationGracePeriodSeconds: 30 + # -- Affinity for table-manager pods. Passed through `tpl` and, thus, to be configured as string + # @default -- Hard node and soft zone anti-affinity + affinity: | + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchLabels: + {{- include "loki.tableManagerSelectorLabels" . | nindent 10 }} + topologyKey: kubernetes.io/hostname + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchLabels: + {{- include "loki.tableManagerSelectorLabels" . | nindent 12 }} + topologyKey: failure-domain.beta.kubernetes.io/zone + # -- Node selector for table-manager pods + nodeSelector: {} + # -- Tolerations for table-manager pods + tolerations: [] + # Configuration for the read pod(s) read: # -- Number of replicas for the read