Skip to content

Commit

Permalink
feat(statefulset): change deployment to use stateful set
Browse files Browse the repository at this point in the history
 - add support for override config
  • Loading branch information
Umaaz committed Apr 11, 2024
1 parent e8f2aa2 commit 79a67b2
Show file tree
Hide file tree
Showing 6 changed files with 227 additions and 84 deletions.
2 changes: 1 addition & 1 deletion charts/mimir-singleton/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion charts/mimir-singleton/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
{{- 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 -}}
12 changes: 12 additions & 0 deletions charts/mimir-singleton/templates/configmap-runtime.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
80 changes: 0 additions & 80 deletions charts/mimir-singleton/templates/deployment.yaml

This file was deleted.

133 changes: 133 additions & 0 deletions charts/mimir-singleton/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
64 changes: 62 additions & 2 deletions charts/mimir-singleton/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down

0 comments on commit 79a67b2

Please sign in to comment.