Skip to content

Commit

Permalink
Added mimir-provisioning chart
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasdc6 committed May 23, 2024
1 parent 1f61edb commit 388692b
Show file tree
Hide file tree
Showing 14 changed files with 503 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release Charts

on:
push:
branches:
- main

jobs:
release:
permissions:
contents: write
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "[email protected]"
- name: Install Helm
uses: azure/setup-helm@v4
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

- name: Run chart-releaser
uses: helm/[email protected]
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
23 changes: 23 additions & 0 deletions charts/mimir-provisioning/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
5 changes: 5 additions & 0 deletions charts/mimir-provisioning/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: mimir-provisioning
description: A Helm chart for Kubernetes
type: application
version: 0.1.0
68 changes: 68 additions & 0 deletions charts/mimir-provisioning/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Chart de aprovisionamiento de mimir

Este chart se utilizara para tareas de aprovisionamiento de mimir (como por
ejemplo la carga de rules).

En lineas generales funciona de la siguiente manera:

- Genera un conjunto de configmaps que se configuran mediante la clave
`provision`.

- Una vez que se instala el chart se crea un job con dos contenedores:

- Estos configmaps luego son levantados por un contenedor de
[k8s-sidecar-container](https://github.com/kiwigrid/k8s-sidecar) quien los
persiste en un volumen local en forma de archivos con path
`/tmp/<tenant>/<archivo>`

- Finalmente este volumen es utilizado por un contenedor de `mimirtool` quien
itera sobre las carpetas y archivos aprovisionamdo mimir en base al tenant y
el archivo.

## Values

| nombre | tipo | default | descripcion |
| --- | --- | --- | --- |
| `mode` | `String` | `"job"` | Modo de depligue del aprovisionador. Posibles valores `job` y `cronjob` |
| `cronjob.schedule` | `String` | `"*/5 * * * *"` | Expresión para el cronjob |
| `global.provisioner.mimirtoolCommand` | `String` | `rules sync` | Subcomando que se le envia a mimirtool. Por defecto realizara un sync de las rules |
| `global.provisioner.mimirtoolArgs` | `String` | `/tmp/$tenant/$file` | Argumentos que se le pasan al comando de mimirtool |
| `imagePullSecrets` | `Array<image-pullsecrets>` | `[]` | Nombre de secreto con credenciales para bajar las imagenes si se utilizacen repositorios privados. |
| `nameOverride` | `String` | `""` | |
| `fullnameOverride` | `String` | `""` | |
| `serviceAccount.create` | `Bool` | `true` | Especifica si se debe crear una sa |
| `serviceAccount.annotations` | `Object` | `{}` | Anotaciones para la sa |
| `serviceAccoint.name` | `String` | `""` | Nombre de la sa que se utiliza con el despliegue. Si es vacio se utiliza el nombre del release |
| `podAnnotations` | `Object` | `{}` | Anotaciones para el pod que se despliega |
| `podSecurityContext` | `Object` | `{}` | Security context a nivel pod |
| `nodeSelector` | `Object` | `{}` | Nodeselector para schedulear el pod |
| `tolerations` | `Array<toleration>` | `[]` | Tolerations para el pod |
| `affinity` | `Object` | `{}` | Affinity para schedulear el pod |
| `backoffLimit` | `Int` | `3` | Cantidad de veces que se ejecuta el pod en caso de fallos |
| `provisioner.image.repository` | `String` | `grafana/mimirtool` | Repositorio donde se obtiene la imagen de mimirtool |
| `provisioner.image.tag` | `String` | `2.10.5` | Tag de la imagen de mimirtool |
| `provisioner.image.pullPolicy` | `String` | `IfNotPresent` | Polituca para bajar la imagen del provisioner |
| `provisioner.securityContext` | `Object` | `{}` | Security context para el contenedor de mimirtool |
| `provisioner.resources` | `Object` | `{}` | Requests y Limits para el contenedor de mimirtool |
| `provisioner.mimirAddress` | `String` | `http://mimir-nginx.mimir.svc` | Url de la api de mimir. Por defecto se configura para utilizar un mimir instalado en el mismo namespace que este chart. |
| `provisioner.script` | `String` | `Ver values.yaml` | Script que se invoca en el contenedor de mimirtool. Por defecto itera en una estructura de archivos `/tmp/<tenant>/<file>` aplicando el `mimirtoolCommand` con el archivo y el tenant infiriendolos del path. |
| `sidecar.image.repository` | `String` | `ghcr.io/kiwigrid/k8s-sidecar` | Repositorio donde se obtiene la imagen de mimirtool |
| `sidecar.image.tag` | `String` | `1.25.3` | Tag de la imagen de mimirtool |
| `sidecar.image.pullPolicy` | `String` | `IfNotPresent` | Polituca para bajar la imagen del sidecar |
| `sidecar.securityContext` | `Object` | `{}` | Security context para el contenedor de sidecar |
| `sidecar.resources` | `Object` | `{}` | Requests y Limits para el contenedor de sidecar |
| `sidecar.extraEnvs` | `Array<env>` | `[]` | Objeto de variables extra para pasar al contenedor del sidecar. Respetan el formato de variables de ambiente de k8s (name,value) |
| `sidecar.resourceLabel` | `String` | `provisioning` | Label que se aplica a los configmaps y a traves del cual el sidecar los identifica para montar como archivos. |
| `sidecar.resourceType` | `String<both,configmap,secret>` | `both` | Que tipo de recursos mira el sidecar. Por defecto seran configmaps y secrets |
| `sidecar.behaviour` | `String<LIST,WATCH>` | `LIST` | Indica en que modo se ejecuta el sidecar. `LIST` chequea los recursos y termina, `WATCH` queda en loop esperando cambios. |
| `provision` | `Object<tenant>` | `{}` | Objeto que define tenant y archivos para `aprovisiona`r mimir |
| `provision.tenant` | `Array<file>` | `""` | Define los archivos que se utilizan para aprovisionar un tenant en mimir |
| `provision.tenant.file` | `Object<name,content>` | `""` | Define un archivo para aprovisionar un tenant. El mismo cuenta con `name` (nombre con que se montara el archivo en el pod de aprovisionamiento) y `content` (contenido de dicho archivo) |

## Acerca de provision

Dado que mimir es multitenant, es importante que el objeto provision tenga como
claves nombres de tenants validos ya que a partir de estos es que se terminan
montando los archivos e infiriendo contra que tenant aplicar el
aprovisionamiento.

16 changes: 16 additions & 0 deletions charts/mimir-provisioning/templates/_cronjob .tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/*
Expand the cronjob definition.
*/}}
{{- define "mimir-provisioning.cronjob" -}}
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ include "mimir-provisioning.fullname" . }}
labels:
{{- include "mimir-provisioning.labels" . | nindent 4 }}
spec:
concurrencyPolicy: Forbid
schedule: {{ .Values.cronjob.schedule }}
jobTemplate:
spec: {{- include "mimir-provisioning.jobSpec" . | nindent 6 }}
{{- end }}
69 changes: 69 additions & 0 deletions charts/mimir-provisioning/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "mimir-provisioning.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "mimir-provisioning.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "mimir-provisioning.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "mimir-provisioning.labels" -}}
helm.sh/chart: {{ include "mimir-provisioning.chart" . }}
{{ include "mimir-provisioning.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "mimir-provisioning.selectorLabels" -}}
app.kubernetes.io/name: {{ include "mimir-provisioning.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "mimir-provisioning.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "mimir-provisioning.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}

{{/*
Create the name of the provision script configmap
*/}}
{{- define "mimir-provisioning.provisionConfigmapName" }}
{{- printf "%s-%s" (include "mimir-provisioning.fullname" .) "script" | trunc 63 | trimSuffix "-" }}
{{- end }}
104 changes: 104 additions & 0 deletions charts/mimir-provisioning/templates/_job.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{{/*
Expand the job definition.
*/}}
{{- define "mimir-provisioning.job" -}}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "mimir-provisioning.fullname" . }}
labels:
{{- include "mimir-provisioning.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": post-install, post-upgrade
"helm.sh/hook-weight": "-5"
spec:
{{- include "mimir-provisioning.jobSpec" . | nindent 2 }}
{{- end }}

{{/*
Expand the job spec definition.
*/}}
{{- define "mimir-provisioning.jobSpec" -}}
backoffLimit: {{ .Values.backoffLimit }}
template:
metadata:
name: {{ printf "%s-%s" (include "mimir-provisioning.fullname" .) "provisioning" | trunc 63 | trimSuffix "-" }}
labels:
{{- include "mimir-provisioning.labels" . | nindent 4 }}
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "mimir-provisioning.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
restartPolicy: OnFailure
initContainers:
- name: file-provisioner
image: {{ .Values.sidecar.image.repository }}:{{ .Values.sidecar.image.tag }}
securityContext:
{{- toYaml .Values.sidecar.securityContext | nindent 12 }}
imagePullPolicy: {{ .Values.sidecar.image.pullPolicy }}
volumeMounts:
- name: provisioning
mountPath: /tmp/
env:
- name: LABEL
value: {{ .Values.sidecar.resourceLabel }}
- name: FOLDER
value: /tmp
- name: RESOURCE
value: {{ .Values.sidecar.resourceType }}
- name: METHOD
value: {{ .Values.sidecar.behaviour }}
{{- if .Values.sidecar.extraEnvs }}
{{ .Values.sidecar.extraEnvs | toYaml | indent 12 | trim }}
{{- end }}
resources:
{{- toYaml .Values.sidecar.resources | nindent 12 }}
containers:
- name: mimirtool
image: {{ .Values.provisioner.image.repository }}:{{ .Values.provisioner.image.tag }}
securityContext:
{{- toYaml .Values.provisioner.securityContext | nindent 12 }}
imagePullPolicy: {{ .Values.provisioner.image.pullPolicy }}
env:
- name: MIMIR_ADDRESS
value: {{ .Values.provisioner.mimirAddress }}
- name: MIMIR_TLS_INSECURE_SKIP_VERIFY
value: {{ .Values.provisioner.mimirTLSInsecureSkipVerify | ternary "1" "0" | quote }}
volumeMounts:
- name: provisioning
mountPath: /tmp/
- name: provision-script
mountPath: /script/mimirtool.sh
subPath: mimirtool.sh
command:
- /script/mimirtool.sh
resources:
{{- toYaml .Values.provisioner.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
volumes:
- name: provisioning
emptyDir: {}
- name: provision-script
configMap:
name: {{ include "mimir-provisioning.provisionConfigmapName" . }}
defaultMode: 0777
{{- end }}
17 changes: 17 additions & 0 deletions charts/mimir-provisioning/templates/provisioning-cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{- $resourceLabel:=.Values.sidecar.resourceLabel -}}
{{ range $tenant,$files:=.Values.provision }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ printf "%s-%s" (include "mimir-provisioning.fullname" $) $tenant | trunc 63 | trimSuffix "-" }}
annotations:
k8s-sidecar-target-directory: {{ $tenant | quote }}
labels:
{{ $resourceLabel | quote }}: ""
data:
{{ range $file:=$files -}}
{{ required (printf "El campo name de los objetos files es requerido. Revise .Values.provisioning.%s" $tenant) $file.name }}: |
{{ (required (printf "El campo content de los objetos files es requerido. Revise .Values.provisioning.%s" $tenant) $file.content) | indent 4 | trim }}
{{ end -}}
{{ end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{- if eq .Values.mode "cronjob"}}
{{- include "mimir-provisioning.cronjob" . }}
{{- else if eq .Values.mode "job" }}
{{- include "mimir-provisioning.job" . }}
{{- else }}
{{- fail "Invalid mode. It should be one of 'cronjob' or 'job'" }}
{{- end }}
9 changes: 9 additions & 0 deletions charts/mimir-provisioning/templates/role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: {{ include "mimir-provisioning.fullname" . }}
rules:
- apiGroups: [""]
resources: ["configmaps", "secrets"]
verbs: ["get", "watch", "list"]
15 changes: 15 additions & 0 deletions charts/mimir-provisioning/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.serviceAccount.create }}
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ include "mimir-provisioning.fullname" . }}
roleRef:
kind: Role
name: {{ include "mimir-provisioning.fullname" . }}
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: {{ include "mimir-provisioning.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
{{- end }}
6 changes: 6 additions & 0 deletions charts/mimir-provisioning/templates/script-cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "mimir-provisioning.provisionConfigmapName" . }}
data:
mimirtool.sh: {{- tpl .Values.provisioner.script . | toYaml | indent 4 -}}
12 changes: 12 additions & 0 deletions charts/mimir-provisioning/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "mimir-provisioning.serviceAccountName" . }}
labels:
{{- include "mimir-provisioning.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
Loading

0 comments on commit 388692b

Please sign in to comment.