From 30fbdb6748c5b19d4b4d1ff7124598113aab1cc6 Mon Sep 17 00:00:00 2001 From: Susanta Gautam Date: Wed, 17 Mar 2021 18:28:31 +0545 Subject: [PATCH] Added helm.sh/hook annotations for jobs in glance chart. Chart upgrading was failing due to some immutable fields in job are needed to upgrade. So, 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. Also helm3_hook value is introduced in values.yaml, which can be used to disable helm hook if needed. Change-Id: Idb4b992b4061f4a014570b7933a585df1a096299 --- glance/Chart.yaml | 2 +- glance/templates/job-bootstrap.yaml | 8 ++++++++ glance/templates/job-db-init.yaml | 8 ++++++++ glance/templates/job-db-sync.yaml | 8 ++++++++ glance/templates/job-image-repo-sync.yaml | 7 +++++++ glance/templates/job-ks-endpoints.yaml | 8 ++++++++ glance/templates/job-ks-service.yaml | 8 ++++++++ glance/templates/job-ks-user.yaml | 8 ++++++++ glance/templates/job-metadefs-load.yaml | 3 +++ glance/templates/job-rabbit-init.yaml | 9 +++++++++ glance/templates/job-storage-init.yaml | 3 +++ glance/values.yaml | 4 ++++ releasenotes/notes/glance.yaml | 1 + 13 files changed, 76 insertions(+), 1 deletion(-) diff --git a/glance/Chart.yaml b/glance/Chart.yaml index cd561f422e..098a411341 100644 --- a/glance/Chart.yaml +++ b/glance/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Glance name: glance -version: 0.2.6 +version: 0.2.7 home: https://docs.openstack.org/glance/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Glance/OpenStack_Project_Glance_vertical.png sources: diff --git a/glance/templates/job-bootstrap.yaml b/glance/templates/job-bootstrap.yaml index aaeabb5b3b..d51cbd3ea4 100644 --- a/glance/templates/job-bootstrap.yaml +++ b/glance/templates/job-bootstrap.yaml @@ -12,6 +12,11 @@ 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 }} + {{- define "glance.templates._job_bootstrap.pod_volumes" -}} {{- $envAll := index . 0 -}} volumeMounts: @@ -28,5 +33,8 @@ volumes: {{- if .Values.manifests.certificates -}} {{- $_ := set $bootstrapJob "tlsSecret" .Values.secrets.tls.image.api.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $bootstrapJob "jobAnnotations" (include "metadata.annotations.job.bootstrap" . | fromYaml) }} +{{- end }} {{ $bootstrapJob | include "helm-toolkit.manifests.job_bootstrap" }} {{- end }} diff --git a/glance/templates/job-db-init.yaml b/glance/templates/job-db-init.yaml index a1cfb0a930..d9b46ca72b 100644 --- a/glance/templates/job-db-init.yaml +++ b/glance/templates/job-db-init.yaml @@ -12,6 +12,11 @@ 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 := "glance" -}} {{- $dbToInit := dict "adminSecret" .Values.secrets.oslo_db.admin "configFile" (printf "/etc/%s/%s.conf" $serviceName "glance-api" ) "logConfigFile" (printf "/etc/%s/logging.conf" $serviceName ) "configDbSection" "database" "configDbKey" "connection" -}} @@ -19,5 +24,8 @@ limitations under the License. {{- if .Values.manifests.certificates -}} {{- $_ := set $dbInitJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}} {{- 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" }} {{- end }} diff --git a/glance/templates/job-db-sync.yaml b/glance/templates/job-db-sync.yaml index f5ce112bfd..e62b42cf4b 100644 --- a/glance/templates/job-db-sync.yaml +++ b/glance/templates/job-db-sync.yaml @@ -12,11 +12,19 @@ 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 }} {{- $dbToSync := index . "dbToSync" | default ( dict "configFile" (printf "/etc/%s/%s.conf" "glance" "glance-api" ) "logConfigFile" (printf "/etc/%s/logging.conf" "glance" ) "image" ( index .Values.images.tags ( printf "%s_db_sync" "glance" )) ) -}} {{- $dbSyncJob := dict "envAll" . "serviceName" "glance" "podVolMounts" .Values.pod.mounts.glance_db_sync.glance_db_sync.volumeMounts "podVols" .Values.pod.mounts.glance_db_sync.glance_db_sync.volumes "dbToSync" $dbToSync -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $dbSyncJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $dbSyncJob "jobAnnotations" (include "metadata.annotations.job.db_sync" . | fromYaml) }} +{{- end }} {{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }} {{- end }} diff --git a/glance/templates/job-image-repo-sync.yaml b/glance/templates/job-image-repo-sync.yaml index 505ff5cff5..fa3f77829a 100644 --- a/glance/templates/job-image-repo-sync.yaml +++ b/glance/templates/job-image-repo-sync.yaml @@ -12,7 +12,14 @@ 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" "glance" -}} +{{- if .Values.helm3_hook }} +{{- $_ := $imageRepoSyncJob "jobAnnotations" (include "metadata.annotations.job.repo_sync" . | fromYaml) }} +{{- end }} {{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }} {{- end }} diff --git a/glance/templates/job-ks-endpoints.yaml b/glance/templates/job-ks-endpoints.yaml index b66e01becc..3fdf635f33 100644 --- a/glance/templates/job-ks-endpoints.yaml +++ b/glance/templates/job-ks-endpoints.yaml @@ -12,10 +12,18 @@ 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" "glance" "serviceTypes" ( tuple "image" ) -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.image.api.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $ksServiceJob "jobAnnotations" (include "metadata.annotations.job.ks_endpoints" . | fromYaml) }} +{{- end }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }} {{- end }} diff --git a/glance/templates/job-ks-service.yaml b/glance/templates/job-ks-service.yaml index 440f456025..e5d3b1d7e4 100644 --- a/glance/templates/job-ks-service.yaml +++ b/glance/templates/job-ks-service.yaml @@ -12,10 +12,18 @@ 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" "glance" "serviceTypes" ( tuple "image" ) -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.image.api.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $ksServiceJob "jobAnnotations" (include "metadata.annotations.job.ks_service" . | fromYaml) }} +{{- end }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }} {{- end }} diff --git a/glance/templates/job-ks-user.yaml b/glance/templates/job-ks-user.yaml index 93adf112d5..dddc2ed9c0 100644 --- a/glance/templates/job-ks-user.yaml +++ b/glance/templates/job-ks-user.yaml @@ -12,10 +12,18 @@ 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" "glance" -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksUserJob "tlsSecret" .Values.secrets.tls.image.api.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $ksUserJob "jobAnnotations" (include "metadata.annotations.job.ks_user" . | fromYaml) }} +{{- end }} {{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }} {{- end }} diff --git a/glance/templates/job-metadefs-load.yaml b/glance/templates/job-metadefs-load.yaml index 49b50a9a85..bebae08e92 100644 --- a/glance/templates/job-metadefs-load.yaml +++ b/glance/templates/job-metadefs-load.yaml @@ -23,6 +23,9 @@ kind: Job metadata: name: glance-metadefs-load annotations: +{{- if .Values.helm3_hook }} + helm.sh/hook: post-install,post-upgrade +{{- end }} {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} spec: template: diff --git a/glance/templates/job-rabbit-init.yaml b/glance/templates/job-rabbit-init.yaml index e557dab4ff..9c9387dd57 100644 --- a/glance/templates/job-rabbit-init.yaml +++ b/glance/templates/job-rabbit-init.yaml @@ -11,10 +11,19 @@ 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" "glance" -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $rmqUserJob "tlsSecret" .Values.endpoints.oslo_messaging.auth.admin.secret.tls.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $rmqUserJob "jobAnnotations" (include "metadata.annotations.job.rabbit_init" . | fromYaml) }} +{{- end }} {{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }} {{- end }} diff --git a/glance/templates/job-storage-init.yaml b/glance/templates/job-storage-init.yaml index 5eef64f03d..b991d487db 100644 --- a/glance/templates/job-storage-init.yaml +++ b/glance/templates/job-storage-init.yaml @@ -51,6 +51,9 @@ kind: Job metadata: name: glance-storage-init annotations: +{{- if .Values.helm3_hook }} + helm.sh/hook: post-install,post-upgrade +{{- end }} {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} spec: template: diff --git a/glance/values.yaml b/glance/values.yaml index 87f4b31f5c..ea3dd8e515 100644 --- a/glance/values.yaml +++ b/glance/values.yaml @@ -1050,6 +1050,10 @@ pod: memory: "1024Mi" cpu: "2000m" +# NOTE(helm_hook): helm_hook might break for helm2 binary. +# set helm3_hook: false when using the helm2 binary. +helm3_hook: true + manifests: certificates: false configmap_bin: true diff --git a/releasenotes/notes/glance.yaml b/releasenotes/notes/glance.yaml index 8d618f68b0..93f6dd1081 100644 --- a/releasenotes/notes/glance.yaml +++ b/releasenotes/notes/glance.yaml @@ -16,4 +16,5 @@ glance: - 0.2.4 Mount rabbitmq TLS secret - 0.2.5 Add Ussuri release support - 0.2.6 Add Victoria and Wallaby releases support + - 0.2.7 Added helm.sh/hook for the jobs ...