Skip to content

Commit

Permalink
Add purge CronJob
Browse files Browse the repository at this point in the history
- Bump Version
  • Loading branch information
mfraezz committed Aug 20, 2020
1 parent 5770c20 commit 4fb4b1c
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 1 deletion.
2 changes: 1 addition & 1 deletion osf/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
description: The Open Science Framework (OSF)
name: osf
version: 0.17.0
version: 0.17.1
keywords:
- open
- science
Expand Down
21 changes: 21 additions & 0 deletions osf/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this
{{- printf "%s-%s-%s" .Release.Name $name .Values.migration.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified migration name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "osf.purge.fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s-%s" .Release.Name $name .Values.purge.name | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified web name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
Expand Down Expand Up @@ -258,6 +267,18 @@ pod.beta.kubernetes.io/init-containers: null
{{- end }}
{{- end -}}

{{- define "osf.purge.environment" -}}
{{- include "osf.common.environment" . -}}
{{- $fullname := include "osf.fullname" . -}}
{{- range $key, $value := .Values.secretEnvs }}
- name: {{ $key }}
valueFrom:
secretKeyRef:
name: {{ $fullname }}-purge
key: {{ $key }}
{{- end }}
{{- end -}}

{{- define "osf.certificates.initContainer" -}}
{{- if .Values.tls.enabled }}
- name: certificates
Expand Down
87 changes: 87 additions & 0 deletions osf/templates/purge-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{{- if .Values.purge.enabled -}}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ template "osf.purge.fullname" . }}-{{ .Release.Time.Seconds }}
labels:
app: {{ template "osf.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
component: "{{ .Values.purge.name }}"
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
spec:
schedule: {{ default "0 22 * * 6" .Values.purge.schedule | quote }}
startingDeadlineSeconds: 900
activeDeadlineSeconds: {{ default 14400 .Values.purge.activeDeadlineSeconds }}
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
metadata:
name: "{{ .Release.Name }}"
labels:
app: {{ template "osf.name" . }}
component: "{{ .Values.purge.name }}"
release: {{ .Release.Name }}
annotations:
checksum/secret: {{ include (print $.Template.BasePath "/purge-secret.yaml") . | sha256sum }}
# Init containers not updated on upgrade : https://github.com/kubernetes/helm/issues/2702
{{- if and (eq .Capabilities.KubeVersion.Major "1") (lt .Capabilities.KubeVersion.Minor "8") }}
pod.alpha.kubernetes.io/init-containers: null
pod.beta.kubernetes.io/init-containers: null
{{- end }}
spec:
restartPolicy: Never
initContainers:
- name: chown
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/bash
- -c
- chown -R www-data:www-data /log
securityContext:
runAsUser: 0
volumeMounts:
- mountPath: /log
name: log
{{- include "osf.certificates.initContainer" . | nindent 12 }}
containers:
- name: {{ .Values.purge.name }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
- /bin/sh
- -c
- python3 -m scripts.purge_trashed_files {{- if .Values.purge.num_records }} --num {{ .Values.purge.num_records }} {{- end }}
env:
- name: DJANGO_SETTINGS_MODULE
value: api.base.settings
{{- include "osf.purge.environment" . | nindent 16 }}
{{- range $key, $value := .Values.purge.env }}
- name: {{ $key }}
value: {{ $value | quote }}
{{- end }}
{{- if or .Values.volumeMounts .Values.purge.volumeMounts }}
volumeMounts:
- mountPath: /log
name: log
{{- include "osf.volumeMounts" . | nindent 16 }}
{{- if .Values.purge.volumeMounts }}
{{- toYaml .Values.purge.volumeMounts | nindent 16 }}
{{- end }}
{{- end }}
volumes:
{{- include "osf.volumes" . | nindent 12 }}
- name: log
{{- if .Values.purge.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.purge.persistence.existingClaim | default (include "osf.purge.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end }}
{{- if .Values.purge.nodeSelector }}
nodeSelector:
{{- toYaml .Values.purge.nodeSelector | nindent 12 }}
{{- end }}
{{- end -}}
24 changes: 24 additions & 0 deletions osf/templates/purge-pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{- if and .Values.purge.enabled .Values.purge.persistence.enabled (not .Values.purge.persistence.existingClaim) -}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "osf.purge.fullname" . }}
labels:
app: {{ template "osf.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
component: "{{ .Values.purge.name }}"
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
annotations:
{{- if .Values.purge.persistence.storageClass }}
volume.beta.kubernetes.io/storage-class: {{ .Values.purge.persistence.storageClass | quote }}
{{- else }}
volume.alpha.kubernetes.io/storage-class: default
{{- end }}
spec:
accessModes:
- {{ .Values.purge.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.purge.persistence.size | quote }}
{{- end -}}
36 changes: 36 additions & 0 deletions osf/templates/purge-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
apiVersion: v1
kind: Secret
metadata:
name: {{ template "osf.fullname" . }}-purge
labels:
app: {{ template "osf.name" . }}
chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
heritage: {{ .Release.Service }}
release: {{ .Release.Name }}
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-weight": "-5"
"helm.sh/hook-delete-policy": "before-hook-creation"
type: Opaque
data:
{{- range $key, $value := .Values.secretEnvs }}
{{ $key }}: {{ $value | b64enc | quote }}
{{- end }}
{{- range $key, $value := .Values.secretFiles }}
{{ $key }}: {{ $value | b64enc | quote }}
{{- end }}
{{- range $key, $value := .Values.purge.secretEnvs }}
{{ $key }}: {{ $value | b64enc | quote }}
{{- end }}
{{- range $key, $value := .Values.purge.secretFiles }}
{{ $key }}: {{ $value | b64enc | quote }}
{{- end }}
{{- if .Values.tls.enabled }}
{{- range $app, $tls := omit .Values.tls "enabled" }}
{{- if $tls.enabled }}
{{- range $key, $value := $tls.files }}
certs-{{ $app }}-{{ $key }}: {{ $value | b64enc | quote }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
8 changes: 8 additions & 0 deletions osf/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ migration:

volumeMounts: []

purge:
enabled: false
name: purge
volumeMounts: []
secretFiles: {}
persistence: {}


web:
enabled: true
name: web
Expand Down

0 comments on commit 4fb4b1c

Please sign in to comment.