Add metadata in job templates

- Add application label using service name
- Add before-hook-creation delete policy as a default
  (It is a default one in helmv3)
- Add custom metadata by passing params

Change-Id: Ie09f8491800031b9ff051a63feb3e018cb283342
This commit is contained in:
okozachenko 2021-03-01 12:36:16 +02:00
parent 4977aaa48d
commit 0ae8f4d21a
13 changed files with 130 additions and 1 deletions

View File

@ -15,7 +15,7 @@ apiVersion: v1
appVersion: v1.0.0 appVersion: v1.0.0
description: OpenStack-Helm Helm-Toolkit description: OpenStack-Helm Helm-Toolkit
name: helm-toolkit name: helm-toolkit
version: 0.2.5 version: 0.2.6
home: https://docs.openstack.org/openstack-helm home: https://docs.openstack.org/openstack-helm
icon: https://www.openstack.org/themes/openstack/images/project-mascots/OpenStack-Helm/OpenStack_Project_OpenStackHelm_vertical.png icon: https://www.openstack.org/themes/openstack/images/project-mascots/OpenStack-Helm/OpenStack_Project_OpenStackHelm_vertical.png
sources: sources:

View File

@ -20,6 +20,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_bootstrap" -}} {{- define "helm-toolkit.manifests.job_bootstrap" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $podVolMounts := index . "podVolMounts" | default false -}} {{- $podVolMounts := index . "podVolMounts" | default false -}}
{{- $podVols := index . "podVols" | default false -}} {{- $podVols := index . "podVols" | default false -}}
@ -42,6 +44,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceNamePretty "bootstrap" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "bootstrap" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -25,6 +25,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_db_drop_mysql" -}} {{- define "helm-toolkit.manifests.job_db_drop_mysql" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $configMapEtc := index . "configMapEtc" | default (printf "%s-%s" $serviceName "etc" ) -}} {{- $configMapEtc := index . "configMapEtc" | default (printf "%s-%s" $serviceName "etc" ) -}}
@ -46,6 +48,14 @@ metadata:
annotations: annotations:
"helm.sh/hook": pre-delete "helm.sh/hook": pre-delete
"helm.sh/hook-delete-policy": hook-succeeded "helm.sh/hook-delete-policy": hook-succeeded
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -25,6 +25,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_db_init_mysql" -}} {{- define "helm-toolkit.manifests.job_db_init_mysql" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $configMapEtc := index . "configMapEtc" | default (printf "%s-%s" $serviceName "etc" ) -}} {{- $configMapEtc := index . "configMapEtc" | default (printf "%s-%s" $serviceName "etc" ) -}}
@ -43,6 +45,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceNamePretty "db-init" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "db-init" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -20,6 +20,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_db_sync" -}} {{- define "helm-toolkit.manifests.job_db_sync" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $configMapEtc := index . "configMapEtc" | default (printf "%s-%s" $serviceName "etc" ) -}} {{- $configMapEtc := index . "configMapEtc" | default (printf "%s-%s" $serviceName "etc" ) -}}
@ -40,6 +42,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceNamePretty "db-sync" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "db-sync" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -21,6 +21,8 @@ limitations under the License.
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $serviceTypes := index . "serviceTypes" -}} {{- $serviceTypes := index . "serviceTypes" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $secretBin := index . "secretBin" -}} {{- $secretBin := index . "secretBin" -}}
@ -43,6 +45,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceNamePretty "ks-endpoints" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "ks-endpoints" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -21,6 +21,8 @@ limitations under the License.
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $serviceTypes := index . "serviceTypes" -}} {{- $serviceTypes := index . "serviceTypes" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $secretBin := index . "secretBin" -}} {{- $secretBin := index . "secretBin" -}}
@ -43,6 +45,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceNamePretty "ks-service" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "ks-service" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -20,6 +20,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_ks_user" -}} {{- define "helm-toolkit.manifests.job_ks_user" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $serviceUser := index . "serviceUser" | default $serviceName -}} {{- $serviceUser := index . "serviceUser" | default $serviceName -}}
@ -43,6 +45,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceUserPretty "ks-user" | quote }} name: {{ printf "%s-%s" $serviceUserPretty "ks-user" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -15,6 +15,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_rabbit_init" -}} {{- define "helm-toolkit.manifests.job_rabbit_init" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $serviceUser := index . "serviceUser" | default $serviceName -}} {{- $serviceUser := index . "serviceUser" | default $serviceName -}}
@ -30,6 +32,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceUserPretty "rabbit-init" | quote }} name: {{ printf "%s-%s" $serviceUserPretty "rabbit-init" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -20,6 +20,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_s3_bucket" -}} {{- define "helm-toolkit.manifests.job_s3_bucket" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $configMapCeph := index . "configMapCeph" | default (printf "ceph-etc" ) -}} {{- $configMapCeph := index . "configMapCeph" | default (printf "ceph-etc" ) -}}
@ -39,6 +41,15 @@ metadata:
name: {{ printf "%s-%s" $serviceNamePretty "s3-bucket" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "s3-bucket" | quote }}
annotations: annotations:
{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -20,6 +20,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_s3_user" -}} {{- define "helm-toolkit.manifests.job_s3_user" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}} {{- $configMapBin := index . "configMapBin" | default (printf "%s-%s" $serviceName "bin" ) -}}
{{- $configMapCeph := index . "configMapCeph" | default (printf "ceph-etc" ) -}} {{- $configMapCeph := index . "configMapCeph" | default (printf "ceph-etc" ) -}}
@ -37,7 +39,16 @@ kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceNamePretty "s3-user" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "s3-user" | quote }}
annotations: annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -20,6 +20,8 @@ limitations under the License.
{{- define "helm-toolkit.manifests.job_image_repo_sync" -}} {{- define "helm-toolkit.manifests.job_image_repo_sync" -}}
{{- $envAll := index . "envAll" -}} {{- $envAll := index . "envAll" -}}
{{- $serviceName := index . "serviceName" -}} {{- $serviceName := index . "serviceName" -}}
{{- $jobAnnotations := index . "jobAnnotations" -}}
{{- $jobLabels := index . "jobLabels" -}}
{{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}} {{- $nodeSelector := index . "nodeSelector" | default ( dict $envAll.Values.labels.job.node_selector_key $envAll.Values.labels.job.node_selector_value ) -}}
{{- $podVolMounts := index . "podVolMounts" | default false -}} {{- $podVolMounts := index . "podVolMounts" | default false -}}
{{- $podVols := index . "podVols" | default false -}} {{- $podVols := index . "podVols" | default false -}}
@ -36,6 +38,16 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceNamePretty "image-repo-sync" | quote }} name: {{ printf "%s-%s" $serviceNamePretty "image-repo-sync" | quote }}
annotations:
"helm.sh/hook-delete-policy": before-hook-creation
{{- if $jobAnnotations }}
{{ toYaml $jobAnnotations | indent 4 }}
{{- end }}
labels:
application: {{ $serviceName }}
{{- if $jobLabels }}
{{ toYaml $jobLabels | indent 4 }}
{{- end }}
spec: spec:
backoffLimit: {{ $backoffLimit }} backoffLimit: {{ $backoffLimit }}
{{- if $activeDeadlineSeconds }} {{- if $activeDeadlineSeconds }}

View File

@ -12,4 +12,5 @@ helm-toolkit:
- 0.2.3 Allow openstack service list to retry in event of keystone connection issues - 0.2.3 Allow openstack service list to retry in event of keystone connection issues
- 0.2.4 Added detailed FiXME for ks-service script bug and code changes - 0.2.4 Added detailed FiXME for ks-service script bug and code changes
- 0.2.5 Added logic to support cert-manager versioning - 0.2.5 Added logic to support cert-manager versioning
- 0.2.6 Add metadata in job templates
... ...