Skip to content

Commit

Permalink
postgres backup chart (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
panzelva committed Apr 23, 2021
1 parent 8a426e8 commit 2bea8d7
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 0 deletions.
23 changes: 23 additions & 0 deletions charts/postgres-backup/.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/
23 changes: 23 additions & 0 deletions charts/postgres-backup/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: v2
name: postgres-backup
description: A Helm chart for Kubernetes

# 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.0.1

# 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.
appVersion: 0.0.1
63 changes: 63 additions & 0 deletions charts/postgres-backup/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "postgres-backup.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 "postgres-backup.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 "postgres-backup.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

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

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

{{/*
Create the name of the service account to use
*/}}
{{- define "postgres-backup.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "postgres-backup.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
34 changes: 34 additions & 0 deletions charts/postgres-backup/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ include "postgres-backup.fullname" . }}
labels:
{{- include "postgres-backup.labels" . | nindent 4 }}
spec:
suspend: {{ .Values.cronjob.suspend }}
schedule: {{ .Values.cronjob.schedule | quote }}
startingDeadlineSeconds: {{ .Values.cronjob.startingDeadlineSeconds }}
concurrencyPolicy: {{ .Values.cronjob.concurrencyPolicy }}
successfulJobsHistoryLimit: {{ .Values.cronjob.successfulJobsHistoryLimit }}
failedJobsHistoryLimit: {{ .Values.cronjob.failedJobsHistoryLimit }}
jobTemplate:
spec:
backoffLimit: {{ .Values.cronjob.job.backoffLimit }}
template:
spec:
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: NODE_ENV
value: production
{{- with .Values.cronjob.container.envFrom }}
envFrom:
{{- toYaml . | nindent 16 }}
{{- end }}
restartPolicy: {{ .Values.cronjob.container.restartPolicy }}
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
26 changes: 26 additions & 0 deletions charts/postgres-backup/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Default values for postgres-backup.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

image:
repository: ghcr.io/panzelva/postgres-backup
pullPolicy: Always
# Overrides the image tag whose default is the chart appVersion.
tag: ""

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

cronjob:
schedule: "0 0 * * *"
startingDeadlineSeconds: 20
concurrencyPolicy: Forbid
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
suspend: false
job:
backoffLimit: 6
container:
envFrom: null
restartPolicy: OnFailure

0 comments on commit 2bea8d7

Please sign in to comment.