From b9e6607dcf1dc53bf97f9cef23617ece2ebea617 Mon Sep 17 00:00:00 2001 From: antares-sw <23400824+antares-sw@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:09:42 +0300 Subject: [PATCH 1/2] Add periodic tasks chart --- charts/periodic-tasks/.helmignore | 23 ++++++ charts/periodic-tasks/Chart.yaml | 24 ++++++ charts/periodic-tasks/templates/_helpers.tpl | 51 +++++++++++++ charts/periodic-tasks/templates/cronjob.yaml | 66 +++++++++++++++++ .../templates/extra-configmaps.yaml | 26 +++++++ .../templates/serviceaccount.yaml | 12 +++ charts/periodic-tasks/values.yaml | 73 +++++++++++++++++++ 7 files changed, 275 insertions(+) create mode 100644 charts/periodic-tasks/.helmignore create mode 100644 charts/periodic-tasks/Chart.yaml create mode 100644 charts/periodic-tasks/templates/_helpers.tpl create mode 100644 charts/periodic-tasks/templates/cronjob.yaml create mode 100644 charts/periodic-tasks/templates/extra-configmaps.yaml create mode 100644 charts/periodic-tasks/templates/serviceaccount.yaml create mode 100644 charts/periodic-tasks/values.yaml diff --git a/charts/periodic-tasks/.helmignore b/charts/periodic-tasks/.helmignore new file mode 100644 index 000000000..0e8a0eb36 --- /dev/null +++ b/charts/periodic-tasks/.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/charts/periodic-tasks/Chart.yaml b/charts/periodic-tasks/Chart.yaml new file mode 100644 index 000000000..352a8bff6 --- /dev/null +++ b/charts/periodic-tasks/Chart.yaml @@ -0,0 +1,24 @@ +apiVersion: v2 +name: periodic-tasks +description: Create CronJob with ease + +# 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 + +# 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" diff --git a/charts/periodic-tasks/templates/_helpers.tpl b/charts/periodic-tasks/templates/_helpers.tpl new file mode 100644 index 000000000..dcb9eba34 --- /dev/null +++ b/charts/periodic-tasks/templates/_helpers.tpl @@ -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 }} + diff --git a/charts/periodic-tasks/templates/cronjob.yaml b/charts/periodic-tasks/templates/cronjob.yaml new file mode 100644 index 000000000..48719b5be --- /dev/null +++ b/charts/periodic-tasks/templates/cronjob.yaml @@ -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 }} diff --git a/charts/periodic-tasks/templates/extra-configmaps.yaml b/charts/periodic-tasks/templates/extra-configmaps.yaml new file mode 100644 index 000000000..5f28bd7d2 --- /dev/null +++ b/charts/periodic-tasks/templates/extra-configmaps.yaml @@ -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 }} diff --git a/charts/periodic-tasks/templates/serviceaccount.yaml b/charts/periodic-tasks/templates/serviceaccount.yaml new file mode 100644 index 000000000..e1046d7ed --- /dev/null +++ b/charts/periodic-tasks/templates/serviceaccount.yaml @@ -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 }} diff --git a/charts/periodic-tasks/values.yaml b/charts/periodic-tasks/values.yaml new file mode 100644 index 000000000..438da3391 --- /dev/null +++ b/charts/periodic-tasks/values.yaml @@ -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 + From f15e4390ad51c955f0fc05dd08c6adea915b1e32 Mon Sep 17 00:00:00 2001 From: antares-sw <23400824+antares-sw@users.noreply.github.com> Date: Wed, 30 Oct 2024 16:42:45 +0300 Subject: [PATCH 2/2] Fix comments --- charts/periodic-tasks/Chart.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/periodic-tasks/Chart.yaml b/charts/periodic-tasks/Chart.yaml index 352a8bff6..db42882ce 100644 --- a/charts/periodic-tasks/Chart.yaml +++ b/charts/periodic-tasks/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: periodic-tasks -description: Create CronJob with ease +description: Periodic Tasks Scheduler # A chart can be either an 'application' or a 'library' chart. # @@ -15,10 +15,10 @@ 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 +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. # It is recommended to use it with quotes. -appVersion: "1.16.0" +appVersion: "0.0.1"