Added post-install and post-upgrade hook for jobs.

Chart upgrading was failing due to some immutable fields are needed to upgrade before the jobs can be upgraded. For solving this issue, we
have added the helm.sh/hook annotations with post-install and post-upgrade values.
As for hook-weight annotations, we have added these to control the flow of the jobs with hook creation as the jobs are dependent. Like,
db-init jobs need to run before db-sync and so on.
helm3_hook values is added so that hook can be disabled from the values files.

Change-Id: Idfcc0479d152286ecd144502d80732094c9e43ea
This commit is contained in:
Susanta Gautam 2021-03-23 16:59:46 +05:45 committed by xuxant02@gmail.com
parent 13ec697a4a
commit 3c9cf1539b
11 changed files with 68 additions and 1 deletions

View File

@ -14,7 +14,7 @@ apiVersion: v1
appVersion: v1.0.0 appVersion: v1.0.0
description: OpenStack-Helm Cinder description: OpenStack-Helm Cinder
name: cinder name: cinder
version: 0.2.5 version: 0.2.6
home: https://docs.openstack.org/cinder/latest/ home: https://docs.openstack.org/cinder/latest/
icon: https://www.openstack.org/themes/openstack/images/project-mascots/Cinder/OpenStack_Project_Cinder_vertical.png icon: https://www.openstack.org/themes/openstack/images/project-mascots/Cinder/OpenStack_Project_Cinder_vertical.png
sources: sources:

View File

@ -28,6 +28,13 @@ apiVersion: batch/v1
kind: Job kind: Job
metadata: metadata:
name: {{ printf "%s-%s" $serviceUserPretty "create-internal-tenant" | quote }} name: {{ printf "%s-%s" $serviceUserPretty "create-internal-tenant" | quote }}
{{- if .Values.helm3_hook }}
annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation
{{- end }}
labels:
application: {{ printf "%s-%s" $serviceUserPretty "create-internal-tenant" | quote }}
spec: spec:
template: template:
metadata: metadata:

View File

@ -12,10 +12,18 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.db_init" }}
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "-5"
{{- end }}
{{- if .Values.manifests.job_db_init }} {{- if .Values.manifests.job_db_init }}
{{- $dbInitJob := dict "envAll" . "serviceName" "cinder" -}} {{- $dbInitJob := dict "envAll" . "serviceName" "cinder" -}}
{{- if .Values.manifests.certificates -}} {{- if .Values.manifests.certificates -}}
{{- $_ := set $dbInitJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}} {{- $_ := set $dbInitJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}}
{{- end -}} {{- end -}}
{{- if .Values.helm3_hook }}
{{- $_ := set $dbInitJob "jobAnnotations" (include "metadata.annotations.job.db_init" . | fromYaml) }}
{{- end }}
{{ $dbInitJob | include "helm-toolkit.manifests.job_db_init_mysql" }} {{ $dbInitJob | include "helm-toolkit.manifests.job_db_init_mysql" }}
{{- end }} {{- end }}

View File

@ -12,10 +12,18 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.db_sync" }}
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "-4"
{{- end }}
{{- if .Values.manifests.job_db_sync }} {{- if .Values.manifests.job_db_sync }}
{{- $dbSyncJob := dict "envAll" . "serviceName" "cinder" "podVolMounts" .Values.pod.mounts.cinder_db_sync.cinder_db_sync.volumeMounts "podVols" .Values.pod.mounts.cinder_db_sync.cinder_db_sync.volumes -}} {{- $dbSyncJob := dict "envAll" . "serviceName" "cinder" "podVolMounts" .Values.pod.mounts.cinder_db_sync.cinder_db_sync.volumeMounts "podVols" .Values.pod.mounts.cinder_db_sync.cinder_db_sync.volumes -}}
{{- if .Values.manifests.certificates -}} {{- if .Values.manifests.certificates -}}
{{- $_ := set $dbSyncJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}} {{- $_ := set $dbSyncJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}}
{{- end -}} {{- end -}}
{{- if .Values.helm3_hook }}
{{- $_ := set $dbSyncJob "jobAnnotations" (include "metadata.annotations.job.db_sync" . | fromYaml) }}
{{- end }}
{{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }} {{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }}
{{- end }} {{- end }}

View File

@ -12,7 +12,14 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.repo_sync" }}
helm.sh/hook: post-install,post-upgrade
{{- end }}
{{- if and .Values.manifests.job_image_repo_sync .Values.images.local_registry.active }} {{- if and .Values.manifests.job_image_repo_sync .Values.images.local_registry.active }}
{{- $imageRepoSyncJob := dict "envAll" . "serviceName" "cinder" -}} {{- $imageRepoSyncJob := dict "envAll" . "serviceName" "cinder" -}}
{{- if .Values.helm3_hook }}
{{- $_ := $imageRepoSyncJob "jobAnnotations" (include "metadata.annotations.job.repo_sync" . | fromYaml) }}
{{- end }}
{{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }} {{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }}
{{- end }} {{- end }}

View File

@ -12,10 +12,18 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.ks_endpoints" }}
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "-2"
{{- end }}
{{- if .Values.manifests.job_ks_endpoints }} {{- if .Values.manifests.job_ks_endpoints }}
{{- $ksServiceJob := dict "envAll" . "serviceName" "cinder" "serviceTypes" ( tuple "volume" "volumev2" "volumev3" ) -}} {{- $ksServiceJob := dict "envAll" . "serviceName" "cinder" "serviceTypes" ( tuple "volume" "volumev2" "volumev3" ) -}}
{{- if .Values.manifests.certificates -}} {{- if .Values.manifests.certificates -}}
{{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.volume.api.internal -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.volume.api.internal -}}
{{- end -}} {{- end -}}
{{- if .Values.helm3_hook }}
{{- $_ := set $ksServiceJob "jobAnnotations" (include "metadata.annotations.job.ks_endpoints" . | fromYaml) }}
{{- end }}
{{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }}
{{- end }} {{- end }}

View File

@ -12,10 +12,18 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.ks_service" }}
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "-3"
{{- end }}
{{- if .Values.manifests.job_ks_service }} {{- if .Values.manifests.job_ks_service }}
{{- $ksServiceJob := dict "envAll" . "serviceName" "cinder" "serviceTypes" ( tuple "volume" "volumev2" "volumev3" ) -}} {{- $ksServiceJob := dict "envAll" . "serviceName" "cinder" "serviceTypes" ( tuple "volume" "volumev2" "volumev3" ) -}}
{{- if .Values.manifests.certificates -}} {{- if .Values.manifests.certificates -}}
{{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.volume.api.internal -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.volume.api.internal -}}
{{- end -}} {{- end -}}
{{- if .Values.helm3_hook }}
{{- $_ := set $ksServiceJob "jobAnnotations" (include "metadata.annotations.job.ks_service" . | fromYaml) }}
{{- end }}
{{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }}
{{- end }} {{- end }}

View File

@ -12,10 +12,18 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.ks_user" }}
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "-1"
{{- end }}
{{- if .Values.manifests.job_ks_user }} {{- if .Values.manifests.job_ks_user }}
{{- $ksUserJob := dict "envAll" . "serviceName" "cinder" -}} {{- $ksUserJob := dict "envAll" . "serviceName" "cinder" -}}
{{- if .Values.manifests.certificates -}} {{- if .Values.manifests.certificates -}}
{{- $_ := set $ksUserJob "tlsSecret" .Values.secrets.tls.volume.api.internal -}} {{- $_ := set $ksUserJob "tlsSecret" .Values.secrets.tls.volume.api.internal -}}
{{- end -}} {{- end -}}
{{- if .Values.helm3_hook }}
{{- $_ := set $ksUserJob "jobAnnotations" (include "metadata.annotations.job.ks_user" . | fromYaml) }}
{{- end }}
{{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }} {{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }}
{{- end }} {{- end }}

View File

@ -12,10 +12,18 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.rabbit_init" }}
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "-4"
{{- end }}
{{- if .Values.manifests.job_rabbit_init }} {{- if .Values.manifests.job_rabbit_init }}
{{- $rmqUserJob := dict "envAll" . "serviceName" "cinder" -}} {{- $rmqUserJob := dict "envAll" . "serviceName" "cinder" -}}
{{- if .Values.manifests.certificates -}} {{- if .Values.manifests.certificates -}}
{{- $_ := set $rmqUserJob "tlsSecret" .Values.endpoints.oslo_messaging.auth.admin.secret.tls.internal -}} {{- $_ := set $rmqUserJob "tlsSecret" .Values.endpoints.oslo_messaging.auth.admin.secret.tls.internal -}}
{{- end -}} {{- end -}}
{{- if .Values.helm3_hook }}
{{- $_ := set $rmqUserJob "jobAnnotations" (include "metadata.annotations.job.rabbit_init" . | fromYaml) }}
{{- end }}
{{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }} {{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }}
{{- end }} {{- end }}

View File

@ -1514,6 +1514,10 @@ network_policy:
egress: egress:
- {} - {}
# NOTE(helm_hook): helm_hook might break for helm2 binary.
# set helm3_hook: false when using the helm2 binary.
helm3_hook: true
manifests: manifests:
certificates: false certificates: false
configmap_bin: true configmap_bin: true

View File

@ -22,4 +22,5 @@ cinder:
- 0.2.3 Mount rabbitmq TLS secret - 0.2.3 Mount rabbitmq TLS secret
- 0.2.4 Add Ussuri release support - 0.2.4 Add Ussuri release support
- 0.2.5 Add volume QoS support - 0.2.5 Add volume QoS support
- 0.2.6 Added helm.sh/hook with value of post-install and post-upgrade
... ...