From 7822e1d5853e91d788618faeb55ef89ffcbe6bc8 Mon Sep 17 00:00:00 2001 From: Emilien Devos Date: Fri, 1 Dec 2023 11:44:36 +0100 Subject: [PATCH] add new helm chart for backup georchestra ldap --- georchestra-backup-ldap/.helmignore | 23 +++++++ georchestra-backup-ldap/Chart.yaml | 24 +++++++ .../templates/_helpers.tpl | 62 +++++++++++++++++ .../templates/cronjob.yaml | 63 +++++++++++++++++ georchestra-backup-ldap/templates/pvc.yaml | 30 +++++++++ georchestra-backup-ldap/values.yaml | 67 +++++++++++++++++++ 6 files changed, 269 insertions(+) create mode 100644 georchestra-backup-ldap/.helmignore create mode 100644 georchestra-backup-ldap/Chart.yaml create mode 100644 georchestra-backup-ldap/templates/_helpers.tpl create mode 100644 georchestra-backup-ldap/templates/cronjob.yaml create mode 100644 georchestra-backup-ldap/templates/pvc.yaml create mode 100644 georchestra-backup-ldap/values.yaml diff --git a/georchestra-backup-ldap/.helmignore b/georchestra-backup-ldap/.helmignore new file mode 100644 index 0000000..0e8a0eb --- /dev/null +++ b/georchestra-backup-ldap/.helmignore @@ -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/ diff --git a/georchestra-backup-ldap/Chart.yaml b/georchestra-backup-ldap/Chart.yaml new file mode 100644 index 0000000..f56ad79 --- /dev/null +++ b/georchestra-backup-ldap/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: georchestra-backup-ldap +description: A Helm chart for backup ldap + +# A chart can be either an 'application' or a 'library' chart. +# +# Application charts are a collection of templates that can be packaged into versioned archives +# to be deployed. +# +# Library charts provide useful utilities or functions for the chart developer. They're included as +# a dependency of application charts to inject those utilities and functions into the rendering +# pipeline. Library charts do not define any templates and therefore cannot be deployed. +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.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 +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.0.0" diff --git a/georchestra-backup-ldap/templates/_helpers.tpl b/georchestra-backup-ldap/templates/_helpers.tpl new file mode 100644 index 0000000..b75093b --- /dev/null +++ b/georchestra-backup-ldap/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "georchestra-backup-ldap.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 "georchestra-backup-ldap.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 "georchestra-backup-ldap.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "georchestra-backup-ldap.labels" -}} +helm.sh/chart: {{ include "georchestra-backup-ldap.chart" . }} +{{ include "georchestra-backup-ldap.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "georchestra-backup-ldap.selectorLabels" -}} +app.kubernetes.io/name: {{ include "georchestra-backup-ldap.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "georchestra-backup-ldap.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "georchestra-backup-ldap.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/georchestra-backup-ldap/templates/cronjob.yaml b/georchestra-backup-ldap/templates/cronjob.yaml new file mode 100644 index 0000000..af76231 --- /dev/null +++ b/georchestra-backup-ldap/templates/cronjob.yaml @@ -0,0 +1,63 @@ +{{- $job := .Values.job -}} +{{- $ldapTargetConfiguration := .Values.configuration.ldapTarget -}} +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ include "georchestra-backup-ldap.fullname" . }} + labels: + {{- include "georchestra-backup-ldap.labels" . | nindent 4 }} +spec: + schedule: {{ $job.schedule | quote }} + successfulJobsHistoryLimit: {{ $job.successfulJobsHistoryLimit }} + jobTemplate: + spec: + metadata: + labels: + {{- include "georchestra-backup-ldap.labels" . | nindent 12 }} + template: + spec: + {{- with $job.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- with $job.securityContext }} + securityContext: + {{ toYaml . | indent 12 }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: "{{ $job.image.repository }}:{{ $job.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ $job.image.pullPolicy }} + volumeMounts: + - mountPath: /backup + name: backup + command: ["/bin/bash"] + args: + - -c + - /usr/bin/ldapsearch -H {{ $ldapTargetConfiguration.service }} -xLLL -D "cn=admin,{{ $ldapTargetConfiguration.baseDC }}" -w {{ $ldapTargetConfiguration.secret }} -b "ou=users,{{ $ldapTargetConfiguration.baseDC }}" > /backup/ldap-$(date +"%s").ldif + - /usr/bin/ldapsearch -H {{ $ldapTargetConfiguration.service }} -xLLL -D "cn=admin,{{ $ldapTargetConfiguration.baseDC }}" -w {{ $ldapTargetConfiguration.secret }} -b "ou=pendingusers,{{ $ldapTargetConfiguration.baseDC }}" >> /backup/ldap-$(date +"%s").ldif + - /usr/bin/ldapsearch -H {{ $ldapTargetConfiguration.service }} -xLLL -D "cn=admin,{{ $ldapTargetConfiguration.baseDC }}" -w {{ $ldapTargetConfiguration.secret }} -b "ou=orgs,{{ $ldapTargetConfiguration.baseDC }}" >> /backup/ldap-$(date +"%s").ldif + - /usr/bin/ldapsearch -H {{ $ldapTargetConfiguration.service }} -xLLL -D "cn=admin,{{ $ldapTargetConfiguration.baseDC }}" -w {{ $ldapTargetConfiguration.secret }} -b "ou=pendingorgs,{{ $ldapTargetConfiguration.baseDC }}" >> /backup/ldap-$(date +"%s").ldif + - /usr/bin/ldapsearch -H {{ $ldapTargetConfiguration.service }} -xLLL -D "cn=admin,{{ $ldapTargetConfiguration.baseDC }}" -w {{ $ldapTargetConfiguration.secret }} -b "ou=roles,{{ $ldapTargetConfiguration.baseDC }}" >> /backup/ldap-$(date +"%s").ldif + - rm `ls -t /backup | awk 'NR>{{ .Values.configuration.keepLastBackups }}'` + {{- with $job.resources }} + resources: + {{ toYaml . | indent 14 }} + {{- end }} + restartPolicy: {{ $job.restartPolicy }} + volumes: + - name: "backup" + persistentVolumeClaim: + claimName: {{ include "georchestra-backup-ldap.fullname" . }}-pvc + {{- with $job.nodeSelector }} + nodeSelector: + {{ toYaml . | indent 12 }} + {{- end }} + {{- with $job.affinity }} + affinity: + {{ toYaml . | indent 12 }} + {{- end }} + {{- with $job.tolerations }} + tolerations: + {{ toYaml . | indent 12 }} + {{- end }} \ No newline at end of file diff --git a/georchestra-backup-ldap/templates/pvc.yaml b/georchestra-backup-ldap/templates/pvc.yaml new file mode 100644 index 0000000..34e8008 --- /dev/null +++ b/georchestra-backup-ldap/templates/pvc.yaml @@ -0,0 +1,30 @@ +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: {{ include "georchestra-backup-ldap.fullname" . }}-pvc + labels: + {{- include "georchestra-backup-ldap.labels" . | nindent 4 }} + annotations: + helm.sh/resource-policy: keep +spec: + accessModes: + {{- range .Values.persistence.accessModes }} + - {{ . | quote }} + {{- end }} + storageClassName: "" + selector: + matchLabels: + {{- include "georchestra-backup-ldap.selectorLabels" . | nindent 6 }} + resources: + requests: + storage: {{ .Values.persistence.size }} + {{- if .Values.persistence.existingPV }} + volumeName: {{ .Values.persistence.existingPV }} + {{- end }} + {{- if .Values.persistence.storageClass }} + {{- if eq "-" .Values.persistence.storageClass }} + storageClassName: "" + {{- else }} + storageClassName: {{ .Values.persistence.storageClass }} + {{- end }} + {{- end }} \ No newline at end of file diff --git a/georchestra-backup-ldap/values.yaml b/georchestra-backup-ldap/values.yaml new file mode 100644 index 0000000..87f54f8 --- /dev/null +++ b/georchestra-backup-ldap/values.yaml @@ -0,0 +1,67 @@ +nameOverride: "" +fullnameOverride: "" + +job: + image: + repository: georchestra/ldap + pullPolicy: Always + # Overrides the image tag whose default is the chart appVersion. + tag: "latest" + schedule: "0 6 * * *" + successfulJobsHistoryLimit: 3 + restartPolicy: OnFailure + nodeSelector: {} + tolerations: [] + affinity: {} + 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 + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + imagePullSecrets: [] + +configuration: + keepLastBackups: "10" + ldapTarget: + service: "ldap://georchestra-ldap-svc:389" + secret: "secret" + baseDC: "dc=georchestra,dc=org" + +persistence: + ## Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. (gp2 on AWS, standard on + ## GKE, AWS & OpenStack) + ## + # storageClass: "-" + ## PVC annotations + # + # If you need this annotation include it under values.yml file and pvc.yml template will add it. + # This is not maintained at Helm v3 anymore. + # https://github.com/8gears/n8n-helm-chart/issues/8 + # + ## Persistent Volume Access Mode + ## + accessModes: + - ReadWriteOnce + ## Persistent Volume size + ## + size: 5Gi + ## Use an existing PV + ## + # existingPV: \ No newline at end of file