From 459f33f00c838692b0eaaa5e113205647ea59c0f Mon Sep 17 00:00:00 2001 From: Susanta Gautam Date: Wed, 24 Mar 2021 20:04:04 +0545 Subject: [PATCH] Added post-install and post-upgrade hook for Jobs on octavia 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: I28dec6d082b95b448752e741e7694d32b2740cfa --- octavia/Chart.yaml | 2 +- octavia/templates/job-bootstrap.yaml | 6 +++++- octavia/templates/job-db-init.yaml | 7 ++++++- octavia/templates/job-db-sync.yaml | 7 ++++++- octavia/templates/job-image-repo-sync.yaml | 6 +++++- octavia/templates/job-ks-endpoint.yaml | 7 ++++++- octavia/templates/job-ks-service.yaml | 7 ++++++- octavia/templates/job-ks-user.yaml | 7 ++++++- octavia/templates/job-rabbit-init.yaml | 8 +++++++- releasenotes/notes/octavia.yaml | 1 + 10 files changed, 49 insertions(+), 9 deletions(-) diff --git a/octavia/Chart.yaml b/octavia/Chart.yaml index 6c486bb0..4fff3e09 100644 --- a/octavia/Chart.yaml +++ b/octavia/Chart.yaml @@ -16,7 +16,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Octavia name: octavia -version: 0.1.1 +version: 0.1.2 home: https://docs.openstack.org/octavia/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Octavia/OpenStack_Project_Octavia_vertical.png sources: diff --git a/octavia/templates/job-bootstrap.yaml b/octavia/templates/job-bootstrap.yaml index cf7bdb7e..3117ba4e 100644 --- a/octavia/templates/job-bootstrap.yaml +++ b/octavia/templates/job-bootstrap.yaml @@ -14,8 +14,12 @@ 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.enabled }} -{{- $bootstrapJob := dict "envAll" . "serviceName" "octavia" "keystoneUser" .Values.bootstrap.ks_user "logConfigFile" .Values.conf.octavia.DEFAULT.log_config_append -}} +{{- $bootstrapJob := dict "envAll" . "serviceName" "octavia" "keystoneUser" .Values.bootstrap.ks_user "logConfigFile" .Values.conf.octavia.DEFAULT.log_config_append "jobAnnotations" (include "metadata.annotations.job.bootstrap" . | fromYaml) -}} {{ $bootstrapJob | include "helm-toolkit.manifests.job_bootstrap" }} {{- end }} diff --git a/octavia/templates/job-db-init.yaml b/octavia/templates/job-db-init.yaml index 77d4008c..b1ca9f64 100644 --- a/octavia/templates/job-db-init.yaml +++ b/octavia/templates/job-db-init.yaml @@ -14,7 +14,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" "octavia" -}} +{{- $dbInitJob := dict "envAll" . "serviceName" "octavia" "jobAnnotations" (include "metadata.annotations.job.db_init" . | fromYaml) -}} {{ $dbInitJob | include "helm-toolkit.manifests.job_db_init_mysql" }} {{- end }} diff --git a/octavia/templates/job-db-sync.yaml b/octavia/templates/job-db-sync.yaml index a5d40b7b..0c7cdb30 100644 --- a/octavia/templates/job-db-sync.yaml +++ b/octavia/templates/job-db-sync.yaml @@ -14,7 +14,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" "octavia" -}} +{{- $dbSyncJob := dict "envAll" . "serviceName" "octavia" "jobAnnotations" (include "metadata.annotations.job.db_sync" . | fromYaml) -}} {{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }} {{- end }} diff --git a/octavia/templates/job-image-repo-sync.yaml b/octavia/templates/job-image-repo-sync.yaml index ebe35e22..25c19e41 100644 --- a/octavia/templates/job-image-repo-sync.yaml +++ b/octavia/templates/job-image-repo-sync.yaml @@ -14,7 +14,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" "octavia" -}} +{{- $imageRepoSyncJob := dict "envAll" . "serviceName" "octavia" "jobAnnotations" (include "metadata.annotations.job.repo_sync" . | fromYaml) -}} {{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }} {{- end }} diff --git a/octavia/templates/job-ks-endpoint.yaml b/octavia/templates/job-ks-endpoint.yaml index 83aeeeb1..3f7eff66 100644 --- a/octavia/templates/job-ks-endpoint.yaml +++ b/octavia/templates/job-ks-endpoint.yaml @@ -14,7 +14,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" "octavia" "serviceTypes" ( tuple "load-balancer" ) -}} +{{- $ksServiceJob := dict "envAll" . "serviceName" "octavia" "serviceTypes" ( tuple "load-balancer" ) "jobAnnotations" (include "metadata.annotations.job.ks_endpoints" . | fromYaml) -}} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }} {{- end }} diff --git a/octavia/templates/job-ks-service.yaml b/octavia/templates/job-ks-service.yaml index b10d1371..d29ee24e 100644 --- a/octavia/templates/job-ks-service.yaml +++ b/octavia/templates/job-ks-service.yaml @@ -14,7 +14,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" "octavia" "serviceTypes" ( tuple "load-balancer" ) -}} +{{- $ksServiceJob := dict "envAll" . "serviceName" "octavia" "serviceTypes" ( tuple "load-balancer" ) "jobAnnotations" (include "metadata.annotations.job.ks_service" . | fromYaml) -}} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }} {{- end }} diff --git a/octavia/templates/job-ks-user.yaml b/octavia/templates/job-ks-user.yaml index ec0875f4..38e91dad 100644 --- a/octavia/templates/job-ks-user.yaml +++ b/octavia/templates/job-ks-user.yaml @@ -14,7 +14,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" "octavia" -}} +{{- $ksUserJob := dict "envAll" . "serviceName" "octavia" "jobAnnotations" (include "metadata.annotations.job.ks_user" . | fromYaml) -}} {{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }} {{- end }} diff --git a/octavia/templates/job-rabbit-init.yaml b/octavia/templates/job-rabbit-init.yaml index 4c33309c..50f7d368 100644 --- a/octavia/templates/job-rabbit-init.yaml +++ b/octavia/templates/job-rabbit-init.yaml @@ -13,7 +13,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" "octavia" -}} +{{- $rmqUserJob := dict "envAll" . "serviceName" "octavia" "jobAnnotations" (include "metadata.annotations.job.rabbit_init" . | fromYaml) -}} {{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }} {{- end }} diff --git a/releasenotes/notes/octavia.yaml b/releasenotes/notes/octavia.yaml index fd854964..9c410eb8 100644 --- a/releasenotes/notes/octavia.yaml +++ b/releasenotes/notes/octavia.yaml @@ -2,3 +2,4 @@ octavia: - 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 hook for Jobs