From 3abcefea391accfa8044cda870a48c99f3d6ded9 Mon Sep 17 00:00:00 2001 From: Susanta Gautam Date: Wed, 24 Mar 2021 18:38:34 +0545 Subject: [PATCH] Added post-install and post-upgrade hook in jobs for barbican 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: I2c0f9468371a60d875fd0267b3d916b286f8ce7b --- barbican/Chart.yaml | 2 +- barbican/templates/job-bootstrap.yaml | 7 ++++++- barbican/templates/job-db-init.yaml | 7 ++++++- barbican/templates/job-db-sync.yaml | 7 ++++++- barbican/templates/job-image-repo-sync.yaml | 6 +++++- barbican/templates/job-ks-endpoints.yaml | 7 ++++++- barbican/templates/job-ks-service.yaml | 7 ++++++- barbican/templates/job-ks-user.yaml | 7 ++++++- barbican/templates/job-rabbit-init.yaml | 8 +++++++- releasenotes/notes/barbican.yaml | 1 + 10 files changed, 50 insertions(+), 9 deletions(-) diff --git a/barbican/Chart.yaml b/barbican/Chart.yaml index e4ab8a7ab7..f88265bdfc 100644 --- a/barbican/Chart.yaml +++ b/barbican/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Barbican name: barbican -version: 0.1.1 +version: 0.1.2 home: https://docs.openstack.org/barbican/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Barbican/OpenStack_Project_Barbican_vertical.png sources: diff --git a/barbican/templates/job-bootstrap.yaml b/barbican/templates/job-bootstrap.yaml index 899b4f6d79..1bee0d852e 100644 --- a/barbican/templates/job-bootstrap.yaml +++ b/barbican/templates/job-bootstrap.yaml @@ -12,7 +12,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" "barbican" "keystoneUser" .Values.bootstrap.ks_user "logConfigFile" .Values.conf.barbican.DEFAULT.log_config_append -}} +{{- $bootstrapJob := dict "envAll" . "serviceName" "barbican" "keystoneUser" .Values.bootstrap.ks_user "logConfigFile" .Values.conf.barbican.DEFAULT.log_config_append "jobAnnotations" (include "metadata.annotations.job.bootstrap" . | fromYaml) -}} {{ $bootstrapJob | include "helm-toolkit.manifests.job_bootstrap" }} {{- end }} diff --git a/barbican/templates/job-db-init.yaml b/barbican/templates/job-db-init.yaml index fdd97c5656..e58cb9d8aa 100644 --- a/barbican/templates/job-db-init.yaml +++ b/barbican/templates/job-db-init.yaml @@ -12,9 +12,14 @@ 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 }} {{- $serviceName := "barbican" -}} -{{- $dbToInit := dict "adminSecret" .Values.secrets.oslo_db.admin "configFile" (printf "/etc/%s/%s.conf" $serviceName $serviceName ) "logConfigFile" (printf "/etc/%s/logging.conf" $serviceName ) "configDbSection" "DEFAULT" "configDbKey" "sql_connection" -}} +{{- $dbToInit := dict "adminSecret" .Values.secrets.oslo_db.admin "configFile" (printf "/etc/%s/%s.conf" $serviceName $serviceName ) "logConfigFile" (printf "/etc/%s/logging.conf" $serviceName ) "configDbSection" "DEFAULT" "configDbKey" "sql_connection" "jobAnnotations" (include "metadata.annotations.job.db_init" . | fromYaml) -}} {{- $dbInitJob := dict "envAll" . "serviceName" $serviceName "dbToInit" $dbToInit -}} {{ $dbInitJob | include "helm-toolkit.manifests.job_db_init_mysql" }} {{- end }} diff --git a/barbican/templates/job-db-sync.yaml b/barbican/templates/job-db-sync.yaml index b7939a393a..7328a52203 100644 --- a/barbican/templates/job-db-sync.yaml +++ b/barbican/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" "barbican" "podVolMounts" .Values.pod.mounts.barbican_db_sync.barbican_db_sync.volumeMounts "podVols" .Values.pod.mounts.barbican_db_sync.barbican_db_sync.volumes -}} +{{- $dbSyncJob := dict "envAll" . "serviceName" "barbican" "podVolMounts" .Values.pod.mounts.barbican_db_sync.barbican_db_sync.volumeMounts "podVols" .Values.pod.mounts.barbican_db_sync.barbican_db_sync.volumes "jobAnnotations" (include "metadata.annotations.job.db_sync" . | fromYaml) -}} {{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }} {{- end }} diff --git a/barbican/templates/job-image-repo-sync.yaml b/barbican/templates/job-image-repo-sync.yaml index d4936879c1..e6648245c7 100644 --- a/barbican/templates/job-image-repo-sync.yaml +++ b/barbican/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" "barbican" -}} +{{- $imageRepoSyncJob := dict "envAll" . "serviceName" "barbican" "jobAnnotations" (include "metadata.annotations.job.repo_sync" . | fromYaml) -}} {{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }} {{- end }} diff --git a/barbican/templates/job-ks-endpoints.yaml b/barbican/templates/job-ks-endpoints.yaml index ab68fc8544..b46da30777 100644 --- a/barbican/templates/job-ks-endpoints.yaml +++ b/barbican/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" "barbican" "serviceTypes" ( tuple "key-manager" ) -}} +{{- $ksServiceJob := dict "envAll" . "serviceName" "barbican" "serviceTypes" ( tuple "key-manager" ) "jobAnnotations" (include "metadata.annotations.job.ks_endpoints" . | fromYaml) -}} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }} {{- end }} diff --git a/barbican/templates/job-ks-service.yaml b/barbican/templates/job-ks-service.yaml index cb671d5ac0..ac4f5a5f24 100644 --- a/barbican/templates/job-ks-service.yaml +++ b/barbican/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" "barbican" "serviceTypes" ( tuple "key-manager" ) -}} +{{- $ksServiceJob := dict "envAll" . "serviceName" "barbican" "serviceTypes" ( tuple "key-manager" ) "jobAnnotations" (include "metadata.annotations.job.ks_service" . | fromYaml) -}} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }} {{- end }} diff --git a/barbican/templates/job-ks-user.yaml b/barbican/templates/job-ks-user.yaml index 58cb01bb15..bbc486da0f 100644 --- a/barbican/templates/job-ks-user.yaml +++ b/barbican/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" "barbican" -}} +{{- $ksUserJob := dict "envAll" . "serviceName" "barbican" "jobAnnotations" (include "metadata.annotations.job.ks_user" . | fromYaml) -}} {{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }} {{- end }} diff --git a/barbican/templates/job-rabbit-init.yaml b/barbican/templates/job-rabbit-init.yaml index 284cdb6724..2ec40f5d01 100644 --- a/barbican/templates/job-rabbit-init.yaml +++ b/barbican/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" "barbican" -}} +{{- $rmqUserJob := dict "envAll" . "serviceName" "barbican" "jobAnnotations" (include "metadata.annotations.job.rabbit_init" . | fromYaml) -}} {{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }} {{- end }} diff --git a/releasenotes/notes/barbican.yaml b/releasenotes/notes/barbican.yaml index eef087ccfd..cc00d57349 100644 --- a/releasenotes/notes/barbican.yaml +++ b/releasenotes/notes/barbican.yaml @@ -2,3 +2,4 @@ barbican: - 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 hook for Jobs