Added post-install and post-upgrade hook for jobs in ironic

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.

Change-Id: I0905be3d1708e5226ccd41b84b409a290c89f826
This commit is contained in:
Susanta Gautam 2021-03-24 17:07:39 +05:45
parent 48ab9f6961
commit 201dd4ea6c
11 changed files with 52 additions and 9 deletions

@ -14,7 +14,7 @@ apiVersion: v1
appVersion: v1.0.0 appVersion: v1.0.0
description: OpenStack-Helm Ironic description: OpenStack-Helm Ironic
name: ironic name: ironic
version: 0.1.1 version: 0.1.2
home: https://docs.openstack.org/ironic/latest/ home: https://docs.openstack.org/ironic/latest/
icon: https://www.openstack.org/themes/openstack/images/project-mascots/Ironic/OpenStack_Project_Ironic_vertical.png icon: https://www.openstack.org/themes/openstack/images/project-mascots/Ironic/OpenStack_Project_Ironic_vertical.png
sources: sources:

@ -12,9 +12,14 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/}} */}}
{{- define "metadata.annotations.job.bootstrap" }}
helm.sh/hook: post-install,post-upgrade
helm.sh/hook-weight: "5"
{{- end }}
{{- if and .Values.manifests.job_bootstrap .Values.bootstrap.image.enabled }} {{- if and .Values.manifests.job_bootstrap .Values.bootstrap.image.enabled }}
{{- if .Values.bootstrap.image.openstack.enabled }} {{- if .Values.bootstrap.image.openstack.enabled }}
{{- $bootstrapJob := dict "envAll" . "serviceName" "ironic" "keystoneUser" .Values.bootstrap.image.openstack.ks_user "logConfigFile" .Values.conf.ironic.DEFAULT.log_config_append -}} {{- $bootstrapJob := dict "envAll" . "serviceName" "ironic" "keystoneUser" .Values.bootstrap.image.openstack.ks_user "logConfigFile" .Values.conf.ironic.DEFAULT.log_config_append "jobAnnotations" (include "metadata.annotations.job.bootstrap" . | fromYaml) -}}
{{ $bootstrapJob | include "helm-toolkit.manifests.job_bootstrap" }} {{ $bootstrapJob | include "helm-toolkit.manifests.job_bootstrap" }}
{{- else }} {{- else }}
{{ include "helm-toolkit.manifests.job_bootstrap" }} {{ include "helm-toolkit.manifests.job_bootstrap" }}

@ -12,7 +12,12 @@ 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" "ironic" -}} {{- $dbInitJob := dict "envAll" . "serviceName" "ironic" "jobAnnotations" (include "metadata.annotations.job.db_init" . | fromYaml) -}}
{{ $dbInitJob | include "helm-toolkit.manifests.job_db_init_mysql" }} {{ $dbInitJob | include "helm-toolkit.manifests.job_db_init_mysql" }}
{{- end }} {{- end }}

@ -12,7 +12,12 @@ 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" "ironic" "podVolMounts" .Values.pod.mounts.ironic_db_sync.ironic_db_sync.volumeMounts "podVols" .Values.pod.mounts.ironic_db_sync.ironic_db_sync.volumes -}} {{- $dbSyncJob := dict "envAll" . "serviceName" "ironic" "podVolMounts" .Values.pod.mounts.ironic_db_sync.ironic_db_sync.volumeMounts "podVols" .Values.pod.mounts.ironic_db_sync.ironic_db_sync.volumes "jobAnnotations" (include "metadata.annotations.job.db_sync" . | fromYaml) -}}
{{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }} {{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }}
{{- end }} {{- end }}

@ -12,7 +12,11 @@ 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" "ironic" -}} {{- $imageRepoSyncJob := dict "envAll" . "serviceName" "ironic" "jobAnnotations" (include "metadata.annotations.job.repo_sync" . | fromYaml) -}}
{{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }} {{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }}
{{- end }} {{- end }}

@ -12,7 +12,12 @@ 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" "ironic" "serviceTypes" ( tuple "baremetal" ) -}} {{- $ksServiceJob := dict "envAll" . "serviceName" "ironic" "serviceTypes" ( tuple "baremetal" ) "jobAnnotations" (include "metadata.annotations.job.ks_endpoints" . | fromYaml) -}}
{{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }}
{{- end }} {{- end }}

@ -12,7 +12,12 @@ 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" "ironic" "serviceTypes" ( tuple "baremetal" ) -}} {{- $ksServiceJob := dict "envAll" . "serviceName" "ironic" "serviceTypes" ( tuple "baremetal" ) "jobAnnotations" (include "metadata.annotations.job.ks_service" . | fromYaml) -}}
{{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }}
{{- end }} {{- end }}

@ -12,7 +12,12 @@ 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" "ironic" -}} {{- $ksUserJob := dict "envAll" . "serviceName" "ironic" "jobAnnotations" (include "metadata.annotations.job.ks_user" . | fromYaml) -}}
{{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }} {{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }}
{{- end }} {{- end }}

@ -23,6 +23,8 @@ kind: Job
metadata: metadata:
name: ironic-manage-cleaning-network name: ironic-manage-cleaning-network
annotations: annotations:
"helm.sh/hook": post-install,post-upgrade
"helm.sh/hook-delete-policy": before-hook-creation
{{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }}
spec: spec:
template: template:

@ -11,7 +11,13 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and 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" "ironic" -}} {{- $rmqUserJob := dict "envAll" . "serviceName" "ironic" "jobAnnotations" (include "metadata.annotations.job.rabbit_init" . | fromYaml) -}}
{{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }} {{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }}
{{- end }} {{- end }}

@ -2,3 +2,4 @@
ironic: ironic:
- 0.1.0 Initial Chart - 0.1.0 Initial Chart
- 0.1.1 Change helm-toolkit dependency version to ">= 0.1.0" - 0.1.1 Change helm-toolkit dependency version to ">= 0.1.0"
- 0.1.2 Added post-install and post-upgrade helm.sh/hook for jobs