From 201dd4ea6c15a48e7ab0374b73aef918baf7074e Mon Sep 17 00:00:00 2001 From: Susanta Gautam Date: Wed, 24 Mar 2021 17:07:39 +0545 Subject: [PATCH] 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 --- ironic/Chart.yaml | 2 +- ironic/templates/job-bootstrap.yaml | 7 ++++++- ironic/templates/job-db-init.yaml | 7 ++++++- ironic/templates/job-db-sync.yaml | 7 ++++++- ironic/templates/job-image-repo-sync.yaml | 6 +++++- ironic/templates/job-ks-endpoints.yaml | 7 ++++++- ironic/templates/job-ks-service.yaml | 7 ++++++- ironic/templates/job-ks-user.yaml | 7 ++++++- ironic/templates/job-manage-cleaning-network.yaml | 2 ++ ironic/templates/job-rabbit-init.yaml | 8 +++++++- releasenotes/notes/ironic.yaml | 1 + 11 files changed, 52 insertions(+), 9 deletions(-) diff --git a/ironic/Chart.yaml b/ironic/Chart.yaml index 44b1611f..c2c8d19e 100644 --- a/ironic/Chart.yaml +++ b/ironic/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Ironic name: ironic -version: 0.1.1 +version: 0.1.2 home: https://docs.openstack.org/ironic/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Ironic/OpenStack_Project_Ironic_vertical.png sources: diff --git a/ironic/templates/job-bootstrap.yaml b/ironic/templates/job-bootstrap.yaml index d2351b69..94221860 100644 --- a/ironic/templates/job-bootstrap.yaml +++ b/ironic/templates/job-bootstrap.yaml @@ -12,9 +12,14 @@ See the License for the specific language governing permissions and 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 .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" }} {{- else }} {{ include "helm-toolkit.manifests.job_bootstrap" }} diff --git a/ironic/templates/job-db-init.yaml b/ironic/templates/job-db-init.yaml index 6413d4b1..e2fd27d7 100644 --- a/ironic/templates/job-db-init.yaml +++ b/ironic/templates/job-db-init.yaml @@ -12,7 +12,12 @@ See the License for the specific language governing permissions and 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 }} -{{- $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" }} {{- end }} diff --git a/ironic/templates/job-db-sync.yaml b/ironic/templates/job-db-sync.yaml index 242fad52..00bf4df2 100644 --- a/ironic/templates/job-db-sync.yaml +++ b/ironic/templates/job-db-sync.yaml @@ -12,7 +12,12 @@ See the License for the specific language governing permissions and 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 }} -{{- $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" }} {{- end }} diff --git a/ironic/templates/job-image-repo-sync.yaml b/ironic/templates/job-image-repo-sync.yaml index 908a9ae7..8399f6dd 100644 --- a/ironic/templates/job-image-repo-sync.yaml +++ b/ironic/templates/job-image-repo-sync.yaml @@ -12,7 +12,11 @@ See the License for the specific language governing permissions and 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 }} -{{- $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" }} {{- end }} diff --git a/ironic/templates/job-ks-endpoints.yaml b/ironic/templates/job-ks-endpoints.yaml index 5ccacf60..73b2fa63 100644 --- a/ironic/templates/job-ks-endpoints.yaml +++ b/ironic/templates/job-ks-endpoints.yaml @@ -12,7 +12,12 @@ See the License for the specific language governing permissions and 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 }} -{{- $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" }} {{- end }} diff --git a/ironic/templates/job-ks-service.yaml b/ironic/templates/job-ks-service.yaml index dd65a3cf..c4c64e1d 100644 --- a/ironic/templates/job-ks-service.yaml +++ b/ironic/templates/job-ks-service.yaml @@ -12,7 +12,12 @@ See the License for the specific language governing permissions and 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 }} -{{- $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" }} {{- end }} diff --git a/ironic/templates/job-ks-user.yaml b/ironic/templates/job-ks-user.yaml index fb9174aa..8f277b37 100644 --- a/ironic/templates/job-ks-user.yaml +++ b/ironic/templates/job-ks-user.yaml @@ -12,7 +12,12 @@ See the License for the specific language governing permissions and 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 }} -{{- $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" }} {{- end }} diff --git a/ironic/templates/job-manage-cleaning-network.yaml b/ironic/templates/job-manage-cleaning-network.yaml index b2b5cd7a..6ccb2b8a 100644 --- a/ironic/templates/job-manage-cleaning-network.yaml +++ b/ironic/templates/job-manage-cleaning-network.yaml @@ -23,6 +23,8 @@ kind: Job metadata: name: ironic-manage-cleaning-network annotations: + "helm.sh/hook": post-install,post-upgrade + "helm.sh/hook-delete-policy": before-hook-creation {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} spec: template: diff --git a/ironic/templates/job-rabbit-init.yaml b/ironic/templates/job-rabbit-init.yaml index 202c42bc..846cc336 100644 --- a/ironic/templates/job-rabbit-init.yaml +++ b/ironic/templates/job-rabbit-init.yaml @@ -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 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 }} -{{- $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" }} {{- end }} diff --git a/releasenotes/notes/ironic.yaml b/releasenotes/notes/ironic.yaml index 6c561492..1698f691 100644 --- a/releasenotes/notes/ironic.yaml +++ b/releasenotes/notes/ironic.yaml @@ -2,3 +2,4 @@ ironic: - 0.1.0 Initial Chart - 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