Skip to content

Commit

Permalink
[Helm] configStorageType value support (#8526)
Browse files Browse the repository at this point in the history
**What this PR does / why we need it**:
Adds `loki.configStorageType` & `loki.externalConfigSecretName` values
and associated helpers and templates to support choosing either
`ConfigMap` or `Secret` as config medium types.

**Which issue(s) this PR fixes**:
Fixes #8268 

**Special notes for your reviewer**:

**Checklist**
- [x] Reviewed the
[`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md)
guide (**required**)
- [x] Documentation added
- [ ] Tests updated
- [x] `CHANGELOG.md` updated
- [ ] Changes that require user attention or interaction to upgrade are
documented in `docs/sources/upgrading/_index.md`

---------

Signed-off-by: garcia.ryan <garcia.ryan@solute.us>
Co-authored-by: Stefan Büringer <4662360+sbueringer@users.noreply.github.com>
Co-authored-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
  • Loading branch information
3 people committed May 26, 2023
1 parent 41c19ec commit 028c12f
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 23 deletions.
18 changes: 18 additions & 0 deletions docs/sources/installation/helm/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,15 @@ true
<td><pre lang="">
See values.yaml
</pre>
</td>
</tr>
<tr>
<td>loki.configStorageType</td>
<td>string</td>
<td>Defines what kind of object stores the configuration, a ConfigMap or a Secret. In order to move sensitive information (such as credentials) from the ConfigMap/Secret to a more secure location (e.g. vault), it is possible to use [environment variables in the configuration](https://grafana.com/docs/loki/latest/configuration/#use-environment-variables-in-the-configuration). Such environment variables can be then stored in a separate Secret and injected via the global.extraEnvFrom value. For details about environment injection from a Secret please see [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/#use-case-as-container-environment-variables).</td>
<td><pre lang="json">
"ConfigMap"
</pre>
</td>
</tr>
<tr>
Expand Down Expand Up @@ -1795,6 +1804,15 @@ true
<td><pre lang="json">
""
</pre>
</td>
</tr>
<tr>
<td>loki.externalConfigSecretName</td>
<td>string</td>
<td>Name of the Secret or ConfigMap that contains the configuration (used for naming even if config is internal).</td>
<td><pre lang="json">
"{{ include \"loki.name\" . }}"
</pre>
</td>
</tr>
<tr>
Expand Down
5 changes: 5 additions & 0 deletions production/helm/loki/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ Entries should include a reference to the pull request that introduced the chang

[//]: # (<AUTOMATED_UPDATES_LOCATOR> : do not remove this line. This locator is used by the CI pipeline to automatically create a changelog entry for each new Loki release. Add other chart versions and respective changelog entries bellow this line.)

## 5.5.9

- [FEATURE] Add `loki.configStorageType` & `loki.externalConfigSecretName` values to chart and templates.

## 5.5.8

- [CHANGE] Add support for annotations on all Deployments and StatefulSets
Expand Down Expand Up @@ -41,6 +45,7 @@ Entries should include a reference to the pull request that introduced the chang

- [BUGFIX] Use $.Release.Namespace consistently
- [CHANGE] Add clusterLabelOverride for alert label overrides.
- [BUGFIX] Use $.Release.Namespace consistently

## 5.5.1

Expand Down
2 changes: 1 addition & 1 deletion production/helm/loki/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: loki
description: Helm chart for Grafana Loki in simple, scalable mode
type: application
appVersion: 2.8.2
version: 5.5.8
version: 5.5.9
home: https://grafana.github.io/helm-charts
sources:
- https://github.com/grafana/loki
Expand Down
2 changes: 1 addition & 1 deletion production/helm/loki/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# loki

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

Helm chart for Grafana Loki in simple, scalable mode

Expand Down
23 changes: 23 additions & 0 deletions production/helm/loki/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,29 @@ ruler:
{{- end }}
{{- end }}

{{/*
Calculate the config from structured and unstructred text input
*/}}
{{- define "loki.calculatedConfig" -}}
{{ tpl (mergeOverwrite (tpl .Values.loki.config . | fromYaml) .Values.loki.structuredConfig | toYaml) . }}
{{- end }}

{{/*
The volume to mount for loki configuration
*/}}
{{- define "loki.configVolume" -}}
{{- if eq .Values.loki.configStorageType "Secret" -}}
secret:
secretName: {{ tpl .Values.loki.externalConfigSecretName . }}
{{- else if eq .Values.loki.configStorageType "ConfigMap" -}}
configMap:
name: {{ tpl .Values.loki.externalConfigSecretName . }}
items:
- key: "config.yaml"
path: "config.yaml"
{{- end -}}
{{- end -}}

{{/*
Memcached Docker image
*/}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
template:
metadata:
annotations:
checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
{{- with .Values.loki.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -148,8 +148,7 @@ spec:
secret:
secretName: {{ .Values.loki.existingSecretForConfig }}
{{- else }}
configMap:
name: {{ include "loki.name" . }}
{{- include "loki.configVolume" . | nindent 10 }}
{{- end }}
- name: runtime-config
configMap:
Expand Down
20 changes: 20 additions & 0 deletions production/helm/loki/templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if not .Values.loki.existingSecretForConfig -}}
apiVersion: v1
{{- if eq .Values.loki.configStorageType "Secret" }}
kind: Secret
{{- else }}
kind: ConfigMap
{{- end }}
metadata:
name: {{ tpl .Values.loki.externalConfigSecretName . }}
labels:
{{- include "loki.labels" . | nindent 4 }}
{{- if eq .Values.loki.configStorageType "Secret" }}
data:
config.yaml: {{ include "loki.calculatedConfig" . | b64enc }}
{{- else }}
data:
config.yaml: |
{{ include "loki.calculatedConfig" . | nindent 4 }}
{{- end -}}
{{- end }}
12 changes: 0 additions & 12 deletions production/helm/loki/templates/configmap.yaml

This file was deleted.

5 changes: 2 additions & 3 deletions production/helm/loki/templates/read/deployment-read.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
template:
metadata:
annotations:
checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
{{- with .Values.loki.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -135,8 +135,7 @@ spec:
secret:
secretName: {{ .Values.loki.existingSecretForConfig }}
{{- else }}
configMap:
name: {{ include "loki.name" . }}
{{- include "loki.configVolume" . | nindent 10 }}
{{- end }}
- name: runtime-config
configMap:
Expand Down
5 changes: 2 additions & 3 deletions production/helm/loki/templates/write/statefulset-write.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ spec:
template:
metadata:
annotations:
checksum/config: {{ include (print .Template.BasePath "/configmap.yaml") . | sha256sum }}
checksum/config: {{ include (print .Template.BasePath "/config.yaml") . | sha256sum }}
{{- with .Values.loki.podAnnotations }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand Down Expand Up @@ -153,8 +153,7 @@ spec:
secret:
secretName: {{ .Values.loki.existingSecretForConfig }}
{{- else }}
configMap:
name: {{ include "loki.name" . }}
{{- include "loki.configVolume" . | nindent 10 }}
{{- end }}
- name: runtime-config
configMap:
Expand Down
6 changes: 6 additions & 0 deletions production/helm/loki/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ loki:
enableServiceLinks: true
# -- Specify an existing secret containing loki configuration. If non-empty, overrides `loki.config`
existingSecretForConfig: ""
# -- Defines what kind of object stores the configuration, a ConfigMap or a Secret.
# In order to move sensitive information (such as credentials) from the ConfigMap/Secret to a more secure location (e.g. vault), it is possible to use [environment variables in the configuration](https://grafana.com/docs/loki/latest/configuration/#use-environment-variables-in-the-configuration).
# Such environment variables can be then stored in a separate Secret and injected via the global.extraEnvFrom value. For details about environment injection from a Secret please see [Secrets](https://kubernetes.io/docs/concepts/configuration/secret/#use-case-as-container-environment-variables).
configStorageType: ConfigMap
# -- Name of the Secret or ConfigMap that contains the configuration (used for naming even if config is internal).
externalConfigSecretName: '{{ include "loki.name" . }}'
# -- Config file contents for Loki
# @default -- See values.yaml
config: |
Expand Down

0 comments on commit 028c12f

Please sign in to comment.