From 79a67b21229d6247abb6c5ba8905807239ddcb83 Mon Sep 17 00:00:00 2001 From: Ben Donnelly Date: Thu, 11 Apr 2024 11:59:13 +0100 Subject: [PATCH] feat(statefulset): change deployment to use stateful set - add support for override config --- charts/mimir-singleton/Chart.yaml | 2 +- charts/mimir-singleton/templates/_helpers.tpl | 20 ++- .../templates/configmap-runtime.yaml | 12 ++ .../mimir-singleton/templates/deployment.yaml | 80 ----------- .../templates/statefulset.yaml | 133 ++++++++++++++++++ charts/mimir-singleton/values.yaml | 64 ++++++++- 6 files changed, 227 insertions(+), 84 deletions(-) create mode 100644 charts/mimir-singleton/templates/configmap-runtime.yaml delete mode 100644 charts/mimir-singleton/templates/deployment.yaml create mode 100644 charts/mimir-singleton/templates/statefulset.yaml diff --git a/charts/mimir-singleton/Chart.yaml b/charts/mimir-singleton/Chart.yaml index 801c89e..ad4f173 100644 --- a/charts/mimir-singleton/Chart.yaml +++ b/charts/mimir-singleton/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.5 +version: 0.2.0 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/mimir-singleton/templates/_helpers.tpl b/charts/mimir-singleton/templates/_helpers.tpl index abd1a32..0cdf763 100644 --- a/charts/mimir-singleton/templates/_helpers.tpl +++ b/charts/mimir-singleton/templates/_helpers.tpl @@ -66,4 +66,22 @@ Calculate the config from structured and unstructured text input */}} {{- define "mimir-singleton.calculatedConfig" -}} {{ tpl (mergeOverwrite (tpl .Values.config.config . | fromYaml) .Values.config.structuredConfig | toYaml) . }} -{{- end -}} \ No newline at end of file +{{- end -}} + +{{/* +Renders the overrides config +*/}} +{{- define "mimir-singleton.overridesConfig" -}} +{{ tpl .Values.overrides.overrides . }} +{{- end -}} + +{{/* +The volume to mount for tempo runtime configuration +*/}} +{{- define "mimir-singleton.runtimeVolume" -}} +configMap: + name: {{ tpl .Values.overrides.externalRuntimeConfigName . }} + items: + - key: "overrides.yaml" + path: "overrides.yaml" +{{- end -}} diff --git a/charts/mimir-singleton/templates/configmap-runtime.yaml b/charts/mimir-singleton/templates/configmap-runtime.yaml new file mode 100644 index 0000000..327a58d --- /dev/null +++ b/charts/mimir-singleton/templates/configmap-runtime.yaml @@ -0,0 +1,12 @@ +{{- if not .Values.overrides.useExternalConfig }} +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ tpl .Values.overrides.externalRuntimeConfigName . }} + labels: + {{- include "mimir-singleton.labels" . | nindent 4 }} + namespace: {{ .Release.Namespace | quote }} +data: + overrides.yaml: | + {{ include "mimir-singleton.overridesConfig" . | nindent 4 }} +{{- end }} \ No newline at end of file diff --git a/charts/mimir-singleton/templates/deployment.yaml b/charts/mimir-singleton/templates/deployment.yaml deleted file mode 100644 index 88d9573..0000000 --- a/charts/mimir-singleton/templates/deployment.yaml +++ /dev/null @@ -1,80 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: {{ include "mimir-singleton.fullname" . }} - labels: - {{- include "mimir-singleton.labels" . | nindent 4 }} -spec: - {{- if not .Values.autoscaling.enabled }} - replicas: {{ .Values.replicaCount }} - {{- end }} - selector: - matchLabels: - {{- include "mimir-singleton.selectorLabels" . | nindent 6 }} - template: - metadata: - {{- with .Values.podAnnotations }} - annotations: - {{- toYaml . | nindent 8 }} - {{- end }} - labels: - {{- include "mimir-singleton.labels" . | nindent 8 }} - {{- with .Values.podLabels }} - {{- toYaml . | nindent 8 }} - {{- end }} - spec: - {{- with .Values.imagePullSecrets }} - imagePullSecrets: - {{- toYaml . | nindent 8 }} - {{- end }} - serviceAccountName: {{ include "mimir-singleton.serviceAccountName" . }} - securityContext: - {{- toYaml .Values.podSecurityContext | nindent 8 }} - containers: - - name: {{ .Chart.Name }} - securityContext: - {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.image.pullPolicy }} - args: - - --config.file - - /etc/mimir/mimir.yaml - ports: - - name: http - containerPort: {{ .Values.service.port }} - protocol: TCP - livenessProbe: - httpGet: - path: /ready - port: http - readinessProbe: - httpGet: - path: /ready - port: http - resources: - {{- toYaml .Values.resources | nindent 12 }} - volumeMounts: - - name: config - mountPath: "/etc/mimir" - {{- with .Values.volumeMounts }} - {{- toYaml . | nindent 12 }} - {{- end }} - volumes: - - name: config - configMap: - name: {{ include "mimir-singleton.fullname" . }} - {{- with .Values.volumes }} - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.nodeSelector }} - nodeSelector: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.affinity }} - affinity: - {{- toYaml . | nindent 8 }} - {{- end }} - {{- with .Values.tolerations }} - tolerations: - {{- toYaml . | nindent 8 }} - {{- end }} diff --git a/charts/mimir-singleton/templates/statefulset.yaml b/charts/mimir-singleton/templates/statefulset.yaml new file mode 100644 index 0000000..13a034b --- /dev/null +++ b/charts/mimir-singleton/templates/statefulset.yaml @@ -0,0 +1,133 @@ +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: {{ template "mimir-singleton.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + {{- include "mimir-singleton.labels" . | nindent 4 }} + {{- with .Values.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + replicas: {{ .Values.replicaCount }} + {{- if .Values.revisionHistoryLimit }} + revisionHistoryLimit: {{ .Values.revisionHistoryLimit }} + {{- end }} + selector: + matchLabels: + {{- include "mimir-singleton.selectorLabels" . | nindent 6 }} + serviceName: {{ template "mimir-singleton.fullname" . }}-headless + template: + metadata: + labels: + {{- include "mimir-singleton.selectorLabels" . | nindent 8 }} + {{- with .Values.podLabels }} + {{- toYaml . | nindent 8 }} + {{- end }} + annotations: + checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} + {{- with .Values.podAnnotations }} + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + serviceAccountName: {{ include "mimir-singleton.serviceAccountName" . }} + automountServiceAccountToken: {{ .Values.serviceAccount.automountServiceAccountToken }} + {{- with .Values.priorityClassName }} + priorityClassName: {{ . }} + {{- end }} + containers: + - args: + - --config.file=/conf/mimir.yaml + - --runtime-config.file=/runtime-config/overrides.yaml + {{- range $key, $value := .Values.extraArgs }} + - "-{{ $key }}{{ if $value }}={{ $value }}{{ end }}" + {{- end }} + image: "{{.Values.image.registry}}/{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + name: mimir + ports: + - name: http + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: /ready + port: http + readinessProbe: + httpGet: + path: /ready + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 10 }} + {{- end }} + env: + {{- with .Values.extraEnv }} + {{- toYaml . | nindent 10 }} + {{- end }} + {{- with .Values.extraEnvFrom }} + envFrom: + {{- toYaml . | nindent 10 }} + {{- end }} + volumeMounts: + {{- if .Values.extraVolumeMounts -}} + {{ toYaml .Values.extraVolumeMounts | nindent 8 }} + {{- end }} + - mountPath: /conf + name: mimir-conf + - mountPath: /runtime-config + name: mimir-runtime-conf + - mountPath: /var/mimir + name: storage + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.securityContext }} + securityContext: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + {{- if .Values.extraVolumes -}} + {{ toYaml .Values.extraVolumes | nindent 12 }} + {{- end }} + - name: mimir-conf + configMap: + name: {{ include "mimir-singleton.fullname" . }} + items: + - key: "mimir.yaml" + path: "mimir.yaml" + - name: mimir-runtime-conf + {{- include "mimir-singleton.runtimeVolume" . | nindent 12 }} + {{- if not .Values.persistence.enabled }} + - name: storage + emptyDir: { } + {{- end }} + updateStrategy: + type: {{- toYaml .Values.updateStrategy | nindent 6 }} + {{- if .Values.persistence.enabled }} + volumeClaimTemplates: + - metadata: + name: storage + annotations: {{- toYaml .Values.persistence.annotations | nindent 10 }} + spec: + accessModes: {{- toYaml .Values.persistence.accessModes | nindent 10 }} + resources: + requests: + storage: {{ .Values.persistence.size | quote }} + storageClassName: {{ .Values.persistence.storageClassName }} + {{- if .Values.persistence.selector }} + selector: {{- toYaml .Values.persistence.selector | nindent 10 }} + {{- end }} + {{- end }} \ No newline at end of file diff --git a/charts/mimir-singleton/values.yaml b/charts/mimir-singleton/values.yaml index cb107f8..70d0862 100644 --- a/charts/mimir-singleton/values.yaml +++ b/charts/mimir-singleton/values.yaml @@ -26,8 +26,15 @@ serviceAccount: # The name of the service account to use. # If not set and create is true, a name is generated using the fullname template name: "" + automountServiceAccountToken: true +## The update strategy to use when deploying new versions +updateStrategy: RollingUpdate +## Annotations for the stateful set +annotations: {} +## Annotations for the pod podAnnotations: {} +## Labels for the pod podLabels: {} podSecurityContext: {} @@ -61,6 +68,30 @@ ingress: # hosts: # - chart-example.local +## Additional container arguments +extraArgs: {} +## -- Environment variables to add, can be in the form of key values, using valueFrom or other kubernetes forms. +## - name: SOME_ENV +## value: some-value +## - name: SOME_KEY_IN_CONFIG +## valueFrom: +## configMapKeyRef: +## name: some-config +## key: KEY_IN_CONFIG +extraEnv: [] +## -- Environment variables from secrets or configmaps to add to the pod +## - configMapRef: +## name: some-config +extraEnvFrom: [] +## -- Volume mounts to add +## - name: extra-volume +## mountPath: /mnt/volume +## readOnly: true +## existingClaim: volume-claim +extraVolumeMounts: [] +# -- Volumes to add +extraVolumes: [] + resources: {} # We usually recommend not to specify default resources and to leave this as a conscious # choice for the user. This also increases chances charts run on environments with little @@ -140,12 +171,14 @@ config: kvstore: store: memberlist + alertmanager: + web: + external_url: {{ .Values.alertManager.external_url }} + alertmanager_storage: backend: local local: path: /tmp/mimir/alertmanager - web: - external_url: {{ .Values.alertManager.external_url }} ingester: ring: @@ -167,9 +200,36 @@ config: structuredConfig: {} +## The configuration for mimir overrides module +overrides: + ## Configuration is loaded from the secret called 'externalConfigSecretName'. + ## If 'useExternalConfig' is true, then the configuration is not generated, just + ## consumed. + useExternalConfig: false + # -- Name of the Secret or ConfigMap that contains the runtime configuration (used for naming even if config is internal). + externalRuntimeConfigName: runtime-config + overrides: | + overrides: {} + alertManager: external_url: http://localhost:9009/alertmanager +# Should we use a persistent volume with the pod +persistence: + # Enabled persistent volume + enabled: false + # Custom annotations to apply to the volume claim + annotations: {} + # Custom selector to apply to the volume claim + selector: + ## Optionally set the storage class name, if not set the cluster default will be used + storageClassName: + ## Set the access modes for the persistence volume + accessModes: + - ReadWriteOnce + ## The size of the volume to use + size: 10Gi + monitoring: enabled: false # The config for the service monitor