Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add periodic tasks chart #600

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions charts/periodic-tasks/.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/
24 changes: 24 additions & 0 deletions charts/periodic-tasks/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: periodic-tasks
description: Create CronJob with ease
antares-sw marked this conversation as resolved.
Show resolved Hide resolved

# 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: 1.0.1
antares-sw marked this conversation as resolved.
Show resolved Hide resolved

# 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.16.0"
antares-sw marked this conversation as resolved.
Show resolved Hide resolved
51 changes: 51 additions & 0 deletions charts/periodic-tasks/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{{/*
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).
*/}}
{{- define "periodic-tasks.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s" .Release.Name | trunc 63 | trimSuffix "-" }}
{{- end}}
{{- end }}

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

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

{{/*
Selector labels
*/}}
{{- define "periodic-tasks.selectorLabels" -}}
app.kubernetes.io/name: {{ include "periodic-tasks.fullname" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
repository: {{ .Values.repository | default "none" }}
{{- end }}

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

66 changes: 66 additions & 0 deletions charts/periodic-tasks/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{ range $cronjob := .Values.cronJobs }}
---
apiVersion: batch/v1
kind: CronJob
metadata:
name: {{ $cronjob.name }}
labels:
{{- include "periodic-tasks.labels" $ | nindent 4 }}
component: "{{ $cronjob.name }}"
spec:
schedule: {{ $cronjob.schedule | quote }}
{{- if $cronjob.timezone }}
timeZone: {{ $cronjob.timezone | quote }}
{{- end }}
{{- if $cronjob.concurrencyPolicy }}
concurrencyPolicy: {{ $cronjob.concurrencyPolicy | quote }}
{{- end }}
{{- if $cronjob.suspend }}
suspend: {{ $cronjob.suspend | quote }}
{{- end }}
startingDeadlineSeconds: 100
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
{{- if $cronjob.volumes }}
volumes:
{{- tpl (toYaml $cronjob.volumes) . | nindent 12 }}
{{- end }}
{{- with $.Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- with $cronjob.affinity }}
affinity:
{{- toYaml . | nindent 12 }}
{{- end }}
containers:
- name: {{ $cronjob.name }}
image: {{ $cronjob.image }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
{{- if $cronjob.arguments }}
args:
{{- range $arg := $cronjob.arguments }}
- {{ $arg }}
{{- end }}
{{- end }}
{{- with $.Values.env }}
env:
{{- toYaml . | nindent 14 }}
{{- end }}
{{- with $.Values.envFrom }}
envFrom:
{{- toYaml . | nindent 14 }}
{{- end }}
{{- if $cronjob.volumeMounts }}
volumeMounts:
{{- tpl (toYaml $cronjob.volumeMounts) . | nindent 12 }}
{{- end }}
resources:
{{- toYaml $cronjob.resources | nindent 14 }}
restartPolicy: OnFailure
---
{{- end }}
26 changes: 26 additions & 0 deletions charts/periodic-tasks/templates/extra-configmaps.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{- $Global := . }}
{{- range $configMapName, $configMapContent := .Values.extraConfigMaps }}
---
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ tpl $configMapName $Global | quote }}
labels:
{{- include "periodic-tasks.labels" $Global | nindent 4 }}
{{- if $configMapContent.labels }}
{{- toYaml $configMapContent.labels | nindent 4 }}
{{- end }}
annotations:
"helm.sh/hook": "pre-install,pre-upgrade"
"helm.sh/hook-delete-policy": "before-hook-creation"
"helm.sh/hook-weight": "0"
{{- if $configMapContent.annotations }}
{{- toYaml $configMapContent.annotations | nindent 4 }}
{{- end }}
{{- if $configMapContent.data }}
data:
{{- with $configMapContent.data }}
{{- tpl . $Global | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/periodic-tasks/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 "periodic-tasks.serviceAccountName" . }}
labels:
{{- include "periodic-tasks.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
73 changes: 73 additions & 0 deletions charts/periodic-tasks/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Default values for periodic-tasks.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

image:
pullPolicy: IfNotPresent

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

## CronJobs
## Example:
## cronJobs:
## - name: cronjob
## image: busybox
## arguments:
## - /bin/sh
## - -c
## - "sleep 100"
## schedule: "*/1 * * * *"
## timeZone: "Europe/Moscow"
## concurrencyPolicy: Forbid
## suspend: false
##
cronJobs: {}

serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

# Application Configuration
env: []
# - name: KEY
# value: value
# - name: TOKEN
# valueFrom:
# secretKeyRef:
# name: my-secret
# key: my_secret_value

# Additional environment from configmap or secret
envFrom: []
# - configMapRef:
# name: env-configmap
# - secretRef:
# name: env-secrets

# Extra ConfigMaps that will be managed by the chart
# (You can use them with EnvFrom or some of the extraContainerVolumes values).
# The format for configmap data is "key/value" where
# * key (can be templated) is the name of the configmap that will be created
# * value: an object with the standard 'data' key.
# The value associated with this keys must be a string (can be templated)
extraConfigMaps: {}
# eg:
# extraConfigMaps:
# custom-config:
# labels:
# my.custom.label/v2: my_custom_label_value_2
# data: |
# config.json: |
# {"key": "some data here in any format, e.g. json, yaml, toml, plaintext and so on"}
# data.csv: |
# column 1 name,column 2 name, column 3 name
# first row data 1,first row data 2,first row data 3
# second row data 1,second row data 2,second row data 3

Loading